yum
轉自:
http://www.cnblogs.com/mchina/archive/2013/01/04/2842275.html
CentOS yum 源的配置與使用
一、yum 簡介
yum,是Yellow dog Updater, Modified 的簡稱,是杜克大學為了提高RPM 軟件包安裝性而開發的一種軟件包管理器。起初是由yellow dog 這一發行版的開發者Terra Soft 研發,用python 寫成,那時還叫做yup(yellow dog updater),后經杜克大學的Linux@Duke 開發團隊進行改進,遂有此名。yum 的宗旨是自動化地升級,安裝/移除rpm 包,收集rpm 包的相關信息,檢查依賴性并自動提示用戶解決。yum 的關鍵之處是要有可靠的repository,顧名思義,這是軟件的倉庫,它可以是http 或ftp 站點,也可以是本地軟件池,但必須包含rpm 的header,header 包括了rpm 包的各種信息,包括描述,功能,提供的文件,依賴性等。正是收集了這些header 并加以分析,才能自動化地完成余下的任務。
yum 的理念是使用一個中心倉庫(repository)管理一部分甚至一個distribution 的應用程序相互關系,根據計算出來的軟件依賴關系進行相關的升級、安裝、刪除等等操作,減少了Linux 用戶一直頭痛的dependencies 的問題。這一點上,yum 和apt 相同。apt 原為debian 的deb 類型軟件管理所使用,但是現在也能用到RedHat 門下的rpm 了。
yum 主要功能是更方便的添加/刪除/更新RPM 包,自動解決包的倚賴性問題,便于管理大量系統的更新問題。
yum 可以同時配置多個資源庫(Repository),簡潔的配置文件(/etc/yum.conf),自動解決增加或刪除rpm 包時遇到的依賴性問題,保持與RPM 數據庫的一致性。
二、yum 安裝
CentOS 默認已經安裝了yum,不需要另外安裝,這里為了實驗目的,先將yum 卸載再重新安裝。
1、查看系統默認安裝的yum
# rpm -qa|grep yum
2、卸載yum
# rpm -e yum-fastestmirror-1.1.16-14.el5.centos.1 yum-metadata-parser-1.1.2-3.el5.centos yum-3.2.22-33.el5.centos
3、重新安裝yum
這里可以通過wget 從網上下載相關包安裝,也可以掛載系統安裝光盤進行安裝,這里選擇掛載系統安裝光盤進行安裝。
# mount /dev/cdrom /mnt/cdrom/
# rpm -ivh yum-3.2.22-33.el5.centos.noarch.rpm yum-fastestmirror-1.1.16-14.el5.centos.1.noarch.rpm yum-metadata-parser-1.1.2-3.el5.centos.i386.rpm
# yum -v
yum 的基礎安裝包包括:
- yum //RPM installer/updater
- yum-fastestmirror //Yum plugin which chooses fastest repository from a mirrorlist
- yum-metadata-parser //A fast metadata parser for yum
其他安裝包根據自己需要安裝。
三、yum 配置
yum 的配置文件分為兩部分:main 和repository
- main 部分定義了全局配置選項,整個yum 配置文件應該只有一個main。常位于/etc/yum.conf 中。
- repository 部分定義了每個源/服務器的具體配置,可以有一到多個。常位于/etc/yum.repo.d 目錄下的各文件中。
yum.conf 文件一般位于/etc目錄下,一般其中只包含main部分的配置選項。
# cat /etc/yum.conf
[main] cachedir=/var/cache/yum//yum 緩存的目錄,yum 在此存儲下載的rpm 包和數據庫,默認設置為/var/cache/yum keepcache=0//安裝完成后是否保留軟件包,0為不保留(默認為0),1為保留 debuglevel=2//Debug 信息輸出等級,范圍為0-10,缺省為2 logfile=/var/log/yum.log//yum 日志文件位置。用戶可以到/var/log/yum.log 文件去查詢過去所做的更新。 pkgpolicy=newest//包的策略。一共有兩個選項,newest 和last,這個作用是如果你設置了多個repository,而同一軟件在不同的repository 中同時存在,yum 應該安裝哪一個,如果是newest,則yum 會安裝最新的那個版本。如果是last,則yum 會將服務器id 以字母表排序,并選擇最后的那個服務器上的軟件安裝。一般都是選newest。 distroverpkg=redhat-release//指定一個軟件包,yum 會根據這個包判斷你的發行版本,默認是redhat-release,也可以是安裝的任何針對自己發行版的rpm 包。 tolerant=1//有1和0兩個選項,表示yum 是否容忍命令行發生與軟件包有關的錯誤,比如你要安裝1,2,3三個包,而其中3此前已經安裝了,如果你設為1,則yum 不會出現錯誤信息。默認是0。 exactarch=1//有1和0兩個選項,設置為1,則yum 只會安裝和系統架構匹配的軟件包,例如,yum 不會將i686的軟件包安裝在適合i386的系統中。默認為1。 retries=6//網絡連接發生錯誤后的重試次數,如果設為0,則會無限重試。默認值為6. obsoletes=1//這是一個update 的參數,具體請參閱yum(8),簡單的說就是相當于upgrade,允許更新陳舊的RPM包。 plugins=1//是否啟用插件,默認1為允許,0表示不允許。我們一般會用yum-fastestmirror這個插件。 bugtracker_url=http://bugs.centos.org/set_project.php?project_id=16&ref=http://bugs.centos.org/bug_report_page.php?category=yum# Note: yum-RHN-plugin doesn't honor this. metadata_expire=1hinstallonly_limit = 5# PUT YOUR REPOS HERE OR IN separate files named file.repo # in /etc/yum.repos.d除了上述之外,還有一些可以添加的選項,如:
exclude=selinux* //?排除某些軟件在升級名單之外,可以用通配符,列表中各個項目要用空格隔開,這個對于安裝了諸如美化包,中文補丁的朋友特別有用。
gpgcheck=1 //?有1和0兩個選擇,分別代表是否是否進行gpg(GNU Private Guard) 校驗,以確定rpm 包的來源是有效和安全的。這個選項如果設置在[main]部分,則對每個repository 都有效。默認值為0。
四、配置本地yum源
1、掛載系統安裝光盤
# mount /dev/cdrom /mnt/cdrom/
2、配置本地yum源
# cd /etc/yum.repos.d/
# ls
會看到四個repo 文件
CentOS-Base.repo?是yum 網絡源的配置文件
CentOS-Media.repo 是yum?本地源的配置文件
修改CentOS-Media.repo
# cat CentOS-Media.repo
# CentOS-Media.repo # # This repo is used to mount the default locations for a CDROM / DVD on # CentOS-5. You can use this repo and yum to install items directly off the # DVD ISO that we release. # # To use this repo, put in your DVD and use it with the other repos too: # yum --enablerepo=c5-media [command] # # or for ONLY the media repo, do this: # # yum --disablerepo=\* --enablerepo=c5-media [command][c5-media] name=CentOS-$releasever - Media baseurl=file:///media/CentOS/file:///mnt/cdrom/file:///media/cdrecorder/ gpgcheck=1 enabled=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-5在baseurl 中修改第2個路徑為/mnt/cdrom(即為光盤掛載點)
將enabled=0改為1
3、禁用默認的yum 網絡源
將yum 網絡源配置文件改名為CentOS-Base.repo.bak,否則會先在網絡源中尋找適合的包,改名之后直接從本地源讀取。
4、執行yum 命令
# yum install postgresql
關于repo 文件的格式
所有repository?服務器設置都應該遵循如下格式:
[serverid] name=Some name for this server baseurl=url://path/to/repository/- serverid 是用于區別各個不同的repository,必須有一個獨一無二的名稱;
- name 是對repository 的描述,支持像$releasever $basearch這樣的變量;
- baseurl 是服務器設置中最重要的部分,只有設置正確,才能從上面獲取軟件。它的格式是:
其中url 支持的協議有 http:// ftp://?file://?三種。baseurl 后可以跟多個url,你可以自己改為速度比較快的鏡像站,但baseurl 只能有一個,也就是說不能像如下格式:
baseurl=url://server1/path/to/repository/ baseurl=url://server2/path/to/repository/ baseurl=url://server3/path/to/repository/其中url 指向的目錄必須是這個repository header 目錄的上一級,它也支持$releasever $basearch 這樣的變量。
url 之后可以加上多個選項,如gpgcheck、exclude、failovermethod 等,比如:
其中gpgcheck,exclude 的含義和[main] 部分相同,但只對此服務器起作用,failovermethode 有兩個選項roundrobin 和priority,意思分別是有多個url可供選擇時,yum 選擇的次序,roundrobin 是隨機選擇,如果連接失敗則使用下一個,依次循環,priority 則根據url 的次序從第一個開始。如果不指明,默認是roundrobin。
五、配置國內yum源
系統默認的yum 源速度往往不盡人意,為了達到快速安裝的目的,在這里修改yum源為國內源。
上海交通大學yum源
a. 修改/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://ftp.sjtu.edu.cn/centos/$releasever/os/$basearch/ gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-5#released updates [updates] name=CentOS-$releasever - Updates #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates baseurl=http://ftp.sjtu.edu.cn/centos/$releasever/updates/$basearch/ gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-5#additional packages that may be useful [extras] name=CentOS-$releasever - Extras #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras baseurl=http://ftp.sjtu.edu.cn/centos/$releasever/extras/$basearch/ gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-5#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://ftp.sjtu.edu.cn/centos/$releasever/centosplus/$basearch/ gpgcheck=1 enabled=0 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-5#contrib - packages by Centos Users [contrib] name=CentOS-$releasever - Contrib #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=contrib baseurl=http://ftp.sjtu.edu.cn/centos/$releasever/contrib/$basearch/ gpgcheck=1 enabled=0 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-5關于變量
- $releasever:代表發行版的版本,從[main]部分的distroverpkg獲取,如果沒有,則根據redhat-release包進行判斷。
- $arch:cpu體系,如i686,athlon等
- $basearch:cpu的基本體系組,如i686和athlon同屬i386,alpha和alphaev6同屬alpha。
b.?導入GPG KEY
yum 可以使用gpg 對包進行校驗,確保下載包的完整性,所以我們先要到各個repository 站點找到gpg key,一般都會放在首頁的醒目位置,一些名字諸如RPM-GPG-KEY-CentOS-5 之類的純文本文件,把它們下載下來,然后用rpm --import RPM-GPG-KEY-CentOS-5?命令將key 導入。
c.?執行yum 命令
其他國內yum源列表如下:
1. 企業貢獻:
搜狐開源鏡像站:http://mirrors.sohu.com/
網易開源鏡像站:http://mirrors.163.com/
2. 大學教學:
北京理工大學:
http://mirror.bit.edu.cn?(IPv4 only)
http://mirror.bit6.edu.cn?(IPv6 only)
北京交通大學:
http://mirror.bjtu.edu.cn?(IPv4 only)
http://mirror6.bjtu.edu.cn?(IPv6 only)
http://debian.bjtu.edu.cn?(IPv4+IPv6)
蘭州大學:http://mirror.lzu.edu.cn/
廈門大學:http://mirrors.xmu.edu.cn/
清華大學:
http://mirrors.tuna.tsinghua.edu.cn/?(IPv4+IPv6)
http://mirrors.6.tuna.tsinghua.edu.cn/?(IPv6 only)
http://mirrors.4.tuna.tsinghua.edu.cn/?(IPv4 only)
天津大學:http://mirror.tju.edu.cn/
中國科學技術大學:
http://mirrors.ustc.edu.cn/?(IPv4+IPv6)
http://mirrors4.ustc.edu.cn/
http://mirrors6.ustc.edu.cn/
東北大學:
http://mirror.neu.edu.cn/?(IPv4 only)
http://mirror.neu6.edu.cn/?(IPv6 only)
電子科技大學:http://ubuntu.uestc.edu.cn/
六、使用第三方軟件庫
Centos/RHEL默認的yum軟件倉庫非常有限,僅僅限于發行版本那幾張盤里面的常規包和一些軟件包的更新,利用RpmForge,可以增加非常多的第三方rpm軟件包。RpmForge庫現在已經擁有超過10000種的CentOS的軟件包,被CentOS社區認為是最安全也是最穩定的一個第三方軟件庫。
1、安裝yum-priorities插件
這個插件是用來設置yum在調用軟件源時的順序的。因為官方提供的軟件源,都是比較穩定和被推薦使用的。因此,官方源的順序要高于第三方源的順序。如何保證這個順序,就需要安裝yum-priorities這插件了。
# yum -y install yum-priorities
2、安裝完yum-priorities插件后需要設置/etc/yum.repos.d/ 目錄下的.repo相關文件(如CentOS-Base.repo),在這些文件中插入順序指令:priority=N (N為1到99的正整數,數值越小越優先)
一般配置[base],?[addons],?[updates],?[extras] 的priority=1,[CentOSplus],?[contrib] 的priority=2,其他第三的軟件源為:priority=N (推薦N>10)
以CentOS-Base.repo 為例:
[base] name=CentOS-$releasever - Base #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os baseurl=http://ftp.sjtu.edu.cn/centos/$releasever/os/$basearch/ gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-5 priority=13、下載與安裝相應rpmforge的rpm文件包
# wget http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.2-2.el5.rf.i386.rpm
4、安裝DAG的PGP Key
# rpm --import http://apt.sw.be/RPM-GPG-KEY.dag.txt
5、驗證rpmforge的rpm文件包
# rpm -K rpmforge-release-0.5.2-2.el5.rf.*.rpm
6、安裝rpmforge的rpm文件包
# rpm -i rpmforge-release-0.5.2-2.el5.rf.i386.rpm
7、設置/etc/yum.repos.d/rpmforge.repo文件中源的級別
[root@TS-DEV yum.repos.d]# cat rpmforge.repo?
### Name: RPMforge RPM Repository for RHEL 5 - dag ### URL: http://rpmforge.net/ [rpmforge] name = RHEL $releasever - RPMforge.net - dag baseurl = http://apt.sw.be/redhat/el5/en/$basearch/rpmforge mirrorlist = http://apt.sw.be/redhat/el5/en/mirrors-rpmforge #mirrorlist = file:///etc/yum.repos.d/mirrors-rpmforge enabled = 1 protect = 0 gpgkey = file:///etc/pki/rpm-gpg/RPM-GPG-KEY-rpmforge-dag gpgcheck = 1 priority=128、測試安裝
# yum install htop
參考?http://wiki.centos.org/AdditionalResources/Repositories/RPMForge#head-5aabf02717d5b6b12d47edbc5811404998926a1b
其他第三方軟件庫如?EPEL(Extra Packages for?Enterprise?Linux?) 和?RPMFusion 的安裝與使用和RPMForge類似,可自行查找資料安裝。
?
David Camp
- 技術交流,請加QQ群:
系統運維技術分享:296513821
- 業務合作,請聯系作者QQ:562866602
- 我的微信號:mchina_tang
- 給我寫信:mchina_tang@qq.com
- 我的地址:江蘇·蘇州
我們永遠相信,分享是一種美德 |?We Believe, Great People Share Knowledge...
分類: Linux 標簽: CentOS, yum 綠色通道:好文要頂關注我收藏該文與我聯系 David_Tang關注 - 2
粉絲 - 487 +加關注 5 0 (請您對文章做出評價) ? 上一篇:Linux NFS服務器的安裝與配置
? 下一篇:linux screen 命令詳解
posted @ 2013-01-04 14:01 David_Tang 閱讀(26571) 評論(6) 編輯 收藏 評論列表 #1樓 2013-01-04 18:08 高天樂 坑爹,卸了yum裝不回來了 支持(0)反對(0) #2樓[樓主] 2013-01-04 21:04 David_Tang @高天樂
請問有什么報錯嗎?yum-3.2.22-33.el5.centos.noarch.rpm yum-fastestmirror-1.1.16-14.el5.centos.1.noarch.rpm 兩個一起裝的嗎?互相有依賴關系。 支持(0)反對(0) #3樓 2013-01-04 22:29 dudu 謝謝分享! 支持(0)反對(0) #4樓 2013-10-07 22:42 也許明天 很好 受用了 支持(0)反對(0) #5樓 2014-01-17 00:19 京月飛鴻 很好,原理和步驟都很清晰 支持(0)反對(0) #6樓 2014-02-25 14:36 藝搜天下 up 支持(0)反對(0) 刷新評論刷新頁面返回頂部 注冊用戶登錄后才能發表評論,請 登錄 或 注冊,訪問網站首頁。 博客園首頁博問新聞閃存程序員招聘知識庫 最新IT新聞:
· 快的推孕婦免費乘車 打車軟件競爭轉向拼服務
· 營銷QQ與微信正式打通 意在增強變現能力
· 京東大調整:人事、架構對標阿里“講故事”
· 史玉柱微博稱10億投資國字頭民營公司 總理簽字創立
· 谷歌CEO拉里·佩奇3天拋售6747萬美元股票
? 更多新聞... 最新知識庫文章:
· MVC vs. MVP vs. MVVM
· PHP 語言需要避免的 10 大誤區
· 不是技術牛人,如何拿到國內IT巨頭的Offer
· 深入淺出交換類排序算法
· 從Code Review談如何做技術
? 更多知識庫文章...
公告
昵稱:David_Tang園齡:2年3個月
粉絲:487
關注:2 +加關注
| |||||||||
| 30 | 31 | 1 | 2 | 3 | 4 | 5 | |||
| 6 | 7 | 8 | 9 | 10 | 11 | 12 | |||
| 13 | 14 | 15 | 16 | 17 | 18 | 19 | |||
| 20 | 21 | 22 | 23 | 24 | 25 | 26 | |||
| 27 | 28 | 29 | 30 | 31 | 1 | 2 | |||
| 3 | 4 | 5 | 6 | 7 | 8 | 9 | |||
搜索
? ?我的標簽
- postgresql(28)
- linux(17)
- Packet Tracer(15)
- Oracle筆記(14)
- zhuojinsz(11)
- 微信(11)
- 微信公眾(11)
- 微信公眾平臺開發(9)
- 微信開發(7)
- 卓錦蘇州(6)
- 更多
隨筆分類(129)
- HTML
- JavaScript
- Linux(14)
- Linux Server(12)
- Linux Shell(12)
- Mysql(2)
- Network(16)
- Oracle(19)
- PHP(11)
- Postgresql(32)
- 微信開發(11)
隨筆檔案(114)
- 2014年3月 (1)
- 2014年2月 (1)
- 2013年10月 (2)
- 2013年8月 (2)
- 2013年7月 (3)
- 2013年6月 (3)
- 2013年4月 (8)
- 2013年3月 (5)
- 2013年2月 (1)
- 2013年1月 (4)
- 2012年12月 (2)
- 2012年11月 (3)
- 2012年9月 (16)
- 2012年8月 (23)
- 2012年7月 (24)
- 2012年6月 (9)
- 2012年5月 (6)
- 2012年4月 (1)
鏈接
- 蘇's 百度
- 蘇's 網易
- 蘇's 新浪
積分與排名
- 積分 - 182113
- 排名 - 599
最新評論
- 1. Re:微信公眾平臺開發(十) 消息回復總結
- @燃燒的饅頭@燃燒的饅頭@lz19881123 $header = sprintf($newsTplHead, $object->FromUserName, $object->ToUserName, time());//圖文頭$body = sprintf($newsTplBody, $object->FromUserName, $object->ToUserName, $title, $desc...
- --xiaomi123
- 2. Re:微信公眾平臺開發(十) 消息回復總結
- @candoudou1header("Content-type: text/html; charset=utf-8");function _response_Multinews($object,$newsContent){ $bodyCount = count($newsContent); $bodyCount = $bodyCount ...
- --xiaomi123
- 3. Re:微信公眾平臺開發(四) 簡單回復功能開發
- responseText()函數中有點錯吧,
$resultStr = sprintf($textTpl, $object->FromUserName, $object->ToUserName, time(), $content, $flag);
FromUserName和ToUserName反了。是吧? - --楚狂人
- 4. Re:微信公眾平臺開發(四) 簡單回復功能開發
- @姑蘇小邪
你這是發送給用戶?圖文信息? - --楚狂人
- 5. Re:Packet Tracer 5.0實驗(四) 利用三層交換機實現VLAN間路由
- @這個不錯
需開啟三層路由,命令為:
ip routing - --黑張
閱讀排行榜
- 1. Linux下Nagios的安裝與配置(43140)
- 2. Linux NFS服務器的安裝與配置(35335)
- 3. CentOS 6.3下Samba服務器的安裝與配置(30581)
- 4. 微信公眾平臺開發(一) 配置接口(28778)
- 5. CentOS yum 源的配置與使用(26566)
評論排行榜
- 1. Linux下Nagios的安裝與配置(51)
- 2. 微信公眾平臺開發(一) 配置接口(37)
- 3. 微信公眾平臺開發(十) 消息回復總結(25)
- 4. CentOS 6.3下Samba服務器的安裝與配置(21)
- 5. 微信公眾平臺開發(四) 簡單回復功能開發(19)
推薦排行榜
- 1. 微信公眾平臺開發(一) 配置接口(26)
- 2. Linux下Nagios的安裝與配置(14)
- 3. CentOS 6.3下Samba服務器的安裝與配置(14)
- 4. Oracle筆記(六) 多表查詢(14)
- 5. 微信公眾平臺開發(九) 數據庫操作(11)
總結
- 上一篇: VMware下如何虚拟软盘启动
- 下一篇: 松下plcgr7安装序列号_向上一阶段跃