YUM是Yellow dog Updater, Modified的缩写,是由Duke University所发起的计划,目的就是为了解决RPM的依赖关系的问题,方便使用者进行软件的安装、升级等等工作。在此在特别说明的是,YUM只是为了解决RPM的依赖关系的问题,而不是一种其它的软件安装模式。当然可以实现这样功能的除了YUM外,还有APT (Advanced Package Tool,是由debian所发展的一个软件管理工具)。

        YUM的工作原理,在每一个 RPM软件的头(header)里面都会纪录该软件的依赖关系,那么如果可以将该头的内容纪录下来并且进行分析,可以知道每个软件在安装之前需要额外安装哪些基础软件。也就是说,在服务器上面先以分析工具将所有的RPM档案进行分析,然后将该分析纪录下来,只要在进行安装或升级时先查询该纪录的文件,就可以知道所有相关联的软件。

 

所以YUM的基本工作流程如下:

       服务器端:在服务器上面存放了所有的RPM软件包,然后以相关的功能去分析每个RPM文件的依赖性关系,将这些数据记录成文件存放在服务器的某特定目录内。

       客户端:如果需要安装某个软件时,先下载服务器上面记录的依赖性关系文件(可通过WWW或FTP方式),通过对服务器端下载的纪录数据进行分析,然后取得所有相关的软件,一次全部下载下来进行安装。

  在这篇文章里,我们配置通过FTP的YUM服务器。 在RHEL的安装盘上有所有的YUM包。 我们只需要把这些YUM 软件放到硬盘上,并配置好FTP。 在客户端修改相关的YUM 参数就可以了。

 

 

一. 服务器端配置

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

[root@felix ~]# 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@felix ~]# chkconfig vsftpd on

[root@felix ~]# chkconfig vsftpd --list

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

[root@felix ~]#service vsftpd restart

Shutting down vsftpd:                                      [FAILED]

Starting vsftpd for vsftpd:                                [  OK  ]

[root@centos Server]#

 

linux FTP 的配置,这里只演示如何使用。

 

 

1.2 将DVD中的RPM包复制到/temp目录下

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

 

 

 

[root@felix temp]# pwd

/temp

 

[root@felix temp]# du -k

276     ./Cluster/repodata

69816   ./Cluster

11416   ./Server/repodata

2639216 ./Server

204     ./VT/repodata

47928   ./VT

160     ./ClusterStorage/repodata

10468   ./ClusterStorage

2767432 .

 

 

 

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

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

 

 

1.3.1 检查包安装情况

 

[root@felix ~]# rpm -q yum

yum-3.2.22-20.el5

[root@felix ~]# rpm -q createrepo

createrepo-0.4.11-3.el5

如果没有安装,请按照以下步骤进行安装

 

[root@felix ~]# rpm -ivh createrepo-0.4.11-3.el5.rpm

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

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

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

 

 

 

1.3.2 重建分组及依赖关系

 

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

 

 

[root@felix repodata]# pwd

/temp/Server/repodata

[root@felix repodata]# ls

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

 

 

 

 

重建Server:

[root@felix temp]# createrepo -g /temp/Server/repodata/comps-rhel5-server-core.xml /temp/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@felix temp]#

 

 

 

 

重建VT:

[root@felix temp]# createrepo -g /temp/VT/repodata/comps-rhel5-vt.xml /temp/VT/

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

Saving Primary metadata

Saving file lists metadata

Saving other metadata

 

重建Cluster:

[root@felix temp]# createrepo -g /temp/Cluster/repodata/comps-rhel5-cluster.xml /temp/Cluster/

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

Saving Primary metadata

Saving file lists metadata

Saving other metadata

 

重建ClusterStorage:

[root@felix temp]# createrepo -g /temp/ClusterStorage/repodata/comps-rhel5-cluster-st.xml /temp/ClusterStorage/

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

Saving Primary metadata

Saving file lists metadata

Saving other metadata

 

 

1.4 服务端文件配置

     声明:为了使yum更好服务我们的服务器,这里介绍两种方法,一是针对服务端本身而言,可以方便服务端进行组件包的维护;二是针对客户端而言,需要更新的组件包来自服务端

 

服务端

1.4.1 在yum服务端创建以下文件

 

[root@felix ~]# cat /etc/yum.repos.d/rhel-debuginfo.repo

[rhel-base]

name=Red Hat Enterprise Linux

baseurl=file:///temp/Server

enabled=1

gpgcheck=0

#gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release

 

[rhel-vt]

name=Red Hat Enterprise Linux 

baseurl=file:///temp/VT

enabled=1

gpgcheck=0

#gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release

 

[rhel-Cluster]

name=Red Hat Enterprise Linux 

baseurl=file:///temp/Cluster

enabled=1

gpgcheck=0

#gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release

 

[rhel-ClusterStorage]

name=Red Hat Enterprise Linux 

baseurl=file:///temp/ClusterStorage

enabled=1

gpgcheck=0

#gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release

 

 

用yum来查询当前主机安装哪些组件包

 

[root@felix ~]# yum grouplist

Loaded plugins: rhnplugin, security

This system is not registered with RHN.

RHN support will be disabled.

Setting up Group Process

Installed Groups:

   Administration Tools

   DNS Name Server

   Development Libraries

   Development Tools

   Editors

   Engineering and Scientific

   FTP Server

   Graphical Internet

   Graphics

   Java Development

   KDE (K Desktop Environment)

   Legacy Network Server

   Legacy Software Development

   Legacy Software Support

   Network Servers

   OpenFabrics Enterprise Distribution

   Server Configuration Tools

   System Tools

   Text-based Internet

   Web Server

   X Window System

Available Groups:

   Authoring and Publishing

   Cluster Storage

   Clustering

   GNOME Desktop Environment

   GNOME Software Development

   Games and Entertainment

   KDE Software Development

   Mail Server

   MySQL Database

   News Server

   Office/Productivity

   PostgreSQL Database

   Printing Support

   Sound and Video

   Virtualization

   Windows File Server

   X Software Development

Done

 

 

以上信息表示yum配置成功

 

 

客户端

1.4.1 在客户端创建以下文件(文件路径与服务端相同"/etc/yum.repos.d")

 

 

 

[root@felix ~]# cat /etc/yum.repos.d/rhel-debuginfo.repo

[rhel-base]

name=Red Hat Enterprise Linux

baseurl=ftp://192.168.16.199/temp/Server

enabled=1

gpgcheck=0

 

[rhel-vt]

name=Red Hat Enterprise Linux 

baseurl=ftp://192.168.16.199/temp/VT

enabled=1

gpgcheck=0

 

[rhel-Cluster]

name=Red Hat Enterprise Linux 

baseurl=ftp://192.168.16.199/temp/Cluster

enabled=1

gpgcheck=0

 

[rhel-ClusterStorage]

name=Red Hat Enterprise Linux 

baseurl=ftp://192.168.16.199/temp/ClusterStorage

enabled=1

gpgcheck=0

 

 

 

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

 

 

 

 

相关参数说明:

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

       name:仓库的描述.

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

       enabled :是否启用这个仓库,1为起用,0为禁用

       gpgcheck :是否检查GPG签名(验证要安装的包是不是REDHAT官方的)。