YUM的基本工作流程如下:
       服务器端:在服务器上面存放了所有的RPM软件包,然后以相关的功能去分析每个RPM文件的依赖性关系,将这些数据记录成文件存放在服务器的某特定目录内。
       客户端:如果需要安装某个软件时,先下载服务器上面记录的依赖性关系文件(可通过WWW或FTP方式),通过对服务器端下载的纪录数据进行分析,然后取得所有相关的软件,一次全部下载下来进行安装。
一. 服务器端配置
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]# ftp 127.0.0.1
1.2 复制RPM 包
       将RHEL 5.4光盘中的Server、VT、Cluster、ClusterStorage四个目录复制到/var/ftp/nmyum下
cp /mnt/cdrom/* ./
 
1.3. 安装createrepo包,并重建包依赖关系
       createrepo包是用来生成RPM 依赖关系及分组信息的。 搭建YUM服务器,必须要重建着2个信息。
[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仓库时,需要先重建该文件。 
重建Server:
[root@centos nmyum]# createrepo -g /var/ftp/nmyum/Server/repodata/comps-rhel5-server-core.xml /var/ftp/nmyum/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 nmyum]#
 
重建VT:
[root@centos nmyum]# createrepo -g /var/ftp/nmyum/VT/repodata/comps-rhel5-vt.xml  /var/ftp/ nmyum /VT/
36/36 - Virtualization-or-IN-5.2-11.noarch.rpm                                  
Saving Primary metadata
Saving file lists metadata
Saving other metadata
 
重建Cluster:
[root@centos nmyum]# createrepo -g /var/ftp/nmyum/Cluster/repodata/comps-rhel5-cluster.xml /var/ftp/nmyum/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 nmyum]# createrepo -g /var/ftp/nmyum/ClusterStorage/repodata/comps-rhel5-cluster-st.xml /var/ftp/nmyum/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.
      
这个是我CentOS上的部分内容。 其他的类似。 这个文件其实是在使用yum安装的客户端使用的。 我们在服务器创建这个配置文件的原因是方便使用。 假如在公司里的Linux客户端非常多,我们不必去修改每个客户端的这个YUN配置文件。 只需要从服务器上将这个文件下载到本机就可以了。
在YUM服务器上创建文件:
[rhel-server]
name=Red Hat Enterprise Linux server
baseurl=ftp://192.168.101.22/nmyum/Server
enabled=1
gpgcheck=1
gpgkey=ftp://192.168.101.22/nmyum/RPM-GPG-KEY-redhat-release
[rhel-vt]
name=Red Hat Enterprise Linux vt
baseurl=ftp://192.168.101.22/nmyum/VT
enabled=1
gpgcheck=1
gpgkey=ftp://192.168.101.22/nmyum/RPM-GPG-KEY-redhat-release
[rhel-clusterstorage]
name=Red Hat Enterprise Linux clusterstorage
baseurl=ftp://192.168.101.22/nmyum/ClusterStorage
enabled=1
gpgcheck=1  
gpgkey=ftp://192.168.101.22/nmyum/RPM-GPG-KEY-redhat-release
[rhel-cluster]
name=Red Hat Enterprise Linux cluster
baseurl=ftp://192.168.101.22/nmyum/Cluster     
enabled=1
gpgcheck=1
gpgkey=ftp://192.168.101.22/nmyum/RPM-GPG-KEY-redhat-release
       说明: 这里提供的只是一个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/nmyum/rhel54.86.repo
--2011-01-03 11:39:53--  ftp://192.168.6.2/nmyum/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
 
用yum 安装 ant :
[root@singledb yum.repos.d]# yum -y install ant
Loaded plugins: rhnplugin, security
This system is not registered with RHN.
RHN support will be disabled.
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package ant.i386 0:1.6.5-2jpp.2 set to be updated
--> Processing Dependency: xml-commons-apis for package: ant
--> Running transaction check
---> Package xml-commons-apis.i386 0:1.3.02-0.b2.7jpp.10 set to be updated
--> Processing Dependency: xml-commons = 1.3.02-0.b2.7jpp.10 for package: xml-commons-apis
--> Running transaction check
---> Package xml-commons.i386 0:1.3.02-0.b2.7jpp.10 set to be updated
--> Finished Dependency Resolution
 
Dependencies Resolved
 
====================================================================================================
 Package                    Arch           Version                        Repository           Size
====================================================================================================
Installing:
 ant                        i386           1.6.5-2jpp.2                   rhel-base           2.0 M
Installing for dependencies:
 xml-commons                i386           1.3.02-0.b2.7jpp.10            rhel-base            19 k
 xml-commons-apis           i386           1.3.02-0.b2.7jpp.10            rhel-base           335 k
 
Transaction Summary
====================================================================================================
Install      3 Package(s)        
Update       0 Package(s)        
Remove       0 Package(s)        
 
Total download size: 2.4 M
Downloading Packages:
(1/3): xml-commons-1.3.02-0.b2.7jpp.10.i386.rpm                              |  19 kB     00:00    
(2/3): xml-commons-apis-1.3.02-0.b2.7jpp.10.i386.rpm                         | 335 kB     00:00    
(3/3): ant-1.6.5-2jpp.2.i386.rpm                                             | 2.0 MB     00:00    
----------------------------------------------------------------------------------------------------
Total                                                               3.3 MB/s | 2.4 MB     00:00    
Running rpm_check_debug
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing     : xml-commons                                                                  1/3
  Installing     : xml-commons-apis                                                             2/3
  Installing     : ant                                                                          3/3
 
Installed:
  ant.i386 0:1.6.5-2jpp.2                                                                          
 
Dependency Installed:
  xml-commons.i386 0:1.3.02-0.b2.7jpp.10         xml-commons-apis.i386 0:1.3.02-0.b2.7jpp.10       
 
Complete!
[root@singledb yum.repos.d]#
 
 
 
 本地yum 的话只需改变一下
 Vim /etc/yum.repo.d/server1.repo
[rhel-server]
name=Red Hat Enterprise Linux server
baseurl=file:///mnt/cdrom/Server
enabled=1
gpgcheck=1
gpgkey=file:///mnt/cdrom/RPM-GPG-KEY-redhat-release
[rhel-vt]
name=Red Hat Enterprise Linux vt
baseurl=file:///mnt/cdrom/VT
enabled=1
gpgcheck=1
gpgkey=file:///mnt/cdrom/RPM-GPG-KEY-redhat-release
 
[rhel-cluster]
name=Red Hat Enterprise Linux cluster
baseurl=file:///mnt/cdrom/Cluster
enabled=1
gpgcheck=1
gpgkey=file:///mnt/cdrom/RPM-GPG-KEY-redhat-release
 
[rhel-clusterstorage]
name=Red Hat Enterprise Linux clusterstorage
baseurl=file:///mnt/cdrom/ClusterStorage
enabled=1
gpgcheck=1
gpgkey=file:///mnt/cdrom/RPM-GPG-KEY-redhat-release

本文出自 “心灵规划” 博客,请务必保留此出处http://haoxiaoyang.blog.51cto.com/4449963/786155