由于国内网络环境较为特殊, 无法直接连接境外的yun仓库, 且centos官方已不再对centos7.0的yum仓库支持, 新装系统第一步要做的就是更换yum云镜像仓库源.
1.备份原有的源配置文件
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
2.下载阿里云的 CentOS 7 源配置
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
(如以上提示:-bash: wget: 未找到命令 则使用curl方式将源配置下载到本地)
curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo

3.清理缓存并生成新缓存
yum clean all
yum makecache
4.配置 CentOS 7 的基础源,这里使用阿里云的 Vault 镜像并通过 HTTP 协议访问,以绕过 HTTPS 加密问题
cat > /etc/yum.repos.d/CentOS-Base.repo << 'EOF'
[base]
name=CentOS-7 - Base
baseurl=http://mirrors.aliyun.com/centos-vault/7.9.2009/os/$basearch/
gpgcheck=0
enabled=1
[updates]
name=CentOS-7 - Updates
baseurl=http://mirrors.aliyun.com/centos-vault/7.9.2009/updates/$basearch/
gpgcheck=0
enabled=1
[extras]
name=CentOS-7 - Extras
baseurl=http://mirrors.aliyun.com/centos-vault/7.9.2009/extras/$basearch/
gpgcheck=0
enabled=1
EOF
5.清理并重建 yum 缓存
yum clean all
yum makecache
6.更新 NSS(网络安全服务)加密库和 curl,来从根本上修复 HTTPS 连接的问题
yum update -y nss nss-util nss-sysinit nss-tools curl ca-certificates
至此,全新的centos7已完成更换阿里源并能正常支持现代 TLS 加密协议了