前期准备
本文基于centos7来配置
配置网络yum源首先要保证网络的畅通,可以ping www.baidu.com来测试网络是否畅通,如果无法ping通则需要检查ip dns hosts等文件是否配置正确
国内源配置
从阿里源下载repo配置文件
curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo

生产缓存
yum makecache

测试
yum install -y vim

官网源配置
重新安装官方源 如果你没有动过官方源,仅想修改地址的话请直接跳到步骤2。
重新安装官方源 如果你没有动过官方源,仅想修改地址的话请直接跳到步骤2。
cd /etc/yum.repos.d/
rm -rf CentOS-*
rpm -Uvh --force https://vault.centos.org/7.9.2009/os/x86_64/Packages/centos-release-7-9.2009.0.el7.centos.x86_64.rpm

替换软件源的URL
sed -e "s|^mirrorlist=|#mirrorlist=|g" \
-e "s|^#baseurl=https://mirror.centos.org/centos/\$releasever|baseurl=https://vault.centos.org/7.9.2009/|g" \
-e "s|^#baseurl=https://mirror.centos.org/\$contentdir/\$releasever|baseurl=https://vault.centos.org/7.9.2009/|g" \
-i.bak \
/etc/yum.repos.d/CentOS-*.repo
建立新的缓存
yum clean all
yum makecache
其他版本的CentOS用户,请参考CentOS Vault Mirror官网,并根据需要修改上述命令中的URLhttps://vault.centos.org/7.9.2009/。