標籤:centos 配置 yum源
一、下載國內比較穩定的yum源,我這裡下載163的源
同時我使用的是CentOS6.2的x86_64版本,所以下載的是CentOS6-Base-163.repo
請根據,如下方法確認自己系統的版本
[[email protected] ~]# lsb_release -a
LSB Version: :core-4.0-amd64:core-4.0-noarch:graphics-4.0-amd64:graphics-4.0-noarch:printing-4.0-amd64:printing-4.0-noarch
Distributor ID: CentOS
Description: CentOS release 6.2 (Final)
Release: 6.2
Codename: Final
[[email protected] ~]# cat /etc/is
iscsi/ issue issue.net
[[email protected] ~]# cat /etc/issue
CentOS release 6.2 (Final)
Kernel \r on an \m
[[email protected] ~]# rpm -q centos-release
centos-release-6-2.el6.centos.7.x86_64
下載CentOS6-Base-163.repo到/etc/yum.repos.d/目錄這個是yum源配置目錄
[[email protected] yum.repos.d]# wget http://mirrors.163.com/.help/CentOS6-Base-163.repo
--2014-06-28 18:46:41-- http://mirrors.163.com/.help/CentOS6-Base-163.repo
正在解析主機 mirrors.163.com... 123.58.173.106
正在串連 mirrors.163.com|123.58.173.106|:80... 已串連。
已發出 HTTP 要求,正在等待回應... 200 OK
長度:2006 (2.0K) [application/octet-stream]
正在儲存至: “CentOS6-Base-163.repo”
100%[======================================>] 2,006 --.-K/s in 0s
2014-06-28 18:46:41 (37.1 MB/s) - 已儲存 “CentOS6-Base-163.repo” [2006/2006])
二、備份原有的yum源設定檔,安裝163源
[[email protected] yum.repos.d]# mv CentOS-Base.repo CentOS-Base.repo。bak
將下載的CentOS6-Base-163.repo更名為CentOS-Base.repo
[[email protected] yum.repos.d]# ls
CentOS6-Base-163.repo CentOS-Base.repo.bak CentOS-Media.repo
CentOS-Base.repo CentOS-Debuginfo.repo
[[email protected] yum.repos.d]# mv CentOS6-Base-163.repo CentOS-Base.repo
mv:是否覆蓋"CentOS-Base.repo"? yes
清楚yum緩衝
[[email protected] yum.repos.d]# yum clean all
Loaded plugins: fastestmirror, refresh-packagekit, security
Cleaning repos: base extras updates
Cleaning up Everything
Cleaning up list of fastest mirrors
更新yum源
[[email protected] yum.repos.d]# yum makecache
Loaded plugins: fastestmirror, refresh-packagekit, security
Determining fastest mirrors
base | 3.7 kB 00:00
base/group_gz | 220 kB 00:00
base/filelists_db | 5.9 MB 00:00
base/primary_db | 4.4 MB 00:00
base/other_db | 2.8 MB 00:00
extras | 3.4 kB 00:00
extras/filelists_db | 11 kB 00:00
extras/prestodelta | 907 B 00:00
extras/primary_db | 19 kB 00:00
extras/other_db | 5.8 kB 00:00
updates | 3.4 kB 00:00
updates/filelists_db | 2.2 MB 00:00
updates/prestodelta | 342 kB 00:00
updates/primary_db | 3.7 MB 00:00
updates/other_db | 31 MB 00:04
Metadata Cache Created
[[email protected] yum.repos.d]#
至此yum源修改完成
三、其他知識擴充知識
關於yum目錄說明及配置本地yum源,參考下面的文章
http://www.cnblogs.com/mchina/archive/2013/01/04/2842275.html
1、yum的簡介
yum,是Yellow dog Updater, Modified 的簡稱,是杜克大學為了提高RPM 軟體包安裝性而開發的一種軟體包管理器。起初是由yellow dog 這一發行版的開發人員Terra Soft 研發,用python 寫成,那時還叫做yup(yellow dog updater),後經杜克大學的[email protected] Team Dev進行改進,遂有此名。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 資料庫的一致性。
2、配置網路源
yum 的設定檔分為兩部分:main 和repository
yum.conf 檔案一般位於/etc目錄下,一般其中只包含main部分的配置選項。
# cat /etc/yum.conf
650) this.width=650;" src="/e/u261/themes/default/images/spacer.gif" alt="複製代碼" style="background:url("/e/u261/lang/zh-cn/images/localimage.png") no-repeat center;border:1px solid #ddd;" />
[main]cachedir=/var/cache/yum //yum 緩衝的目錄,yum 在此儲存下載的rpm 包和資料庫,預設設定為/var/cache/yumkeepcache=0 //安裝完成後是否保留軟體包,0為不保留(預設為0),1為保留debuglevel=2 //Debug 資訊輸出等級,範圍為0-10,預設為2logfile=/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
650) this.width=650;" src="/e/u261/themes/default/images/spacer.gif" alt="複製代碼" style="background:url("/e/u261/lang/zh-cn/images/localimage.png") no-repeat center;border:1px solid #ddd;" />
除了上述之外,還有一些可以添加的選項,如:
exclude=selinux* // 排除某些軟體在升級名單之外,可以用萬用字元,列表中各個項目要用空格隔開,這個對於安裝了諸如美化包,中文補丁的朋友特別有用。
gpgcheck=1 // 有1和0兩個選擇,分別代表是否是否進行gpg(GNU Private Guard) 校正,以確定rpm 包的來源是有效和安全的。這個選項如果設定在[main]部分,則對每個repository 都有效。預設值為0。
3、配置本地源
掛載系統安裝光碟片
# mount /dev/cdrom /mnt/cdrom/
配置本地yum源
# cd /etc/yum.repos.d/
# ls
會看到四個repo 檔案
650) this.width=650;" src="/e/u261/themes/default/images/spacer.gif" style="background:url("/e/u261/lang/zh-cn/images/localimage.png") no-repeat center;border:1px solid #ddd;" alt="spacer.gif" />
CentOS-Base.repo 是yum 網路源的設定檔
CentOS-Media.repo 是yum 本地源的設定檔
修改CentOS-Media.repo
# cat CentOS-Media.repo
650) this.width=650;" src="/e/u261/themes/default/images/spacer.gif" alt="複製代碼" style="background:url("/e/u261/lang/zh-cn/images/localimage.png") no-repeat center;border:1px solid #ddd;" />
# 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 - Mediabaseurl=file:///media/CentOS/ file:///mnt/cdrom/ file:///media/cdrecorder/gpgcheck=1enabled=1gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-5
650) this.width=650;" src="/e/u261/themes/default/images/spacer.gif" alt="複製代碼" style="background:url("/e/u261/lang/zh-cn/images/localimage.png") no-repeat center;border:1px solid #ddd;" />
在baseurl 中修改第2個路徑為/mnt/cdrom(即為光碟片掛載點)
將enabled=0改為1
禁用預設的yum 網路源
將yum 網路源設定檔改名為CentOS-Base.repo.bak,否則會先在網路源中尋找適合的包,改名之後直接從本地源讀取
本文出自 “飛翔的豬” 部落格,請務必保留此出處http://thinkpig007.blog.51cto.com/971471/1431959