https://help.aliyun.com/zh/ecs/user-guide/change-centos-8-repository-addresses?spm=a2c4g.11186623.0.0.a65cad75ZzQ9Zw
centos8(centos8官方源已下线,建议切换centos-vault源
1.运行以下命令备份之前的repo文件
rename '.repo' '.repo.bak' /etc/yum.repos.d/*.repo
2.运行以下命令下载最新的repo文件(这里http://mirrors.cloud.aliyuncs.com域名失效替换为https://mirrors.aliyun.com)
wget https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo -O /etc/yum.repos.d/Centos-vault-8.5.2111.repo
wget https://mirrors.aliyun.com/repo/epel-archive-8.repo -O /etc/yum.repos.d/epel-archive-8.repo
3.运行以下命令替换repo文件中的链接
sed -i 's/http:\/\/mirrors.cloud.aliyuncs.com/url_tmp/g' /etc/yum.repos.d/Centos-vault-8.5.2111.repo
sed -i 's/http:\/\/mirrors.cloud.aliyuncs.com/http:\/\/mirrors.aliyun.com/g' /etc/yum.repos.d/Centos-vault-8.5.2111.repo
sed -i 's/url_tmp/http:\/\/mirrors.aliyun.com/g' /etc/yum.repos.d/Centos-vault-8.5.2111.repo
sed -i 's/http:\/\/mirrors.cloud.aliyuncs.com/http:\/\/mirrors.aliyun.com/g' /etc/yum.repos.d/epel-archive-8.repo
4.运行以下命令重新创建缓存
yum clean all && yum makecache
yum源和epel源切换完成后,即可使用yum install命令在实例上安装您所需要的软件包
或者
1.cd /etc/yum.repos.d/
2.sed -i 's/mirrorlist/#mirrorlist/g' /etc/yum.repos.d/CentOS-*
sed -i 's|#baseurl=http://mirror.centos.org|baseurl=http://vault.centos.org|g' /etc/yum.repos.d/CentOS-*
3.yum clean all && yum makecache