yum介紹
為什麼要使用yum
Linux系統維護中令管理員很頭疼的就是軟件包之間的依賴性了,往往是你要安裝A軟件,但是編譯的時候告訴你X軟件安裝之前需要B軟件,而當你安裝Y軟件的時候,又告訴你需要Z庫了,好不容易安裝好Z庫,發現版本還有問題等。由於歷史原因,RPM軟件包管理系統對軟件之間的依存關系沒有內部定義,造成安裝RPM軟件時經常出現令人無法理解的軟件依賴問題。其實開源社區早就對這個問題嘗試進行解決了,不同的發行版推出了各自的工具,比如Yellow Dog的YUM(Yellow dog Updater, Modified),Debian的APT(Advanced Packaging Tool)等。開發這些工具的目的都是為了要解決安裝RPM時的依賴性問題,而不是額外再建立一套安裝模式。這些軟件也被開源軟件愛好者們逐漸移植到別的發行版上。
目前,APT和YUM都可以運行在Red Hat系統上。目前 yum 是Red Hat/Fedora系統上默認安裝的更新系統。
什麼是yum
YUM是Yellow dog Updater, Modified 的簡稱,起初是由yellow dog 發行版的開發者 Terra Soft 研發,用 python 寫成,那時叫做 yup (yellow dog updater),後經杜克大學的 Linux@Duke 開發團隊進行改進,遂有此名。yum 的宗旨是自動化地升級,安裝/移除rpm包,收集rpm包的相關信息,檢查依賴性並自動提示用戶解決。yum 的關鍵之處是要有可靠的 repository,顧名思義,這是軟件的倉庫,它可以是 http 或 ftp 站點,也可以是本地軟件池,但必須包含 rpm 的 header,header 包括了rpm 包的各種信息,包括描述,功能,提供的文件,依賴性等.正是收集了這些 header並加以分析,才能自動化地完成余下的任務。
yum 具有如下特點:
當用戶端有升級、安裝的需求時, yum 會向容器要求清單的升級,等到清單升級到本機的 /var/cache/yum 裡面後, 等一下升級時就會用這個本機清單與本機的 RPM 數據庫進行比較,這樣就知道該下載什麼軟件。接下來 yum 會跑到容器服務器 (yum server) 下載所需要的軟件,然後再透過 RPM 的機制開始安裝軟件啦!這就是整個流程.
內網YUM配置
在很多公司中,出於網絡安全、維護成本等方面的考慮,服務器並沒有接入到公共網絡。從”yum使用流程”示意圖可以看出,沒有接入公網的服務器默認 是無法訪問外部的yum服務器的,這樣yum帶給系統管理員的維護便利似乎一下子蕩然無存了。好在yum提供了簡潔的資源庫配置,結合ftp、http服 務,我們就可以很方便快速的打造出一個內網的yum服務器,以供其他內網Linux系統使用。
以下即是一個簡單的內網yum環境搭建示例。
環境
倉庫規劃
倉庫(repository)是一個預備好的目錄,或是一個網站,包含了軟件包和索引文件。 yum 可以在倉庫中自動地定位並獲取正確的 RPM 軟件包。這樣,您就不必手動搜索和安裝新應用程序和升級補丁了。只用一個命令,您就可以更新系統中所有軟件,也可以根據指定搜索目標來查找安裝新軟件。
[root@yum]# pwd /apps/yum [root@yum]# tree -L 3 . . └── centos └── 6.2_64 ├── addons ├── base ├── centosplus ├── contrib ├── extras └── updates 8 directories, 0 files
在本例中,YUM鏡像服務器為每個版本的 CentOS 分別提供了一些倉庫。其中,為CentOS 6.2 64bit提供了 以下幾個倉庫:
[root@yum]# createrepo centos/6.2_64/base 2762/6295 - gthumb-2.10.11-8.el6.x86_64.rpm
[root@yum]# pwd /apps/yum/centos/6.2_64/extras [root@server extras]# ll total 92 -rw-r--r-- 1 root root 92328 Dec 13 11:02 rlwrap-0.37-1.el6.x86_64.rpm [root@yum]# createrepo --update . 1/1 - rlwrap-0.37-1.el6.x86_64.rpm Saving Primary metadata Saving file lists metadata Saving other metadata [root@yum]# ll total 96 drwxr-xr-x 2 root root 4096 Apr 1 18:09 repodata -rw-r--r-- 1 root root 92328 Dec 13 11:02 rlwrap-0.37-1.el6.x86_64.rpm
[root@server html]# grep DocumentRoot /etc/httpd/conf/httpd.conf # DocumentRoot: The directory out of which you will serve your DocumentRoot "/var/www/html" # This should be changed to whatever you set DocumentRoot to. # DocumentRoot /www/docs/dummy-host.example.com [root@server html]# pwd /var/www/html [root@server html]# ln -s /apps/yum/ yum [root@server html]# ll total 0 lrwxrwxrwx 1 root root 10 Apr 1 17:39 yum -> /apps/yum/
[root@yum]# service httpd start Starting httpd:
yum測試
服務端測試
1.確認連接
[root@client]# ping yum.egolife.com PING yum.egolife.com (192.168.1.111) 56(84) bytes of data. 64 bytes from yum.egolife.com (192.168.1.111): icmp_seq=1 ttl=64 time=0.041 ms 64 bytes from yum.egolife.com (192.168.1.111): icmp_seq=2 ttl=64 time=0.039 ms 64 bytes from yum.egolife.com (192.168.1.111): icmp_seq=3 ttl=64 time=0.038 ms ^C --- yum.egolife.com ping statistics --- 3 packets transmitted, 3 received, 0% packet loss, time 2879ms rtt min/avg/max/mdev = 0.038/0.039/0.041/0.005 ms
2.更改yum倉庫配置
[root@yum]# vim /etc/yum.repos.d/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] name=CentOS-$releasever - Base #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os #baseurl=http://mirror.centos.org/centos/$releasever/os/$basearch/ baseurl=http://yum.egolife.com/yum/centos/6.2_64/base gpgcheck=0 enabled=1 #gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6 #released updates [updates] name=CentOS-$releasever - Updates #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates #baseurl=http://mirror.centos.org/centos/$releasever/updates/$basearch/ baseurl=http://yum.egolife.com/yum/centos/6.2_64/updates gpgcheck=0 enabled=0 #gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6 #additional packages that may be useful [extras] name=CentOS-$releasever - Extras #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras #baseurl=http://mirror.centos.org/centos/$releasever/extras/$basearch/ baseurl=http://yum.egolife.com/yum/centos/6.2_64/extras gpgcheck=0 enabled=1 #gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6 #additional packages that extend functionality of existing packages [centosplus] name=CentOS-$releasever - Plus mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus #baseurl=http://mirror.centos.org/centos/$releasever/centosplus/$basearch/ baseurl=http://yum.egolife.com/yum/centos/6.2_64/centosplus gpgcheck=0 enabled=0 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6 #contrib - packages by Centos Users [contrib] name=CentOS-$releasever - Contrib mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=contrib #baseurl=http://mirror.centos.org/centos/$releasever/contrib/$basearch/ baseurl=http://yum.egolife.com/yum/centos/6.2_64/contrib gpgcheck=0 enabled=0 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
以上配置主要說明如下:
注:
在此次測試中,以硬編碼的形式指定了具體的URL,包括yum服務器,Linux平台和發行版。在yum配置中,releasever,basearch以變量的形式從OS中獲取,來確定不同Linux的平台和發行版本,從很大程度上保證了配置的靈活性。
在配置baseurl=http://mirror.centos.org/centos/$releasever/os/$basearch/中,可以看到有幾個變量,releaseve和basearch,該變量的值,即對應當前的Linux發行版,可以從/etc/yum.conf中找到。
[root@server etc]# head /etc/yum.conf [main] cachedir=/var/cache/yum/$basearch/$releasever keepcache=0 debuglevel=2 logfile=/var/log/yum.log exactarch=1 obsoletes=1 gpgcheck=1 plugins=1 installonly_limit=5 [root@server etc]# ll /var/cache/yum/x86_64/6/ total 12 drwxr-xr-x. 3 root root 4096 Apr 1 17:15 base drwxr-xr-x. 3 root root 4096 Apr 1 17:15 extras -rw-r--r-- 1 root root 0 Apr 1 17:15 timedhosts.txt drwxr-xr-x. 3 root root 4096 Jan 7 00:03 updates
從以上輸出,可以看到本例中,releasever=6,basearch=x86_64。
3.yum測試
[root@server conf]# yum info yum Loaded plugins: downloadonly, fastestmirror, refresh-packagekit, security Determining fastest mirrors base | 1.3 kB 00:00 extras | 1.3 kB 00:00 Installed Packages Name : yum Arch : noarch Version : 3.2.29 Release : 22.el6.centos Size : 4.5 M Repo : installed From repo : anaconda-CentOS-201112091719.x86_64 Summary : RPM package installer/updater/manager URL : http://yum.baseurl.org/ License : GPLv2+ Description : Yum is a utility that can check for and automatically download and : install updated RPM packages. Dependencies are obtained and downloaded : automatically, prompting the user for permission as necessary.
客戶端測試
其他Linux客戶機中,在保證到yum.egolife.com正常的網絡連接的前提下,按照上述配置,即可以正常使用yum服務。
root@oabak ~]# yum install -y lrzsz Loaded plugins: fastestmirror, refresh-packagekit Loading mirror speeds from cached hostfile Setting up Install Process Resolving Dependencies There are unfinished transactions remaining. You might consider running yum-complete-transaction first to finish them. The program yum-complete-transaction is found in the yum-utils package. --> Running transaction check ---> Package lrzsz.x86_64 0:0.12.20-27.1.el6 will be installed --> Finished Dependency Resolution Dependencies Resolved ============================================================================================ Package Arch Version Repository Size ============================================================================================ Installing: lrzsz x86_64 0.12.20-27.1.el6 base 71 k Transaction Summary ============================================================================================ Install 1 Package(s) Total download size: 71 k Installed size: 159 k Downloading Packages: lrzsz-0.12.20-27.1.el6.x86_64.rpm | 71 kB 00:00 Running rpm_check_debug Running Transaction Test Transaction Test Succeeded Running Transaction Installing : lrzsz-0.12.20-27.1.el6.x86_64 1/1 Installed: lrzsz.x86_64 0:0.12.20-27.1.el6 Complete!轉自:http://www.dylanninin.com/blog/2013/04/configure-yum-in-intranet.html