CentOS系統更換yum源
問題
當初瞎鼓搗服務器,更換yum源為aliyun的,奈何阿里的源最近全部打不開,導致yum安裝不了,一直報錯:
http://mirrors.aliyun.com/centos/6/os/x86_64/repodata/repomd.xml: [Errno 14] PYCURL ERROR 22 - “The requested URL returned error: 404 Not Found”
Trying other mirror.
http://mirrors.aliyuncs.com/centos/6/os/x86_64/repodata/repomd.xml: [Errno 14] PYCURL ERROR 7 - “couldn’t connect to host”
Trying other mirror.
http://mirrors.cloud.aliyuncs.com/centos/6/os/x86_64/repodata/repomd.xml: [Errno 14] PYCURL ERROR 6 - “Couldn’t resolve host ‘mirrors.cloud.aliyuncs.com’”
Trying other mirror.
Error: Cannot retrieve repository metadata (repomd.xml) for repository: base. Please verify its path and try again
在網上查了些資料,總算弄懂應該怎么處理了,但是找不到一個對應的源,所以還原默認了;
1. 查詢服務器的系統版本
[root@nys yum.repos.d]# rpm -qi centos-release
Name : centos-release Relocations: (not relocatable)
Version : 6 Vendor: CentOS
Release : 10.el6.centos.12.3 Build Date: Tue 26 Jun 2018 10:52:41 PM CST
Install Date: Mon 23 Jul 2018 11:48:26 AM CST Build Host: x86-01.bsys.centos.org
Group : System Environment/Base Source RPM: centos-release-6-10.el6.centos.12.3.src.rpm
Size : 38232 License: GPLv2
Signature : RSA/SHA1, Tue 26 Jun 2018 11:35:30 PM CST, Key ID 0946fca2c105b9de
Packager : CentOS BuildSystem <http://bugs.centos.org>
Summary : CentOS release file
Description :
CentOS release files
如上:Version,Release兩項,當前服務器操作系統的版本就是:6.10
2. 更換yum源
- 進入yum配置文件目錄
cd /etc/yum.repos.d[root@nys yum.repos.d]# ll
total 60
drwxr-xr-x 2 root root 4096 Oct 17 2017 backup
-rw-r--r-- 1 root root 1901 Jan 5 15:35 CentOS-Base.repo #此文件為yum使用的源配置
-rw-r--r-- 1 root root 1991 Jun 26 2018 CentOS-Base.repo.rpmnew
-rw-r--r-- 1 root root 647 Jun 26 2018 CentOS-Debuginfo.repo
-rw-r--r-- 1 root root 289 Jun 26 2018 CentOS-fasttrack.repo
-rw-r--r-- 1 root root 630 Jun 26 2018 CentOS-Media.repo
-rw-r--r-- 1 root root 8854 Jun 26 2018 CentOS-Vault.repo
-r--r--r-- 1 root root 664 May 11 2018 epel.repo
-rw-r--r-- 1 root root 957 Nov 5 2012 epel.repo.rpmnew
-rw-r--r-- 1 root root 1056 Nov 5 2012 epel-testing.repo
-rw-r--r-- 1 root root 206 Aug 20 17:58 influxdb.repo
- 確保yum源可訪問,此處用的163源
http://mirrors.163.com/centos/6.10/
- 可以查看網易的源說明:
http://mirrors.163.com/.help/
- 下載對應版本的163源:
wget http://mirrors.163.com/.help/CentOS6-Base-163.repo
- 替換源文件到Base:
sudo cp CentOS6-Base-163.repo CentOS-Base.repo
- 更換Base文件中的路徑為指定版本號:
# 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 - 163.com
#此處路徑需要替換為真實可訪問地址
baseurl=http://mirrors.163.com/centos/$releasever/os/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os
gpgcheck=1
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-6#released updates
[updates]
name=CentOS-$releasever - Updates - 163.com
baseurl=http://mirrors.163.com/centos/$releasever/updates/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates
gpgcheck=1
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-6#additional packages that may be useful
--More--(51%)
* 需要將$releasever替換為當前系統版本號:6.10,對應可訪問的163源路徑
http://mirrors.163.com/centos/6.10/
- 使用vim替換:
:%s/$releasever/6.10/g
- 僅展示部分替換后的文件內容:
# 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-6.10 - Base - 163.com
baseurl=http://mirrors.163.com/centos/6.10/os/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=6.10&arch=$basearch&repo=os
gpgcheck=1
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-6#released updates
[updates]
name=CentOS-6.10 - Updates - 163.com
baseurl=http://mirrors.163.com/centos/6.10/updates/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=6.10&arch=$basearch&repo=updates
gpgcheck=1
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-6--More--(51%)
3. 更新yum
#重置緩存
yum makecache
其它可參考執行的命令
#檢查可以更新的軟件包
yum check-update #更新所有的軟件包
yum update #更新特定的軟件包
yum update kernel #大規模的升級
yum upgrade#清楚緩存中rpm包文件
yum clean packages #清楚緩存中rpm的頭文件
yum clean headers #清除緩存中舊的頭文件
yum clean old headers #清除緩存中舊的rpm頭文件和包文件
yum clean all
如果不成功,還原為默認源配置文件
- CentOS-Base.repo 源文件內容,需要將版本6改為7,因為6版本repomd.xml文件已經沒有了,只能從7版本開始
http://mirror.centos.org/centos/7/os/x86_64/repodata/
[root@nys yum.repos.d]# cat 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-7 - Base
mirrorlist=http://mirrorlist.centos.org/?release=7&arch=$basearch&repo=os&infra=$infra
#baseurl=http://mirror.centos.org/centos/7/os/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6#released updates
[updates]
name=CentOS-7 - Updates
mirrorlist=http://mirrorlist.centos.org/?release=7&arch=$basearch&repo=updates&infra=$infra
#baseurl=http://mirror.centos.org/centos/7/updates/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6#additional packages that may be useful
[extras]
name=CentOS-7 - Extras
mirrorlist=http://mirrorlist.centos.org/?release=7&arch=$basearch&repo=extras&infra=$infra
#baseurl=http://mirror.centos.org/centos/7/extras/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-7 - Plus
mirrorlist=http://mirrorlist.centos.org/?release=7&arch=$basearch&repo=centosplus&infra=$infra
#baseurl=http://mirror.centos.org/centos/7/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6#contrib - packages by Centos Users
[contrib]
name=CentOS-7 - Contrib
mirrorlist=http://mirrorlist.centos.org/?release=7&arch=$basearch&repo=contrib&infra=$infra
#baseurl=http://mirror.centos.org/centos/7/contrib/$basearch/
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
- 更新epel.repo文件內容,將6改為7:
[root@nys yum.repos.d]# more epel.repo
[epel]
name=Extra Packages for Enterprise Linux 7 - $basearch
baseurl=http://mirrors.aliyun.com/epel/7/$basearch
failovermethod=priority
enabled=1
gpgcheck=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7[epel-debuginfo]
name=Extra Packages for Enterprise Linux 7 - $basearch - Debug
baseurl=http://mirrors.aliyun.com/epel/7/$basearch/debug
failovermethod=priority
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
gpgcheck=0[epel-source]
name=Extra Packages for Enterprise Linux 7 - $basearch - Source
baseurl=http://mirrors.aliyun.com/epel/7/SRPMS
failovermethod=priority
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
gpgcheck=0
- 清楚緩存并重置
yum clean allyum makecacheyum -y update