之前寫的2篇有關YUM文章:
Linux yum 命令介紹
http://blog.csdn.net/tianlesoftware/archive/2009/12/28/5092720.aspx
Linux yum 安裝
http://blog.csdn.net/tianlesoftware/archive/2010/03/15/5381522.aspx
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@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 ./images/pxeboot
8914 ./images/xen
166766 ./images
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
用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]#
------------------------------------------------------------------------------