背景:在进行服务器系统安全类问题更新时,yum update 更新发现报错如下
[Errno 14] PYCURL ERROR 22 - "The requested URL returned error: 404 Not Found"
Trying other mirror.
To address this issue please refer to the below wiki article
https://wiki.centos.org/yum-errors
If above article doesn't help to resolve this issue please use https://bugs.centos.org/.
重新设置 yum 源后,用官方、阿里、网易等的源都是仍然报这个错。
换个思路,可能是源发生变更了,在查询CentOS官网产品信息(https://wiki.centos.org/zh/About/Product)后果然发现,CentOS6源仓库于2020.11.30停止维护更新了(CentOS5早在2017年初就停了),被移除了,因国内各大镜像源是同步的所以也都失效了。
解决建议:
1、最安全:升级CentOS系统版本改用CentOS7或8.
2、如果生产环境对安全问题(如漏洞更新补丁等)要求不是很严格,可用官网的旧版存档 https://vault.centos.org/ 先顶一段时间,该旧版存档源由开发者维护而不是官方了,所以一些安全更新可能不是很及时,且在国外下载获取速度相对慢一些。
下面给出该具体方法:
1)查看当前系统版本后面会用 cat /etc/issue
[root]# cat /etc/issue
CentOS release 6.10 (Final)
Kernel \r on an \m
[root]#
2)修改源仓库文件(先备份再操作)
cp /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak // 备份文件
vim /etc/yum.repos.d/CentOS-Base.repo // 编辑文件
将内容中原来阿里或网易等镜像的 url 链接改为 https://vault.centos.org/ ,若用的是原来 mirrorlist 源,就把 mirrorlist 开头的行注释掉在旁边新添加 baseurl 开头的行,案例如下
[base]
name=CentOS-$releasever - Base
baseurl=http://vault.centos.org/$releasever/os/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os
gpgcheck=1
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-6
#released updates
[updates]
name=CentOS-$releasever - Updates
baseurl=http://vault.centos.org/$releasever/updates/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates
gpgcheck=1
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-6
#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras
baseurl=http://vault.centos.org/$releasever/extras/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras
gpgcheck=1
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-6
#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever - Plus
baseurl=http://vault.centos.org/$releasever/centosplus/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus
gpgcheck=1
enabled=0
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-6
#contrib - packages by Centos Users
[contrib]
name=CentOS-$releasever - Contrib
baseurl=http://vault.centos.org/$releasever/contrib/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=contrib
gpgcheck=1
enabled=0
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-6
注:若是CentOS5,还要将其中几行 gpgkey=......KEY-CentOS-6 行末的 6 都改为 5 。
这时,若版本号就是6,不是6.2或6.10等有小数点后缀的版本号,
保存后运行
yum clean all
yum makecache
一般没问题,否则仍可能报错,下面继续。
3)若上步后仍然报错,就是URL中的变量 $releasever 值问题,报错提示网址404,网址路径不对应。$releasever 得到的值是发行版本号的整数,无小数点,查看命令 rpm -qi centos-release 显示列表中 Version 值便是。若 系统实际 版本号是有小数点后缀的,可直接把 CentOS-Base.repo 文件内容中几行 baseurl 开头行中的 $releasever 替换为有小数点的版本号,我的版本号是6.10,替换结果如下(记住先备份文件或注释原有行复制粘贴新行再修改)!
[base]
name=CentOS-$releasever - Base
baseurl=http://vault.centos.org/6.10/os/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os
gpgcheck=1
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-6
#released updates
[updates]
name=CentOS-$releasever - Updates
baseurl=http://vault.centos.org/6.10/updates/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates
gpgcheck=1
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-6
#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras
baseurl=http://vault.centos.org/6.10/extras/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras
gpgcheck=1
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-6
#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever - Plus
baseurl=http://vault.centos.org/6.10/centosplus/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus
gpgcheck=1
enabled=0
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-6
#contrib - packages by Centos Users
[contrib]
name=CentOS-$releasever - Contrib
baseurl=http://vault.centos.org/6.10/contrib/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=contrib
gpgcheck=1
enabled=0
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-6
保存运行 yum clean 然后 yum makecache 再 yum update。
4)若仍然报错,多半是因为设置了 epel 项目,报错中提示epel中的网址404,文件路径 /etc/yum.repos.d/epel.repo,epel项目维护跟随官方,所以也停止了维护被移除了。
什么是epel? 如果既想获得 RHEL 的高质量、高性能、高可靠性,又需要方便易用(关键是免费)的软件包更新功能,那么 Fedora Project 推出的 EPEL(Extra Packages for Enterprise Linux)正好适合。EPEL(http://fedoraproject.org/wiki/EPEL) 是由 Fedora 社区打造,为 RHEL 及衍生发行版如 CentOS、Scientific Linux 等提供高质量软件包的项目。
将 epel.repo 文件重新命名为 epel.repo.back 让epel找不到文件不去找额外包即可,也可直接删除该文件但不推荐。
mv /etc/yum.repos.d/epel.repo /etc/yum.repos.d/epel.repo.bak
运行
yum clean all
yum makecache
yum update
我的分享至此结束。
如有更好解决方式或发现错误,欢迎评论补充和纠正。谢谢!