1. 程式人生 > >centos安裝網路repo源及錯誤說明

centos安裝網路repo源及錯誤說明

其實安裝網路源很簡單,但是今天遇到了個奇特的問題,折騰了幾個小時。

先說下安裝網路源的步驟:

修改CentOS預設yum源為mirrors.163.com

1、首先備份系統自帶yum源配置檔案/etc/yum.repos.d/CentOS-Base.repo

1 [[email protected] ~]# mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup


2、進入yum源配置檔案所在的資料夾

1 [[email protected] ~]# cd /etc/yum.repos.d/


3、下載163的yum源配置檔案到上面那個資料夾內

CentOS7

1 [[email protected] yum.repos.d]# wget http://mirrors.163.com/.help/CentOS7-Base-163.repo

 
CentOS6

1 [[email protected] yum.repos.d]# wget http://mirrors.163.com/.help/CentOS6-Base-163.repo

 
CentOS5

1 [[email protected] yum.repos.d]
# wget http://mirrors.163.com/.help/CentOS5-Base-163.repo


4、執行yum makecache生成快取

1 [[email protected] yum.repos.d]# yum makecache


5、這時候再更新系統就會看到以下mirrors.163.com資訊

1 2 3 4 5 6 [[email protected] yum.repos.d]# yum -y update 已載入外掛:fastestmirror, refresh-packagekit, security
設定更新程序Loading mirror speeds from cached hostfile * base: mirrors.163.com * extras: mirrors.163.com * updates: mirrors.163.com

修改CentOS預設yum源為mirrors.aliyun.com
1、首先備份系統自帶yum源配置檔案/etc/yum.repos.d/CentOS-Base.repo

1 [[email protected] ~]# mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup


2、下載ailiyun的yum源配置檔案到/etc/yum.repos.d/
CentOS7

1 [[email protected] ~]# wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo


CentOS6

1 [[email protected] ~]# wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo


CentOS5

1 [[email protected] ~]# wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-5.repo

 
3、執行yum makecache生成快取

1 [[email protected] ~]# yum makecache


4、這時候再更新系統就會看到以下mirrors.aliyun.com資訊

1 2 3 4 5 6 [[email protected] ~]# yum -y update 已載入外掛:fastestmirror, refresh-packagekit, security 設定更新程序Loading mirror speeds from cached hostfile * base: mirrors.aliyun.com * extras: mirrors.aliyun.com * updates: mirrors.aliyun.com
是不是很Easy!

-----------------------------------------------------------------------------------------------------------

其實我也是按照這個步驟操作的,但是報了錯:

[[email protected] yum.repos.d]# yum makecache
Loaded plugins: fastestmirror, security
Error: File contains no section headers.
file: file:///etc/yum.repos.d/6CentOS-Base.repo, line: 1
'<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">\r\n'

這是啥情況,問題在於你下載的不對,這裡建議使用瀏覽器下載,然後上傳至伺服器

[[email protected] yum.repos.d]# file CentOS6-Base-163.repo 
CentOS6-Base-163.repo: ASCII English text

當你使用wget下載的時候,請確認下file出來是否為ASCII English text,必須是這個格式。

當然了,你可用另外一種方式裝

 rpm -ivh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm  你會發現又報錯了,百思不得其解~~ [[email protected] yum.repos.d]# rpm -ivh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
Retrieving http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
error: /var/tmp/rpm-tmp.COfzVl: not an rpm package (or package manifest): 

還是相同的解決辦法,在瀏覽器輸入http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm,然後上傳至伺服器。

[[email protected] yum.repos.d]# yum install fail2ban
Loaded plugins: fastestmirror
Setting up Install Process
Determining fastest mirrors
epel                                                                                   | 4.2 kB     00:00     
http://download.fedoraproject.org/pub/epel/6/x86_64/repodata/repomd.xml: [Errno -1] Error importing repomd.xml for epel: Damaged repomd.xml file
Trying other mirror.
Error: Cannot retrieve repository metadata (repomd.xml) for repository: epel. Please verify its path and try again

上述報錯的一切一切的原因,今天終於找到了,在網路的出口有限制,導致異常,出問題時可以使用手機4G做熱點試一試。