centos7已经停止支持,yum源也失效了 ,但是我们服务用的都是CentOS7 ,也不会轻易升级。so 我们只能找找替代方案,很幸运发现阿里云的yum源还可以使用,记录下来方便下次可能用到,顺便有缘人搜到这篇文章的话,也能给你一个参考。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# 查看所有仓库配置文件 ls -l /etc/yum.repos.d/
总用量 56 -rw-r--r--. 1 root root 2523 8月 2 2024 CentOS-Base.repo -rw-r--r--. 1 root root 1309 10月 23 2020 CentOS-CR.repo -rw-r--r--. 1 root root 649 10月 23 2020 CentOS-Debuginfo.repo -rw-r--r--. 1 root root 314 10月 23 2020 CentOS-fasttrack.repo -rw-r--r--. 1 root root 630 10月 23 2020 CentOS-Media.repo -rw-r--r--. 1 root root 1331 10月 23 2020 CentOS-Sources.repo -rw-r--r--. 1 root root 8515 10月 23 2020 CentOS-Vault.repo -rw-r--r--. 1 root root 616 10月 23 2020 CentOS-x86_64-kernel.repo -rw-r--r--. 1 root root 2081 8月 2 2024 docker-ce.repo -rw-r--r--. 1 root root 951 10月 3 2017 epel.repo -rw-r--r--. 1 root root 1050 10月 3 2017 epel-testing.repo -rw-r--r--. 1 root root 0 7月 23 2024 jenkins.repo -rw-r--r--. 1 root root 477 4月 27 2014 nux-dextop.repo
# 查看当前启用的仓库 yum repolist all |
1 2 3 4 5 |
# 创建备份目录 mkdir -p /root/yum-repos-backup
# 备份所有仓库配置 cp /etc/yum.repos.d/*.repo /root/yum-repos-backup/ |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# 删除之前的所有配置 rm -rf /etc/yum.repos.d/*
# 配置阿里云 # 检查阿里云网络是否正常 curl -I http://mirrors.aliyun.com/centos-vault/7.9.2009/os/x86_64/
# 创建新的完整仓库配置 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/x86_64/ enabled=1 gpgcheck=1 gpgkey=http://mirrors.aliyun.com/centos-vault/RPM-GPG-KEY-CentOS-7
[updates] name=CentOS-7 - Updates baseurl=http://mirrors.aliyun.com/centos-vault/7.9.2009/updates/x86_64/ enabled=1 gpgcheck=1 gpgkey=http://mirrors.aliyun.com/centos-vault/RPM-GPG-KEY-CentOS-7
[extras] name=CentOS-7 - Extras baseurl=http://mirrors.aliyun.com/centos-vault/7.9.2009/extras/x86_64/ enabled=1 gpgcheck=1 gpgkey=http://mirrors.aliyun.com/centos-vault/RPM-GPG-KEY-CentOS-7
[centosplus] name=CentOS-7 - Plus baseurl=http://mirrors.aliyun.com/centos-vault/7.9.2009/centosplus/x86_64/ enabled=0 gpgcheck=1 gpgkey=http://mirrors.aliyun.com/centos-vault/RPM-GPG-KEY-CentOS-7 EOF |
创建EPEL仓库配置
1 2 3 4 5 6 7 8 9 |
# 创建EPEL仓库配置 cat > /etc/yum.repos.d/epel.repo << 'EOF' [epel] name=Extra Packages for Enterprise Linux 7 - x86_64 baseurl=http://mirrors.aliyun.com/epel/7/x86_64/ enabled=1 gpgcheck=1 gpgkey=http://mirrors.aliyun.com/epel/RPM-GPG-KEY-EPEL-7 EOF |
1 2 3 4 5 6 7 8 |
# 清理所有缓存 yum clean all
# 重新生成缓存 yum makecache
# 测试仓库连接 yum repolist enabled |
最新CentOS 7 yum源失效的解决方案
方案一:切换至阿里云源(推荐)
1 2 3 4 5 6 7 8 9 10 11 |
# 备份原有repo文件 mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
# 下载新的 CentOS-Base.repo 到 /etc/yum.repos.d/ wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo 或 curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
# 清理并重建缓存 sudo yum clean all sudo yum makecache |
方案二:系统迁移
建议升级至以下替代系统:
迁移工具推荐:
1 2 |
sudo yum install -y leapp-upgrade sudo leapp preupgrade |
验证方法
1 2 3 4 5 |
# 测试源可用性 sudo yum install -y telnet && echo "源配置成功"
# 检查系统可升级包 sudo yum check-update |
重要提示:本文方案仅为临时应对措施,建议在测试环境验证后实施。对于关键业务系统,应制定完整的迁移计划。