CentOS7换源教程

CentOS 7 官方已 EOL,现在换源一般有两种思路:

  • 推荐:换到 CentOS Vault(官方历史仓库,最稳)

  • 🔁 常用:换到 国内镜像的 vault 源(速度更快)


一、推荐方案:使用官方 CentOS Vault(最稳)

1️⃣ 备份原有 repo

mkdir -p /etc/yum.repos.d/backup
mv /etc/yum.repos.d/*.repo /etc/yum.repos.d/backup/

2️⃣ 新建 vault 源文件

vi /etc/yum.repos.d/CentOS-Vault.repo

粘贴以下内容(CentOS 7.9.2009)👇

[base]
name=CentOS-7.9.2009 - Base
baseurl=http://vault.centos.org/7.9.2009/os/$basearch/
gpgcheck=1
gpgkey=http://vault.centos.org/RPM-GPG-KEY-CentOS-7
enabled=1

[updates]
name=CentOS-7.9.2009 - Updates
baseurl=http://vault.centos.org/7.9.2009/updates/$basearch/
gpgcheck=1
gpgkey=http://vault.centos.org/RPM-GPG-KEY-CentOS-7
enabled=1

[extras]
name=CentOS-7.9.2009 - Extras
baseurl=http://vault.centos.org/7.9.2009/extras/$basearch/
gpgcheck=1
gpgkey=http://vault.centos.org/RPM-GPG-KEY-CentOS-7
enabled=1

3️⃣ 清缓存并测试

yum clean all
yum makecache
yum repolist

二、国内镜像(阿里云 Vault,速度更快)

如果你在国内或需要更快速度,推荐阿里云 vault

sed -i.bak \
-e 's|^mirrorlist=|#mirrorlist=|g' \
-e 's|^#baseurl=http://mirror.centos.org|baseurl=https://mirrors.aliyun.com/centos-vault|g' \
/etc/yum.repos.d/CentOS-*.repo

然后:

yum clean all
yum makecache

三、验证是否成功

yum install -y wget

能正常安装说明换源成功 ✅


四、常见问题

❓ 报错:Cannot find a valid baseurl

  • 多半是 还在用 mirrorlist

  • 检查 repo 是否还有 mirrorlist= 没被注释

grep mirrorlist /etc/yum.repos.d/*.repo

❓ GPG key 错误

rpm --import http://vault.centos.org/RPM-GPG-KEY-CentOS-7

 

© 版权声明
THE END
喜欢就支持一下吧
点赞7 分享