yum是什么
yum = Yellow dog Updater, Modified
主要功能是更方便的添加/删除/更新RPM包.
它能自动解决包的倚赖性问题.
它能便于管理大量系统的更新问题
yum特点
可以同时配置多个资源库(Repository)
简洁的配置文件(/etc/yum.conf
自动解决增加或删除rpm包时遇到的倚赖性问题
使用方便
保持与RPM数据库的一致性
yum安装
CentOS自带(yum-*.noarch.rpm)
#rpm -ivh yum-*.noarch.rpm
在第一次启用yum之前首先需要导入系统的RPM-GPG-KEY:
#rpm --import /usr/share/doc/centos-release-3(4)/RPM-GPG-KEY-CentOS-3(4)
yum指令
注:当第一次使用yum或yum资源库有更新时,yum会自动下载所有所需的headers放置于/var/cache/yum目录下,所需时间可能较长.
rpm包的更新
检查可更新的rpm包
#yum check-update
更新所有的rpm包
#yum update
更新指定的rpm包,如更新kernel和kernel source
#yum update kernel kernel-source
大规模的版本升级,与yum update不同的是,连旧的淘汰的包也升级
#yum upgrade
rpm包的安装和删除
安装rpm包,如xmms-mp3
#yum install xmms-mp3
删除rpm包,包括与该包有倚赖性的包
#yum remove licq
注:同时会提示删除licq-gnome,licq-qt,licq-text
yum暂存(/var/cache/yum/)的相关参数
清除暂存中rpm包文件
#yum clean packages
清除暂存中rpm头文件
#yum clearn headers
清除暂存中旧的rpm头文件
#yum clean oldheaders
清除暂存中旧的rpm头文件和包文件
#yum clearn 或#yum clearn all
注:相当于yum clean packages + yum clean oldheaders
包列表
列出资源库中所有可以安装或更新的rpm包
#yum list
列出资源库中特定的可以安装或更新以及已经安装的rpm包
#yum list mozilla#yum list mozilla*
注:可以在rpm包名中使用匹配符,如列出所有以mozilla开头的rpm包
列出资源库中所有可以更新的rpm包
#yum list updates
列出已经安装的所有的rpm包
#yum list installed
列出已经安装的但是不包含在资源库中的rpm包
#yum list extras
注:通过其它网站下载安装的rpm包
rpm包信息显示(info参数同list)
列出资源库中所有可以安装或更新的rpm包的信息
#yum info
列出资源库中特定的可以安装或更新以及已经安装的rpm包的信息
#yum info mozilla#yum info mozilla*
注:可以在rpm包名中使用匹配符,如列出所有以mozilla开头的rpm包的信息
列出资源库中所有可以更新的rpm包的信息
#yum info updates
列出已经安装的所有的rpm包的信息
#yum info installed
列出已经安装的但是不包含在资源库中的rpm包的信息
#yum info extras
注:通过其它网站下载安装的rpm包的信息
搜索rpm包
搜索匹配特定字符的rpm包
#yum search mozilla
注:在rpm包名,包描述等中搜索
搜索有包含特定文件名的rpm包
#yum provides realplay
增加资源库
例如:增加rpm.livna.org作为资源库
安装Livna.org rpms GPG key
#rpm --import http://rpm.livna.org/RPM-LIVNA-GPG-KEY
检查GPG Key
# rpm -qa gpg-pubkey*
显示Key信息
#rpm -qi gpg-pubkey-a109b1ec-3f6e28d5
(注:如果要删除Key,使用#rpm -e gpg-pubkey-a109b1ec-3f6e28d5)
yum常用的命令
# yum install xxx            安装xxx软件
# yum info xxx                查看xxx软件的信息
# yum remove xxx        删除软件包
# yum list                        列出软件包
# yum clean                    清除缓冲和就的包
# yum provides xxx        以xxx为关键字搜索包(提供的信息为关键字)
# yum search xxx           搜索软件包(以名字为关键字)
# yum groupupdate xxx
# yum grouplist xxx
# yum groupremove xxx
这三个都是一组为单位进行升级 列表和删除的操作。。比如 "Mysql Database"就是一个组会同时操作相关的所有软件包;
# yum update                系统升级
# yum list available        列出所有升级源上的包;
# yum list updates         列出所有升级源上的可以更新包;
# yum list installed         列出已经安装的包;
# yun update kernel       升级内核;
yum常用的源
1) 自动选择最快的源
由于yum中有的mirror速度是非常慢的,如果yum选择了这个mirror,这个时候yum就会非常慢,对此,可以下载fastestmirror插件,它会自动选择最快的mirror:
#yum install yum-fastestmirror
配置文件:(一般不用动)/etc/yum/pluginconf.d/fastestmirror.conf
你的yum镜像的速度测试记录文件:/var/cache/yum/timedhosts.txt
(2)使用图形界面的yum
如果觉得命令行的yum不方便,那么可以使用图形化的yumex,这个看起来更方便,因为可以自由地选择软件仓库:
#yum install yumex

然后在系统工具中就可以看到yum extender了。实际上系统自带的“添加/删除程序“也可以实现图形化的软件安装,但有些yumex的功能它没有。


. 服务器端配置

1.1  安装FTP 服务,并配置自启动

[root@centos Server]# rpm -ivh vsftpd-2.0.5-16.el5.i386.rpm

warning: vsftpd-2.0.5-16.el5.i386.rpm: Header V3 DSA signature: NOKEY, key ID 37017186

Preparing...                ########################################### [100%]

  1:vsftpd                 ########################################### [100%]

[root@centos Server]# chkconfig vsftpd on

[root@centos Server]# chkconfig vsftpd --list

vsftpd          0:off   1:off   2:on    3:on    4:on    5:on    6:off

[root@centos Server]# service vsftpd restart

Shutting down vsftpd:                                      [FAILED]

Starting vsftpd for vsftpd:                                [  OK  ]

[root@centos Server]#

linux FTP 的配置,在下篇文章里会做说明, 这篇只演示如何使用。

1.2 复制RPM

将RHEL 5光盘中的Server、VT、Cluster、ClusterStorage四个目录复制到/var/ftp/pub下。

[root@centos RHEL_5.4 i386 DVD]# du -k

253     ./Cluster/repodata

69571   ./Cluster

143     ./ClusterStorage/repodata

10300   ./ClusterStorage

10546   ./Server/repodata

2626369 ./Server

182     ./VT/repodata

47724   ./VT

8512    ./p_w_picpaths/pxeboot

8914    ./p_w_picpaths/xen

166766  ./p_w_picpaths

8646    ./isolinux

2934671 .

[root@centos RHEL_5.4 i386 DVD]# cp -rf Cluster /var/ftp/pub/

[root@centos RHEL_5.4 i386 DVD]# cp -rf ClusterStorage /var/ftp/pub/

[root@centos RHEL_5.4 i386 DVD]# cp -rf VT /var/ftp/pub/          

[root@centos RHEL_5.4 i386 DVD]# cp -rf Server/ /var/ftp/pub/

[root@centos pub]# pwd

/var/ftp/pub

[root@centos pub]# ls

Cluster  ClusterStorage  Server  VT

[root@centos pub]# du -k

276     ./Cluster/repodata

69816   ./Cluster

10584   ./Server/repodata

2638388 ./Server

160     ./ClusterStorage/repodata

10468   ./ClusterStorage

200     ./VT/repodata

47924   ./VT

2766600 .

[root@centos pub]#

1.3. 安装createrepo包,并重建包依赖关系

      createrepo包是用来生成RPM 依赖关系及分组信息的。 搭建YUM服务器,必须要重建着2个信息。

1.3.1 检查包安装情况

[root@centos Server]# rpm -q yum

yum-3.2.22-20.el5.centos

[root@centos Server]# rpm -q createrepo

package createrepo is not installed

[root@centos Server]# rpm -ivh createrepo-0.4.11-3.el5.noarch.rpm

warning: createrepo-0.4.11-3.el5.noarch.rpm: Header V3 DSA signature: NOKEY, key ID 37017186

Preparing...                ########################################### [100%]

  1:createrepo             ########################################### [100%]

[root@centos Server]# rpm -q createrepo

createrepo-0.4.11-3.el5

[root@centos Server]#

1.3.2 重建分组及依赖关系

在RHEL 5中每个目录下的repodata目录下都有一个repomd.xml,该文件中就记录了rpm包的依赖关系,还有一个comps-rhel5-*.xml文件,这个文件主要记录分组情况,建立yum仓库时,需要先重建该文件。

[root@centos repodata]# pwd

/var/ftp/pub/Server/repodata

[root@centos repodata]# ls

comps-rhel5-server-core.xml  filelists.xml.gz  other.xml.gz  primary.xml.gz  repomd.xml  TRANS.TBL

重建Server

[root@centos pub]# createrepo -g /var/ftp/pub/Server/repodata/comps-rhel5-server-core.xml /var/ftp/pub/Server/

2292/2292 - xorg-x11-xinit-1.0.2-15.el5.i386.rpm    --这里有2千多个包

Saving Primary metadata

Saving file lists metadata

Saving other metadata

[root@centos pub]#

重建VT

[root@centos pub]# createrepo -g /var/ftp/pub/VT/repodata/comps-rhel5-vt.xml /var/ftp/pub/VT/

36/36 - Virtualization-or-IN-5.2-11.noarch.rpm                                  

Saving Primary metadata

Saving file lists metadata

Saving other metadata

重建Cluster:

[root@centos pub]# createrepo -g /var/ftp/pub/Cluster/repodata/comps-rhel5-cluster.xml /var/ftp/pub/Cluster/

32/32 - Cluster_Administration-zh-TW-5.2-1.noarch.rpm                          

Saving Primary metadata

Saving file lists metadata

Saving other metadata

重建ClusterStorage

[root@centos pub]# createrepo -g /var/ftp/pub/ClusterStorage/repodata/comps-rhel5-cluster-st.xml /var/ftp/pub/ClusterStorage/

39/39 - Global_File_System-or-IN-5.2-1.noarch.rpm                              

Saving Primary metadata

Saving file lists metadata

Saving other metadata

[root@centos pub]#

1.4 修改YUM 配置文件

在每个客户端使用YUM时,必须需要修改配置文件。

我们先看文件: /etc/yum.repos.d/*.repo。 这个文件名称可以随便定义,但是扩展名必须是repo.

[root@centos pub]# cat /etc/yum.repos.d/CentOS-Base.repo

[base]

name=CentOS-$releasever - Base

mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os

#baseurl=http://mirror.centos.org/centos/$releasever/os/$basearch/

gpgcheck=1

gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-5

...

这个是我CentOS上的部分内容。 其他的类似。 这个文件其实是在使用yum安装的客户端使用的。 我们在服务器创建这个配置文件的原因是方便使用。 假如在公司里的Linux客户端非常多,我们不必去修改每个客户端的这个YUN配置文件。 只需要从服务器上将这个文件下载到本机就可以了。

YUM服务器上创建文件:

[root@centos pub]# cat /etc/yum.repos.d/rhel54.86.repo  

[rhel-base]

name= TianleSoftware Redhat Enterprise 5.4

baseurl=ftp://192.168.6.2/pub/Server

gpgcheck=0

enabled=1

[rhel-vt]

name= TianleSoftware Redhat Enterprise 5.4

baseurl=ftp://192.168.6.2/pub/VT

gpgcheck=0

enabled=1

[rhel-cluster]

name= TianleSoftware Redhat Enterprise 5.4

baseurl=ftp://192.168.6.2/pub/Cluster

gpgcheck=0

enabled=1

[rhel-ClusterStorage]

name= TianleSoftware Redhat Enterprise 5.4

baseurl=ftp://192.168.6.2/pub/ClusterStorage

gpgcheck=0

enabled=1

说明:这里提供的只是一个FTP地址,所以可以使用其他的方式来实现FTP。 不一定非要像第一步里说明的,使用LINUX的FTP。

相关参数说明:

[ ]内的是仓库的名字,不重复即可。

name仓库的描述.

baseurl: YUM源地址, 这里配置的是FTP,还可以是HTTP,FILE等。

enabled 是否启用这个仓库,1为起用,0为禁用
gpgcheck :是否检查GPG签名(验证要安装的包是不是REDHAT官方的)。

. 客户端配置

[root@singledb yum.repos.d]# cd /etc/yum.repos.d/                    

[root@singledb yum.repos.d]# wget ftp://192.168.6.2/pub/rhel54.86.repo

--2011-01-03 11:39:53--  ftp://192.168.6.2/pub/rhel54.86.repo

          => `rhel54.86.repo.1'

Connecting to 192.168.6.2:21... connected.

Logging in as anonymous ... Logged in!

==> SYST ... done.    ==> PWD ... done.

==> TYPE I ... done.  ==> CWD /pub ... done.

==> SIZE rhel54.86.repo ... 471

==> PASV ... done.    ==> RETR rhel54.86.repo ... done.

Length: 471

100%[==========================================================>] 471         --.-K/s   in 0s    

2011-01-03 11:39:53 (23.6 MB/s) - `rhel54.86.repo.1' saved [471]

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

Loaded plugins: rhnplugin, security

This system is not registered with RHN.

RHN support will be disabled.

rhel-ClusterStorage                                                          | 1.1 kB     00:00    

rhel-ClusterStorage/primary                                                  | 8.3 kB     00:00    

rhel-ClusterStorage                                                                           39/39

rhel-base                                                                    | 1.1 kB     00:00    

rhel-base/primary                                                            | 806 kB     00:00    

rhel-base                                                                                 2292/2292

rhel-cluster                                                                 | 1.1 kB     00:00    

rhel-cluster/primary                                                         | 5.9 kB     00:00    

rhel-cluster                                                                                  32/32

rhel-vt                                                                      | 1.1 kB     00:00    

rhel-vt/primary                                                              | 9.0 kB     00:00    

rhel-vt                                                                                       36/36

Skipping security plugin, no data

Setting up Update Process

No Packages marked for Update