溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

配置YUM源的步驟(原理)

發(fā)布時(shí)間:2020-08-13 12:34:39 來源:ITPUB博客 閱讀:302 作者:白石溪頭 欄目:建站服務(wù)器

yum的配置一般有兩種方式:

 

一種是直接配置/etc目錄下的yum.conf文件,

另外一種是在/etc/yum.repos.d目錄下增加.repo文件。


一、yum的配置文件yum.conf詳解 

 

配置YUM源的步驟(原理)

$ cat /etc/yum.conf 
 
[main]
cachedir=/var/cache/yum         #yum下載的RPM包的緩存目錄
keepcache=0                        #緩存是否保存,1保存,0不保存。
debuglevel=2                       #調(diào)試級(jí)別(0-10),默認(rèn)為2(具體調(diào)試級(jí)別的應(yīng)用,我也不了解)。
logfile=/var/log/yum.log         #yum的日志文件所在的位置
exactarch=1             #在更新的時(shí)候,是否允許更新不同版本的RPM包,比如是否在i386上更新i686的RPM包。
obsoletes=1             #這是一個(gè)update的參數(shù),具體請(qǐng)參閱yum(8),簡單的說就是相當(dāng)于upgrade,允許更新陳舊的RPM包。
gpgcheck=1             #是否檢查GPG(GNU Private Guard),一種密鑰方式簽名。
plugins=1             #是否允許使用插件,默認(rèn)是0不允許,但是我們一般會(huì)用yum-fastestmirror這個(gè)插件。
installonly_limit=3         #允許保留多少個(gè)內(nèi)核包。
exclude=selinux*         #屏蔽不想更新的RPM包,可用通配符,多個(gè)RPM包之間使用空格分離。
#       This is the default, if you make this bigger yum won't see if the metadata# is newer on the remote and so you'll "gain" the bandwidth of not having to# download the new metadata and "pay" for it by yum not having correct
# information.
# It is esp. important, to have correct metadata, for distributions like
# Fedora which don't keep old packages around. If you don't like this checking
# interupting your command line usage, it's much better to have something# manually check the metadata once an hour (yum-updatesd will do this).
# metadata_expire=90m
# PUT YOUR REPOS HERE or IN separate files named file.repo
# in /etc/yum.repos.d

配置YUM源的步驟(原理)

二、*.repo文件詳解

 

什么是repo文件?

repo文件是Fedora中yum源(軟件倉庫)的配置文件,通常一個(gè)repo文件定義了一個(gè)或者多個(gè)軟件倉庫的細(xì)節(jié)內(nèi)容,例如我們將從哪里下載需要安裝或者升級(jí)的軟件包,repo文件中的設(shè)置內(nèi)容將被yum讀取和應(yīng)用!
我們以一份系統(tǒng)自帶的repo文件做為實(shí)例來探討(Fedora和redhat是一致的)(#號(hào)后面是我加的注釋):

配置YUM源的步驟(原理)

[fedora]       #方括號(hào)里面的是軟件源的名稱,將被yum取得并識(shí)別name=Fedora $releasever - $basearch   #這里也定義了軟件 倉庫的名稱,通常是為了方便閱讀配置文件,一般沒什么作用,$releasever變量定義了發(fā)行版本,通常是8,9,10等數(shù)字,$basearch變 量定義了系統(tǒng)的架構(gòu),可以是i386、x86_64、ppc等值,這兩個(gè)變量根據(jù)當(dāng)前系統(tǒng)的版本架構(gòu)不同而有不同的取值,這可以方便yum升級(jí)的時(shí)候選擇 適合當(dāng)前系統(tǒng)的軟件包,以下同……failovermethod=priority   #failovermethod 有兩個(gè)值可以選擇,priority是默認(rèn)值,表示從列出的baseurl中順序選擇鏡像服務(wù)器地址,roundrobin表示在列出的服務(wù)器中隨機(jī)選擇exclude=compiz* *compiz* fusion-icon* #exclude這個(gè)選項(xiàng)是后來我自己加上去的,用來禁止這個(gè)軟件倉庫中的某些軟件包的安裝和更新,可以使用通配符,并以空格分隔,可以視情況需要自行添加#baseurl=http://download.fedoraproject.org/pub/fedora/linux/releases/$releasever/Everything/$basearch/os/
#上面的一行baseurl第一個(gè)字符是'#'表示該行已經(jīng)被注釋,將不會(huì)被讀取,這一行的意思是指定一個(gè)baseurl(源的鏡像服務(wù)器地址)
#mirrorlist=http://mirrors.fedoraproject.org/mirrorlist?repo=fedora-$releasever&arch=$basearch#上面的這一行是指定一個(gè)鏡像服務(wù)器的地址列表,通常是開啟的,本例中加了注釋符號(hào)禁用了,我們可以試試,將$releasever和$basearch替換成自己對(duì)應(yīng)的版本和架構(gòu),例如10和i386,在瀏覽器中打開,我們就能看到一長串鏡可用的鏡像服務(wù)器地址列表。
選擇自己訪問速度較快的鏡像服務(wù)器地址復(fù)制并粘貼到repo文件中,我們就能獲得較快的更新速度了,格式如下baseurl所示:baseurl=ftp://ftp.sfc.wide.ad.jp/pub/Linux/Fedora/releases/10/Everything/i386/oshttp://ftp.chg.ru/pub/Linux/fedora/linux/releases/10/Everything/i386/oshttp://ftp.yz.yamagata-u.ac.jp/pub/linux/fedora/linux/releases/10/Everything/i386/oshttp://mirror.nus.edu.sg/fedora/releases/10/Everything/i386/oshttp://mirror.yandex.ru/fedora/linux/releases/10/Everything/i386/oshttp://ftp.twaren.net/Linux/Fedora/linux/releases/10/Everything/i386/oshttp://ftp.itu.edu.tr/Mirror/Fedora/linux/releases/10/Everything/i386/osenabled=1 #這個(gè)選項(xiàng)表示這個(gè)repo中定義的源是啟用的,0為禁用gpgcheck=1 #這個(gè)選項(xiàng)表示這個(gè)repo中下載的rpm將進(jìn)行g(shù)pg的校驗(yàn),已確定rpm包的來源是有效和安全的gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-fedora-$basearch #定義用于校驗(yàn)的gpg密鑰,就是數(shù)位簽章的公鑰檔所在位置!##以下的軟件倉庫基本上用不到,選項(xiàng)含義同上[fedora-debuginfo]
name=Fedora $releasever - $basearch - Debug
failovermethod=priority
#baseurl=http://download.fedoraproject.org/pub/fedora/linux/releases/$releasever/Everything/$basearch/debug/mirrorlist=http://mirrors.fedoraproject.org/mirrorlist?repo=fedora-debug-$releasever&arch=$basearchenabled=0gpgcheck=1gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-fedora-$basearch[fedora-source]
name=Fedora $releasever - Source
failovermethod=priority
#baseurl=http://download.fedoraproject.org/pub/fedora/linux/releases/$releasever/Everything/source/SRPMS/mirrorlist=http://mirrors.fedoraproject.org/mirrorlist?repo=fedora-source-$releasever&arch=$basearchenabled=0gpgcheck=1gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-fedora-$basearch

配置YUM源的步驟(原理)

 

 

下面看看rhel5.8自帶的repo文件

 

配置YUM源的步驟(原理)

[root@10gasm yum.repos.d]# cat rhel-debuginfo.repo 
[rhel-debuginfo]
name=Red Hat Enterprise Linux $releasever - $basearch - Debug
baseurl=ftp://ftp.redhat.com/pub/redhat/linux/enterprise/$releasever/en/os/$basearch/Debuginfo/enabled=0gpgcheck=1gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release

配置YUM源的步驟(原理)

我自己設(shè)置的本地yum庫

[root@10gasm yum.repos.d]# cat dvd.repo 
[dvd]
name=install dvd
baseurl=file:///mnt/Serverenabled=1gpgcheck=0

非常簡單。

 

可以使用下面的命令查看所有的容器配置(Repository)是否生效

yum repolist all

使用all參數(shù)列出了所有的容器配置,如果不加all只列出可用的Repository,這個(gè)可用性取決于repo配置文件中的enabled參數(shù),如果為0,則不可用,為1則可用

例如:

配置YUM源的步驟(原理)

[root@10gasm yum.repos.d]# yum repolist all
Loaded plugins: katello, product-id, security, subscription-manager
Updating certificate-based repositories.
Unable to read consumer identity
repo id                                           repo name                                                                       status
dvd                                               install dvd                                                                     enabled: 3,285rhel-debuginfo                                    Red Hat Enterprise Linux 5Server - x86_64 - Debug                               disabledrepolist: 3,285

配置YUM源的步驟(原理)

 顯示出dvd這個(gè)repository是可用的,有3285個(gè)文件,rhel-debuginfo這個(gè)庫是不可用的。

如果修改rhel-debuginfo中enabled為1然后再次查看

配置YUM源的步驟(原理)

[root@10gasm yum.repos.d]# yum repolist all
Loaded plugins: katello, product-id, security, subscription-manager
Updating certificate-based repositories.
Unable to read consumer identityftp://ftp.redhat.com/pub/redhat/linux/enterprise/5Server/en/os/x86_64/Debuginfo/repodata/repomd.xml: [Errno 4] IOError: <urlopen error (-3, 'Temporary failure in name resolution')>Trying other mirror.
repo id                                           repo name                                                                      status
dvd                                               install dvd                                                                    enabled: 3,285rhel-debuginfo                                    Red Hat Enterprise Linux 5Server - x86_64 - Debug                              enabled:     0repolist: 3,285







配置好以后,執(zhí)行yum update,報(bào)錯(cuò):Error performing checksum

 

[root@web1 yum.repos.d]# yum update

Loaded plugins: katello, product-id,security, subscription-manager

Updating certificate-based repositories.

Unable to read consumer identity

base                                                                                                        | 3.7 kB     00:00    

base/primary_db                                                                                              |4.4 MB     00:02    

http://mirrors.ustc.edu.cn/centos/6.4/os/x86_64/repodata/1e584feac3f3fb76ad4b6fb7e1bc8d44fa124814e9d186dc913ded3c63a216b3-primary.sqlite.bz2: [Errno -3]  Error performingchecksum

Trying other mirror.

base/primary_db                                                                                             | 4.4 MB     00:02    

http://mirrors.ustc.edu.cn/centos/6.4/os/x86_64/repodata/1e584feac3f3fb76ad4b6fb7e1bc8d44fa124814e9d186dc913ded3c63a216b3-primary.sqlite.bz2: [Errno -3] Error performing checksum

Trying other mirror.

Error: failure:repodata/1e584feac3f3fb76ad4b6fb7e1bc8d44fa124814e9d186dc913ded3c63a216b3-primary.sqlite.bz2from base: [Errno 256] No more mirrors to try.

 

 

google了一下,說是在rhel 6 中 repomd.xml 文件使用 sha256 作為hash  算法  ,在rhel 5中 默認(rèn)使用的是sha 作為hash 算法。

 

但我是在redhat 5.8 上使用5.9的yum。 也出現(xiàn)了這種錯(cuò)誤。

# yum clean all 清空yum的注冊(cè)記錄.


向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請(qǐng)聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI