Error: Failed to download metadata for repo 'appstream': Cannot download repomd.xml
编辑于 2022-11-28 00:11:11 阅读 3251
背景信息
CentOS 8操作系统版本结束了生命周期(EOL),Linux社区已不再维护该操作系统版本。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的源会发生报错。报错原文如下
[root@iZbp1430s16l9piu268n8rZ data]# yum install git
CentOS Linux 8 - AppStream 14 kB/s | 2.3 kB 00:00
Errors during downloading metadata for repository 'appstream':
- Status code: 404 for http://mirrors.cloud.aliyuncs.com/centos/8/AppStream/x86_64/os/repodata/repomd.xml (IP: 100.100.2.148)
Error: Failed to download metadata for repo 'appstream': Cannot download repomd.xml: Cannot download repodata/repomd.xml: All mirrors were tried
操作步骤
- 登录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
非阿里云用户
- 先备份
rename '.repo' '.repo.bak' /etc/yum.repos.d/*.repo
- 下载新的 CentOS-Base.repo 到 /etc/yum.repos.d/
wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo
- 运行
yum makecache
生成缓存