linux配置yum源


yum(全稱為 Yellow dog Updater, Modified)是一個在Fedora和RedHat以及SUSE中的Shell前端軟件包管理器。基於RPM包管理,能夠從指定的服務器自動下載RPM包並且安裝,可以自動處理依賴性關系,並且一次安裝所有依賴的軟體包,無須繁瑣地一次次下載、安裝。yum提供了查找、安裝、刪除某一個、一組甚至全部軟件包的命令,而且命令簡潔而又好記。

--1.1 實驗環境

RHEL6:虛擬機

--1.2 掛載光驅

(在VMware虛擬機下,可共享主機本地磁盤上的解壓后的鏡像文件,直接copy里面的Packages目錄到/opt/rpm/local_repo/) [root@redhat6 yum.repos.d]# mount /dev/cdrom /mnt    

mount: block device /dev/sr0 is write-protected, mounting read-only 備注:將光盤 ISO 文件掛載到目錄 /mnt 

卸載:umount /mnt

========

如果是iso鏡像文件,掛載方式如下:

#mkdir -p /opt/rpm/local_repo/

#mount -o loop -t iso9660 /tmp/rhel-server-6.3-x86_64-dvd.iso   /mnt --之后,可在/mnt目錄下看到iso鏡像里的所有文件。

把/mnt/Packages下的所有rpm名拷貝到/opt/rpm/local_repo

--1.3 創建本地目錄,用來 copy 光盤包

[root@redhat6 local_repo]# mkdir -p /opt/rpm/local_repo

--1.4 copy RPM 包到指定目錄

[root@redhat6 log]# cd /mnt/Packages/

[root@redhat6 Packages]# cp * /opt/rpm/local_repo

--1.5 安裝 createrepo 包

[root@redhat6 local_repo]# rpm -ivh createrepo-0.9.8-4.el6.noarch.rpm

warning: createrepo-0.9.8-4.el6.noarch.rpm: Header V3 RSA/SHA256 Signature, key ID fd431d51: NOKEY error: Failed dependencies:         deltarpm is needed by createrepo-0.9.8-4.el6.noarch        

python-deltarpm is needed by createrepo-0.9.8-4.el6.noarch You have new mail in /var/spool/mail/root

--1.5.1根據提示,安裝需要的包

 [root@redhat6 local_repo]# rpm -ivh deltarpm-3.5-0.5.20090913git.el6.i686.rpm

warning: deltarpm-3.5-0.5.20090913git.el6.i686.rpm: Header V3 RSA/SHA256 Signature, key ID fd431d51: NOKEY Preparing...                ########################################### [100%]    1:deltarpm               ########################################### [100%]

[root@redhat6 local_repo]# rpm -ivh python-deltarpm-3.5-0.5.20090913git.el6.i686.rpm

warning: python-deltarpm-3.5-0.5.20090913git.el6.i686.rpm: Header V3 RSA/SHA256 Signature, key ID fd431d51: NOKEY Preparing...                ########################################### [100%]    1:python-deltarpm        ########################################### [100%]

[root@redhat6 local_repo]# rpm -ivh createrepo-0.9.8-4.el6.noarch.rpm

warning: createrepo-0.9.8-4.el6.noarch.rpm: Header V3 RSA/SHA256 Signature, key ID fd431d51: NOKEY Preparing...                ########################################### [100%]    1:createrepo             ########################################### [100%]          備注:createrepo 包安裝成功   

--1.6 創建 repo 數據庫  

[root@redhat6 local_repo]# createrepo -d /opt/rpm/local_repo

1944/2804 - MAKEDEV-3.24-6.el6.i686.rpm                                       

  iso-8859-1 encoding on Ville Skytt?ville.skytta@iki.fi> - 2.8.2-2

2804/2804 - perl-Archive-Extract-0.38-119.el6_1.1.i686.rpm      Saving Primary metadata Saving file lists metadata Saving other metadata Generating sqlite DBs Sqlite DBs complete     

===============

補充說明:

使用-g參數指定分組文件:-g GROUPFILE, --groupfile=GROUPFILE 如果不加該參數,yum group list...不可用;分組文件在iso鏡像文件里的repodata目錄下,一般是這種格式:xxx-comps-xxx.xml

             -d, --database create sqlite database files: now default, see --no-database to disable

所以要使用該命令來創建repo數據庫:createrepo -g /../xxxxx-comps-Server.x86_64.xml  /opt/rpm/local_repo   //-d參數可以不要

===============       

備注:這個步驟需要點時間。 (配置完成)

--1.7 編寫 /etc/yum.repos.d/local_repo.repo 文件

   文件 /etc/yum.repos.d/local_repo.repo   內容如下。

 [rhel-source]
name=Red Hat Enterprise Linux Local repo  
##倉庫描述
baseurl=file:///opt/rpm/local_repo        
##軟件倉庫位置
enabled=1                                 
##是否啟用
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release  
##簽名秘鑰

=======================================

關於gpgkey的值說明:應該填寫什么值要到/etc/pki/rpm-gpg目錄下去查看。根據自己安裝的操作系統來填寫相應的值。

或者簡單粗暴的方法是把配置文件里gpgcheck=0,不要做簽名檢查。但是不安全,建議生產環境還是要gpgcheck=1。然后導入rpm包的公鑰,之后再安裝紅帽簽名的rpm包時就不會報錯了。

[root@localhost rpm-gpg]# pwd
/etc/pki/rpm-gpg
[root@localhost rpm-gpg]# ls
RPM-GPG-KEY RPM-GPG-KEY-fedora RPM-GPG-KEY-fedora-test RPM-GPG-KEY-oracle

========================================================================================================

補充:三條命令完成YUM源配置

如果是自己在虛擬機里測試,配置yum源最簡單的方法是使用yum-config-manager工具(在RHEL7系統中)。

# mount /dev/cdrom /mnt
# yum-config-manager --add-repo="file:///mnt"
# vi /etc/yum.repos.d/mnt.repo
    gpgcheck=0 

[root@rhel2 ~]# mount /dev/cdrom /mnt #插入光驅,並掛載到/mnt目錄下
[root@rhel2 ~]# cd /etc/yum.repos.d/
[root@rhel2 yum.repos.d]# rm -rf *   #把原來的yum配置文件刪除,或者不刪除也沒關系,這里主要是為了演示
[root@rhel2 yum.repos.d]# ll
total 0
[root@rhel2 yum.repos.d]# yum-config-manager --add-repo="file:///mnt"   #引號里為YUM repo路徑。如果是其它路徑,比如http或ftp路徑,注意修改。
Loaded plugins: langpacks, product-id
adding repo from: file:///mnt

[mnt]
name=added from: file:///mnt
baseurl=file:///mnt
enabled=1

[root@rhel2 yum.repos.d]# ll   #之后會自動生成mnt.repo文件
total 4
-rw-r--r--. 1 root root 67 Nov 16 00:40 mnt.repo
[root@rhel2 yum.repos.d]# vi mnt.repo 

[mnt]
name=added from: file:///mnt
baseurl=file:///mnt
enabled=1
gpgcheck=0    #默認是沒有這一行的,需要手動添加。之后就可以使用yum命令來安裝軟件包了。生產環境建議gpgcheck=1,然后使用下面的命令導入簽名文件。

"mnt.repo" 6L, 77C written
[root@rhel2 yum.repos.d]# ll /etc/pki/rpm-gpg/   #下面這些是紅帽系統自身的RPM包的公鑰。如果是生產環境中,需要把gpgchec修改為1,然后用命令導入這些RPM簽名公鑰文件。
total 20
-rw-r--r--. 1 root root 3375 Jun 29 02:36 RPM-GPG-KEY-redhat-beta
-rw-r--r--. 1 root root 1990 Jun 29 02:36 RPM-GPG-KEY-redhat-legacy-former
-rw-r--r--. 1 root root 1164 Jun 29 02:36 RPM-GPG-KEY-redhat-legacy-release
-rw-r--r--. 1 root root  885 Jun 29 02:36 RPM-GPG-KEY-redhat-legacy-rhx
-rw-r--r--. 1 root root 3211 Jun 29 02:36 RPM-GPG-KEY-redhat-release
[root@rhel2 yum.repos.d]# rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-*   #建議導入所有
[root@rhel2 yum.repos.d]# 
[root@localhost ~]# yum clean all  --清除一下緩存
Loaded plugins: langpacks, product-id, search-disabled-repos, subscription-manager
This system is not registered with an entitlement server. You can use subscription-manager to register.
Cleaning repos: mnt_cdrom
Cleaning up everything
Maybe you want: rm -rf /var/cache/yum, to also free up space taken by orphaned data from disabled or removed repos
[root@localhost ~]# yum repolist --查看repolist
Loaded plugins: langpacks, product-id, search-disabled-repos, subscription-manager
This system is not registered with an entitlement server. You can use subscription-manager to register.
mnt_cdrom                                                                                                                   | 4.1 kB  00:00:00     
(1/2): mnt_cdrom/group_gz                                                                                                   | 137 kB  00:00:00     
(2/2): mnt_cdrom/primary_db                                                                                                 | 4.0 MB  00:00:00     
repo id                                                     repo name                                                                        status
mnt_cdrom                                                   added from: file:///mnt/cdrom                                                    4,986
repolist: 4,986
[root@localhost ~]# 

 

二 、yum 源測試

yum的命令形式一般是如下:

yum [options] [command] [package ...]

其中的[options]是可選的,選項包括-h(幫助),-y(當安裝過程提示選擇全部為"yes"),-q(不顯示安裝的過程)等等。[command]為所要進行的操作,[package ...]是操作的對象。

概括了部分常用的命令包括:

自動搜索最快鏡像插件:   yum install yum-fastestmirror

安裝yum圖形窗口插件:    yum install yumex

查看可能批量安裝的列表: yum grouplist

1 安裝 yum install 全部安裝 yum install package1 安裝指定的安裝包package1 yum groupinsall group1 安裝程序組group1

2 更新和升級 yum update 全部更新 yum update package1 更新指定程序包package1 yum check-update 檢查可更新的程序 yum upgrade package1 升級指定程序包package1 yum groupupdate group1 升級程序組group1

3 查找和顯示 yum info package1 顯示安裝包信息package1 yum list 顯示所有已經安裝和可以安裝的程序包 yum list package1 顯示指定程序包安裝情況package1 yum groupinfo group1 顯示程序組group1信息yum search string 根據關鍵字string查找安裝包

4 刪除程序 yum remove | erase package1 刪除程序包package1 yum groupremove group1 刪除程序組group1 yum deplist package1 查看程序package1依賴情況

5 清除緩存 yum clean packages 清除緩存目錄下的軟件包 yum clean headers 清除緩存目錄下的 headers yum clean oldheaders 清除緩存目錄下舊的 headers yum clean, yum clean all (= yum clean packages; yum clean oldheaders) 清除緩存目錄下的軟件包及舊的headers  be disabled. Setting up Insta

《FROM:http://francs3.blog.163.com/blog/static/40576727201221644041342/

四、錯誤處理:

[root@localhost rpm-gpg]# yum install ksh  --執行yum安裝測試時發生錯誤,如下:
已加載插件:langpacks
http://public-yum.oracle.com/repo/OracleLinux/OL7/UEKR3/x86_64/repodata/repomd.xml: [Errno 14] curl#6 - "Could not resolve host: public-yum.oracle.com; 未知的錯誤"
正在嘗試其它鏡像。


One of the configured repositories failed (Latest Unbreakable Enterprise Kernel for Oracle Linux 7Server (x86_64)),
and yum doesn't have enough cached data to continue. At this point the only
safe thing yum can do is fail. There are a few ways to work "fix" this:

1. Contact the upstream for the repository and get them to fix the problem.

2. Reconfigure the baseurl/etc. for the repository, to point to a working
upstream. This is most often useful if you are using a newer
distribution release than is supported by the repository (and the
packages for the previous distribution release still work).

3. Disable the repository, so yum won't use it by default. Yum will then
just ignore the repository until you permanently enable it again or use
--enablerepo for temporary usage:

yum-config-manager --disable ol7_UEKR3

4. Configure the failing repository to be skipped, if it is unavailable.
Note that yum will try to contact the repo. when it runs most commands,
so will have to try and fail each time (and thus. yum will be be much
slower). If it is a very temporary problem though, this is often a nice
compromise:

yum-config-manager --save --setopt=ol7_UEKR3.skip_if_unavailable=true

failure: repodata/repomd.xml from ol7_UEKR3: [Errno 256] No more mirrors to try.
http://public-yum.oracle.com/repo/OracleLinux/OL7/UEKR3/x86_64/repodata/repomd.xml: [Errno 14] curl#6 - "Could not resolve host: public-yum.oracle.com; 未知的錯誤"

錯誤分析:從上面可看出,在執行Yum安裝時應該沒有用到我們配置文件 /etc/yum.repos.d/local_repo.repo.

查看/etc/yum.repos.d目錄:

[root@localhost yum.repos.d]# ls
local_repo.repo public-yum-ol7.repo
[root@localhost yum.repos.d]# pwd
/etc/yum.repos.d
[root@localhost yum.repos.d]# mv public-yum-ol7.repo public-yum-ol7.repo_bak  --把原來的配置文件備份

安裝測試:--正常

[root@localhost yum.repos.d]# yum install ksh
已加載插件:langpacks
正在解決依賴關系
--> 正在檢查事務
---> 軟件包 ksh.x86_64.0.20120801-19.el7 將被 安裝
--> 解決依賴關系完成

依賴關系解決

===================================
Package 架構 版本 源 大小
====================================
正在安裝:
ksh x86_64 20120801-19.el7 oracle-linux-source 878 k

事務概要
=========================================
安裝 1 軟件包

總下載量:878 k
安裝大小:3.1 M
Is this ok [y/d/N]:

……

==========步驟說明======================================

第1步:在虛擬機軟件里選中光盤iso鏡像

第2步:將光盤設備掛載到/media/cdrom目錄

# mkdir -p /media/cdrom

# mount /dev/cdrom /media/cdrom

第3步:把Packages目錄拷貝到其它地方,並創建yum庫

#cp -rf /media/cdrom/Packages /opt/local_repo/

#createrepo -d /opt/local_repo/Packages

第4步:使用Vim編輯器創建Yum倉庫的配置文件

#vi /etc/yum.repos.d/rhel6.repo
[rhel6]
name=rhel6
baseurl=file:///opt/local_repo/Packages
enabled=1
gpgcheck=0

 ==================

RHEL7-配置本地YUM源:

http://www.unixarena.com/2015/04/how-to-create-the-yum-repository-on-rhel-7.html

[root@localhost ~]# yum clean allLoaded plugins: langpacks, product-id, search-disabled-repos, subscription-managerThis system is not registered with an entitlement server. You can use subscription-manager to register.Cleaning repos: mnt_cdromCleaning up everythingMaybe you want: rm -rf /var/cache/yum, to also free up space taken by orphaned data from disabled or removed repos[root@localhost ~]# yum repolist Loaded plugins: langpacks, product-id, search-disabled-repos, subscription-managerThis system is not registered with an entitlement server. You can use subscription-manager to register.mnt_cdrom                                                                                                                   | 4.1 kB  00:00:00     (1/2): mnt_cdrom/group_gz                                                                                                   | 137 kB  00:00:00     (2/2): mnt_cdrom/primary_db                                                                                                 | 4.0 MB  00:00:00     repo id                                                     repo name                                                                        statusmnt_cdrom                                                   added from: file:///mnt/cdrom                                                    4,986repolist: 4,986[root@localhost ~]# 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM