背景
centos7已经停止支持,yum源也失效了 ,但是我们服务用的都是centos7 ,也不会轻易升级。so 我们只能找找替代方案,很幸运发现阿里云的yum源还可以使用,记录下来方便下次可能用到,顺便有缘人搜到这篇文章的话,也能给你一个参考。
1. 查看当前有哪些是在使用的
# 查看所有仓库配置文件 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
2. 备份配置
# 创建备份目录 mkdir -p /root/yum-repos-backup # 备份所有仓库配置 cp /etc/yum.repos.d/*.repo /root/yum-repos-backup/
3. 安装阿里云yum源
# 删除之前的所有配置 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仓库配置
# 创建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
4. 清理缓存并测试
# 清理所有缓存 yum clean all # 重新生成缓存 yum makecache # 测试仓库连接 yum repolist enabled
5.方法补充
最新centos 7 yum源失效的解决方案
方案一:切换至阿里云源(推荐)
# 备份原有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
方案二:系统迁移
建议升级至以下替代系统:
- centos stream 8/9
- rhel 8/9(开发者订阅免费)
- almalinux/rockylinux 8/9
迁移工具推荐:
sudo yum install -y leapp-upgrade sudo leapp preupgrade
验证方法
# 测试源可用性 sudo yum install -y telnet && echo "源配置成功" # 检查系统可升级包 sudo yum check-update
重要提示:本文方案仅为临时应对措施,建议在测试环境验证后实施。对于关键业务系统,应制定完整的迁移计划。
到此这篇关于解决centos7下yum失效问题的文章就介绍到这了,更多相关centos7 yum失效解决内容请搜索代码网以前的文章或继续浏览下面的相关文章希望大家以后多多支持代码网!
发表评论