截止目前CentOS-7.x官方已经停止维护,yum命令默认已经无法使用。
CentOS官方提供了一个旧版软件存档http://vault.centos.org/,我们可以使用这个连接替换yum源
1、查询当前系统版本
cat /etc/redhat-release
当前系统版本是CentOS Linux release 7.9.2009 (Core)
yum install wget #测试安装软件,默认无法使用yum命令
2、创建yum源文件
#备份默认的源文件
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo-backup
vi /etc/yum.repos.d/CentOS-Base.repo #编辑源文件
[base]
name=CentOS-7.9.2009
enabled=1
failovermethod=priority
baseurl=https://vault.centos.org/7.9.2009/os/$basearch/
gpgcheck=1
gpgkey=https://vault.centos.org/RPM-GPG-KEY-CentOS-7
[updates]
name=CentOS-7.9.2009
enabled=1
failovermethod=priority
baseurl=https://vault.centos.org/7.9.2009/updates/$basearch/
gpgcheck=1
gpgkey=https://vault.centos.org/RPM-GPG-KEY-CentOS-7
[extras]
name=CentOS-7.9.2009
enabled=1
failovermethod=priority
baseurl=https://vault.centos.org/7.9.2009/extras/$basearch/
gpgcheck=1
gpgkey=https://vault.centos.org/RPM-GPG-KEY-CentOS-7
:wq! #保存退出
yum clean all
yum makecache #生成缓存
yum install wget #再次测试安装软件
成功使用yum安装了wget
3、配置其他yum源
3.1、配置阿里云的yum源
下载阿里云的 yum 源配置文件,使用 wget 命令从阿里云下载新的 yum 源配置文件。
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo-vault-backup
wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
yum clean all
yum makecache #生成缓存
yum install wget #再次测试安装软件
3.2、配置163yum源
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo-aliyun-backup
vi /etc/yum.repos.d/CentOS-Base.repo #编辑源文件
[base]
name=CentOS-$releasever - Base - 163.com
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os
baseurl=http://mirrors.163.com/centos-vault/7.9.2009/os/$basearch/
gpgcheck=1
gpgkey=http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-7
#released updates
[updates]
name=CentOS-$releasever - Updates - 163.com
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates
baseurl=http://mirrors.163.com/centos-vault/7.9.2009/updates/$basearch/
gpgcheck=1
gpgkey=http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-7
#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras - 163.com
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras
baseurl=http://mirrors.163.com/centos-vault/7.9.2009/extras/$basearch/
gpgcheck=1
gpgkey=http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-7
#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever - Plus - 163.com
baseurl=http://mirrors.163.com/centos-vault/7.9.2009/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-7
:wq! #保存退出
yum clean all
yum makecache #生成缓存
yum install wget #再次测试安装软件
3.3、配置中科大yum源
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo-163-backup
vi /etc/yum.repos.d/CentOS-Base.repo #编辑源文件
[base]
name=CentOS- - Base
baseurl=https://mirrors.ustc.edu.cn/centos-vault/centos/7.9.2009/os/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
[updates]
name=CentOS- - Updates
baseurl=https://mirrors.ustc.edu.cn/centos-vault/centos/7.9.2009/updates/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
[extras]
name=CentOS- - Extras
baseurl=https://mirrors.ustc.edu.cn/centos-vault/centos/7.9.2009/extras/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
[centosplus]
name=CentOS- - Plus
baseurl=https://mirrors.ustc.edu.cn/centos-vault/centos/7.9.2009/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
:wq! #保存退出
yum clean all
yum makecache #生成缓存
yum install wget #再次测试安装软件
至此,CentOS-7.x官方停止维护后yum源失效解决办法完成。