说明: 经过网上抄袭和自己的总结加实验, 非常详细, 可留作参考.
yum 的配置一般有两种方式: 一种是直接配置 / etc 目录下的 yum.conf 文件, 另外一种是在 / etc/yum.repos.d 目录下增加. repo 文件.
一, yum 的配置文件 yum.conf 详解
- view source http://www.it165.net/os/html/201409/9273.html#viewSource http://www.it165.net/os/html/201409/9273.html#printSource ? http://www.it165.net/os/html/201409/9273.html#about
- 01.$ cat /etc/yum.conf
- 02.
- 03.
- [main]
- 04.
- cachedir=/var/cache/yum #yum 下载的 RPM 包的缓存目录
- 05.
- keepcache=0
- # 缓存是否保存,
1 保存, 0 不保存.
- 06.
- debuglevel=2 #调试级别(0-
- 10
), 默认为 2
- (具体调试级别的应用, 我也不了解).
- 07.
- logfile=/var/log/yum.log #yum 的日志文件所在的位置
- 08.
- exactarch=1
- # 在更新的时候, 是否允许更新不同版本的 RPM 包, 比如是否在 i386 上更新 i686 的 RPM 包.
- 09.
- obsoletes=1
- # 这是一个 update 的参数, 具体请参阅 yum(
- 8
), 简单的说就是相当于 upgrade, 允许更新陈旧的 RPM 包.
- 10.
- gpgcheck=1
- # 是否检查 GPG(GNU Private Guard), 一种密钥方式签名.
- 11.
- plugins=1
- # 是否允许使用插件, 默认是
- 0
不允许, 但是我们一般会用 yum-fastestmirror 这个插件.
- 12.
- installonly_limit=
- 3
- # 允许保留多少个内核包.
- 13.
- exclude=selinux* #屏蔽不想更新的 RPM 包, 可用通配符, 多个 RPM 包之间使用空格分离.
- 14.
- # This is the
- default, if you make this
- bigger yum won't see
- if the metadata
- 15.
- # is newer on the remote and so you'll"gain"
- the bandwidth of not having to
- 16.
- # download the new metadata and "pay" for
- it by yum not having correct
- 17.
- # information.
- 18.
- # It is esp. important, to have correct metadata,
- for distributions like
- 19.
- # Fedora which don
- 't keep old packages around. If you don'
t like this checking
- 20.
- # interupting your command line usage, it's much better to have something
- 21.
- # manually check the metadata once an hour (yum-updatesd will
do this).
- 22.
- # metadata_expire=90m
- 23.
- # PUT YOUR REPOS HERE or IN separate files named file.repo
- 24.
- # in /etc/yum.repos.d
二,*.repo 文件详解 什么是 repo 文件? repo 文件是 Fedora 中 yum 源 (软件仓库) 的配置文件, 通常一个 repo 文件定义了一个或者多个软件仓库的细节内容, 例如我们将从哪里下载需要安装或者升级的软件包, repo 文件中的设置内容将被 yum 读取和应用!
我们以一份系统自带的 repo 文件做为实例来探讨(Fedora 和 redhat 是一致的)(# 号后面是我加的注释):
- view source http://www.it165.net/os/html/201409/9273.html#viewSource http://www.it165.net/os/html/201409/9273.html#printSource ? http://www.it165.net/os/html/201409/9273.html#about
- 01.
- [fedora] #方括号里面的是软件源的名称, 将被 yum 取得并识别
- 02.
- 03.
- name=Fedora $releasever - $basearch #这里也定义了软件 仓库的名称, 通常是为了方便阅读配置文件, 一般没什么作用,$releasever 变量定义了发行版本, 通常是
- 8
- ,
- 9
- ,
- 10
等数字,$basearch 变 量定义了系统的架构, 可以是 i386,x86_64,ppc 等值, 这两个变量根据当前系统的版本架构不同而有不同的取值, 这可以方便 yum 升级的时候选择 适合当前系统的软件包, 以下同......
- 04.
- failovermethod=priority #failovermethod 有两个值可以选择, priority 是默认值, 表示从列出的 baseurl 中顺序选择镜像服务器地址, roundrobin 表示在列出的服务器中随机选择
- 05.
- exclude=compiz* *compiz* fusion-icon* #exclude 这个选项是后来我自己加上去的, 用来禁止这个软件仓库中的某些软件包的安装和更新, 可以使用通配符, 并以空格分隔, 可以视情况需要自行添加
- 06.
- #baseurl=http:
- //download.fedoraproject.org/pub/fedora/linux/releases/$releasever/Everything/$basearch/os/
- 07.
- # 上面的一行 baseurl 第一个字符是
- '#'
表示该行已经被注释, 将不会被读取, 这一行的意思是指定一个 baseurl(源的镜像服务器地址)
- 08.
- #mirrorlist=http:
- //mirrors.fedoraproject.org/mirrorlist?repo=fedora-$releasever&arch=$basearch
- 09.
- # 上面的这一行是指定一个镜像服务器的地址列表, 通常是开启的, 本例中加了注释符号禁用了, 我们可以试试, 将 $releasever 和 $basearch 替换成自己对应的版本和架构, 例如
- 10
和 i386, 在 < a href=
- "http://www.it165.net/edu/ewl/"
- target="_blank" class="keylink"
>浏览器</a > 中打开, 我们就能看到一长串镜可用的镜像服务器地址列表.
10.
选择自己访问速度较快的镜像服务器地址复制并粘贴到 repo 文件中, 我们就能获得较快的更新速度了, 格式如下 baseurl 所示:
- 11.
- baseurl=
- 12.
- ftp:
- //ftp.sfc.wide.ad.jp/pub/<a href="http://www.it165.net/os/oslin/" target="_blank" class="keylink">Linux</a>/Fedora/releases/10/Everything/i386/os
- 13.
- http:
- //ftp.chg.ru/pub/<a href="http://www.it165.net/os/oslin/" target="_blank" class="keylink">Linux</a>/fedora/linux/releases/10/Everything/i386/os
- 14.
- http:
- //ftp.yz.yamagata-u.ac.jp/pub/linux/fedora/linux/releases/10/Everything/i386/os
- 15.
- http:
- //mirror.nus.edu.sg/fedora/releases/10/Everything/i386/os
- 16.
- http:
- //mirror.yandex.ru/fedora/linux/releases/10/Everything/i386/os
- 17.
- http:
- //ftp.twaren.net/Linux/Fedora/linux/releases/10/Everything/i386/os
- 18.
- http:
- //ftp.itu.edu.tr/Mirror/Fedora/linux/releases/10/Everything/i386/os
- 19.
- 20.
- enabled=1
- # 这个选项表示这个 repo 中定义的源是启用的,
0 为禁用
- 21.
- gpgcheck=1
- # 这个选项表示这个 repo 中下载的 rpm 将进行 gpg 的校验, 已确定 rpm 包的来源是有效和安全的
- 22.
- gpgkey=file:
- ///etc/pki/rpm-gpg/RPM-GPG-KEY-fedora-$basearch #定义用于校验的 gpg 密钥, 就是数位签章的公钥档所在位置!
- 23.
- 24.
- ## 以下的软件仓库基本上用不到, 选项含义同上
- 25.
- [fedora-debuginfo]
- 26.
- name=Fedora $releasever - $basearch - Debug
- 27.
- failovermethod=priority
- 28.
- #baseurl=http:
- //download.fedoraproject.org/pub/fedora/linux/releases/$releasever/Everything/$basearch/debug/
- 29.
- mirrorlist=http:
- //mirrors.fedoraproject.org/mirrorlist?repo=fedora-debug-$releasever&arch=$basearch
- 30.
- enabled=0
- 31.
- gpgcheck=1
- 32.
- gpgkey=file:
- ///etc/pki/rpm-gpg/RPM-GPG-KEY-fedora-$basearch
- 33.
- 34.
- [fedora-source]
- 35.
- name=Fedora $releasever - Source
- 36.
- failovermethod=priority
- 37.
- #baseurl=http:
- //download.fedoraproject.org/pub/fedora/linux/releases/$releasever/Everything/source/SRPMS/
- 38.
- mirrorlist=http:
- //mirrors.fedoraproject.org/mirrorlist?repo=fedora-source-$releasever&arch=$basearch
- 39.
- enabled=0
- 40.
- gpgcheck=1
- 41.
- gpgkey=file:
- ///etc/pki/rpm-gpg/RPM-GPG-KEY-fedora-$basearch
下面看看 rhel5.8 自带的 repo 文件
- view source http://www.it165.net/os/html/201409/9273.html#viewSource http://www.it165.net/os/html/201409/9273.html#printSource ? http://www.it165.net/os/html/201409/9273.html#about
- 1.[root@10gasm
- yum.repos.d]# cat rhel-debuginfo.repo
- 2.[rhel-debuginfo]
- 3.
- name=Red Hat Enterprise Linux $releasever - $basearch - Debug
- 4.
- baseurl=ftp:
- //ftp.redhat.com/pub/redhat/linux/enterprise/$releasever/en/os/$basearch/Debuginfo/
- 5.
- enabled=0
- 6.
- gpgcheck=1
- 7.
- gpgkey=file:
- ///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release
我自己设置的本地 yum 库
- view source http://www.it165.net/os/html/201409/9273.html#viewSource http://www.it165.net/os/html/201409/9273.html#printSource ? http://www.it165.net/os/html/201409/9273.html#about
- 1.[root@10gasm
- yum.repos.d]# cat dvd.repo
- 2.[dvd]
- 3.
- name=install dvd
- 4.
- baseurl=file:///mnt/Server
- 5.
- enabled=1
- 6.
- gpgcheck=0
非常简单. 可以使用下面的命令查看所有的容器配置 (Repository) 是否生效
- view source http://www.it165.net/os/html/201409/9273.html#viewSource http://www.it165.net/os/html/201409/9273.html#printSource ? http://www.it165.net/os/html/201409/9273.html#about
- 1.yum repolist all
使用 all 参数列出了所有的容器配置, 如果不加 all 只列出可用的 Repository, 这个可用性取决于 repo 配置文件中的 enabled 参数, 如果为 0, 则不可用, 为 1 则可用 例如:
- view source http://www.it165.net/os/html/201409/9273.html#viewSource http://www.it165.net/os/html/201409/9273.html#printSource ? http://www.it165.net/os/html/201409/9273.html#about
- 1.[root@10gasm
- yum.repos.d]# yum repolist all
- 2.
- Loaded plugins: katello, product-id, security, subscription-manager
- 3.
- Updating certificate-based repositories.
- 4.
- Unable to read consumer identity
- 5.
- repo id repo name status
- 6.
- dvd install dvd <strong>enabled:
- 3
- ,
- 285
- </strong>
- 7.
- rhel-debuginfo Red Hat Enterprise Linux 5Server - x86_64 - Debug <strong>disabled</strong>
- 8.
- repolist:
- 3
- ,
- 285
显示出 dvd 这个 repository 是可用的, 有 3285 个文件, rhel-debuginfo 这个库是不可用的.
如果修改 rhel-debuginfo 中 enabled 为 1 然后再次查看
- view source http://www.it165.net/os/html/201409/9273.html#viewSource http://www.it165.net/os/html/201409/9273.html#printSource ? http://www.it165.net/os/html/201409/9273.html#about
- 01.[root@10gasm
- yum.repos.d]# yum repolist all
- 02.
- Loaded plugins: katello, product-id, security, subscription-manager
- 03.
- Updating certificate-based repositories.
- 04.
- Unable to read consumer identity
- 05.
- ftp:
- //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')>
- 06.
- Trying other mirror.
- 07.
- repo id repo name status
- 08.
- dvd install dvd enabled:
- 3
- ,
- 285
- 09.
- rhel-debuginfo Red Hat Enterprise Linux 5Server - x86_64 - Debug <strong>enabled:
- 0</strong>
- 10.
- repolist:
- 3
- ,
- 285
- <br>
来源: http://www.bubuko.com/infodetail-2706140.html