一、YUM的配置与使用

yum的配置一般有两种方式,一种是直接配置/etc目录下的yum.conf文件,另外一种是在/etc/yum.repos.d目录下增加.repo文件。

1、  yum的配置文件

[root@eurasiaxz ~]# more /etc/yum.conf
[main]
cachedir=/var/cache/yum/$basearch/$releaseve			#yum下载的RPM包的缓存目录
keepcache=0										#缓存是否保存,1保存,0不保存
debuglevel=2			#调试级别(0-10),默认为2(具体调试级别的应用,我也不了解)
logfile=/var/log/yum.log								#yum的日志文件所在的位置
exactarch=1			#在更新的时候,是否允许更新不同版本的RPM包,比如是否在i386上更新i686的RPM包
obsoletes=1			#这是一个update的参数,具体请参阅yum(8),简单的说就是相当于upgrade,允许更新陈旧的RPM包
gpgcheck=1			#是否检查GPG(GNU Private Guard),一种密钥方式签名
plugins=1				#是否允许使用插件,默认是0不允许,但是我们一般会用yum-fastestmirror这个插件
installonly_limit=5									#允许保留多少个内核包
bugtracker_url=http://bugs.centos.org/set_project.php?project_id=16&ref=http://bugs.centos.org/bug_report_page.php?category=yum
distroverpkg=centos-release

#  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

2、*.repo文件详解

什么是repo文件?repo文件是CentOS中yum源(软件仓库)的配置文件,通常一个repo文件定义了一个或者多个软件仓库的细节内容,例如我们将从哪里下载需要安装或者升级的软件包,repo文件中的设置内容将被yum读取和应用!

我们以一份系统自带的repo文件做为实例来探讨(#号后面是我加的注释):

[root@eurasiaxz yum.repos.d]# more CentOS-Base.repo 
# CentOS-Base.repo
#
# The mirror system uses the connecting IP address of the client and the
# update status of each mirror to pick mirrors that are updated to and
# geographically close to the client.  You should use this for CentOS updates
# unless you are manually picking other mirrors.
#
# If the mirrorlist= does not work for you, as a fall back you can try the 
# remarked out baseurl= line instead.
#
#

[base]			#方括号里面的是软件源的名称,将被yum取得并识别
name=CentOS-$releasever – Base
#这里也定义了软件仓库的名称,通常是为了方便阅读配置文件,一般没什么作用

failovermethod=priority
#failovermethod 有两个值可以选择,priority是默认值,表示从列出的baseurl中顺序选择镜像服务器地址,roundrobin表示在列出的服务器中随机选择

exclude=compiz* *compiz* fusion-icon*
#exclude这个选项是后来我自己加上去的,用来禁止这个软件仓库中的某些软件包的安装和更新,可以使用通配符,并以空格分隔,可以视情况需要自行添加

mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os
#上面的这一行是指定一个镜像服务器的地址列表,通常是开启的,我们可以试试,将$releasever和$basearch替换成自己对应的版本和架构,例如6.4和i386,在浏览器中打开,我们就能看到一长串镜可用的镜像服务器地址列表。(备注:$releasever变量定义了发行版本,通常是8,9,10等数字,$basearch变量定义了系统的架构,可以是i386、x86_64、ppc等值,这两个变量根据当前系统的版本架构不同而有不同的取值,这可以方便yum升级的时候选择 适合当前系统的软件包,以下同……)

#baseurl=http://mirror.centos.org/centos/$releasever/os/$basearch/
#上面的一行baseurl第一个字符是'#'表示该行已经被注释,将不会被读取,这一行的意思是指定一个baseurl(源的镜像服务器地址)

enabled=1
#这个选项表示这个repo中定义的源是启用的,0为禁用

gpgcheck=1
#这个选项表示这个repo中下载的rpm将进行gpg的校验,已确定rpm包的来源是有效和安全的

gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
#定义用于校验的gpg密钥