ECS使用yum命令安装软件包失败时提示"HTTP Error 404 -Not Found Trying other mirror"

免责申明:本文可能由社区贡献或涉及第三方产品信息,建议您访问社区或第三方产品的官方网站获取帮助与支持。第三方产品不在阿里云售后支持范围。本文仅供参考,阿里云不做任何暗示或其他形式的承诺。

问题描述
执行yum -y install XXX、yum list、yum search XXX等从YUM仓库获取资源信息命令时,出现类似如下报错信息。
http://mirrors.cloud.aliyuncs.com/centos/7/os/x86_64/repodata/repomd.xml: [Errno 14] HTTP Error 404 - Not Found

或者出现URL中$releasever变量无法识别的报错,此报错您需要使用缺少centos-release软件包步骤解决问题。
http://mirrors.cloud.aliyuncs.com/centos/$releasever/os/x86_64/repodata/repomd.xml: [Errno 14] HTTP Error 404 - Not Found

CentOS 8 EOL如何切换源?

CentOS 8操作系统版本结束了生命周期(EOL),Linux社区已不再维护该操作系统版本。建议您切换到Anolis或Alinux。如果您的业务过渡期仍需要使用CentOS 8系统中的一些安装包,请根据下文切换CentOS 8的源。

背景信息
2021年12月31日CentOS 8 EOL。按照社区规则,CentOS 8的源地址[http://mirror.centos.org/centos/8/] 内容已移除,目前第三方的镜像站中均已移除CentOS 8的源。阿里云的源[http://mirrors.cloud.aliyuncs.com] 和[http://mirrors.aliyun.com] 也无法同步到CentOS 8的源。当您在阿里云上继续使用默认配置的CentOS 8的源会发生报错。报错示例如下图所示:centos8报错
您可以通过下文的操作步骤,在CentOS 8操作系统的ECS实例中将源配置按照网络环境不同进行切换。

yum源:专有网络VPC类型实例需切换为[http://mirrors.cloud.aliyuncs.com/centos-vault/8.5.2111] 源。
epel源:专有网络VPC类型实例需切换为[http://mirrors.cloud.aliyuncs.com/epel-archive/8/] 源。

说明 本文主要说明ECS实例中的相关操作与配置。如果您的服务器不是ECS实例,需保证服务器具有公网访问能力,并且源地址[http://mirrors.cloud.aliyuncs.com] 需要替换为 [http://mirrors.aliyun.com] 。例如,切换yum源为[http://mirrors.aliyun.com/centos-vault/8.5.2111/] 切换epel源为http://mirrors.aliyun.com/epel-archive/8/] 。

操作步骤

登录CentOS 8系统的ECS实例。具体操作,请参见连接方式概述。

运行以下命令备份之前的repo文件。

rename '.repo' '.repo.bak' /etc/yum.repos.d/*.repo

运行以下命令下载最新的repo文件。

wget https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo -O /etc/yum.repos.d/Centos-vault-8.5.2111.repo

wget https://mirrors.aliyun.com/repo/epel-archive-8.repo -O /etc/yum.repos.d/epel-archive-8.repo

运行以下命令替换repo文件中的链接。

sed -i 's/mirrors.cloud.aliyuncs.com/url_tmp/g' /etc/yum.repos.d/Centos-vault-8.5.2111.repo && sed -i 's/mirrors.aliyun.com/mirrors.cloud.aliyuncs.com/g' /etc/yum.repos.d/Centos-vault-8.5.2111.repo && sed -i 's/url_tmp/mirrors.aliyun.com/g' /etc/yum.repos.d/Centos-vault-8.5.2111.repo

sed -i 's/mirrors.aliyun.com/mirrors.cloud.aliyuncs.com/g' /etc/yum.repos.d/epel-archive-8.repo

运行以下命令重新创建缓存。

yum clean all && yum makecache

yum源和epel源切换完成后,即可使用yum install命令在实例上安装您所需要的软件包。

[anchor0]: http://mirror.centos.org/centos/8/内容已移除,目前第三方的镜像站中均已移除CentOS
[anchor1]: http://mirrors.cloud.aliyuncs.com和http://mirrors.aliyun.com也无法同步到CentOS
[anchor2]: http://mirrors.cloud.aliyuncs.com/centos-vault/8.5.2111源。
[anchor3]: http://mirrors.cloud.aliyuncs.com/epel-archive/8/源。
[anchor4]: http://mirrors.cloud.aliyuncs.com需要替换为http://mirrors.aliyun.com。例如,切换yum源为http://mirrors.aliyun.com/centos-vault/8.5.2111/;切换epel源为http://mirrors.aliyun.com/epel-archive/8/。
Last modification:October 14, 2022
如果觉得我的文章对你有用,请随意赞赏