yum 源 :Errors during downloading metadata for repository ‘BaseOS‘ / ‘AppStream‘

问题

CentOS 8 yum安装软件时,提示无法从 appstream \ base下载

[root@zy yum.repos.d]# yum -y install epel-release
CentOS-8 - Base                                                                                                                                                                   443  B/s | 153  B     00:00    
Errors during downloading metadata for repository 'BaseOS':
  - Status code: 404 for https://mirrors.tuna.tsinghua.edu.cn/centos/8/BaseOS/x86_64/os/repodata/repomd.xml (IP: 101.6.15.130)
Error: Failed to download metadata for repo 'BaseOS': Cannot download repomd.xml: Cannot download repodata/repomd.xml: All mirrors were tried
# 或者以下错误
CentOS-8 - AppStream                                                                                8.8 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

本人为 第一种解法 解决了云主机无法使用 yum 的问题!
其他解法 请读者自行尝试!


解法一

错误信息如下:

[root@zy nginx-1.19.0]# yum install node:16
CentOS-8 - AppStream                                                                                8.8 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

首先备份原有数据

cp /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo1
cp /etc/yum.repos.d/CentOS-AppStream.repo /etc/yum.repos.d/CentOS-AppStream.repo1 

执行以下命令

vim /etc/yum.repos.d/CentOS-Base.repo
# esc 键盘 : 命令模式下执行:
(进入文件后直接输入冒号,粘贴如下两个命令即可)
%s/mirrors.cloud.aliyuncs.com/mirrors.aliyun.com/g 
# 继续执行:
%s/$releasever/$releasever-stream/g

### 执行如上
vim /etc/yum.repos.d/CentOS-AppStream.repo
# esc 键盘 : 命令模式下执行:
%s/mirrors.cloud.aliyuncs.com/mirrors.aliyun.com/g 
# 继续执行:
%s/$releasever/$releasever-stream/g

最后!       解决!!!

yum makecache
yum update


解法二

  1. 备份文件
rename '.repo' '.repo.bak' /etc/yum.repos.d/*.repo
  1. 下载最新的repo文件
wget https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo -O /etc/yum.repos.d/Centos-vault-8.5.2111.repo
#如果后期 yum clean all && yum makecache报错下载xml文件404,则不需要执行这一句
wget https://mirrors.aliyun.com/repo/epel-archive-8.repo -O /etc/yum.repos.d/epel-archive-8.repo 
  1. 替换 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
#如果后期 yum clean all && yum makecache报错下载xml文件404,则不需要执行这一句
sed -i 's/mirrors.aliyun.com/mirrors.cloud.aliyuncs.com/g' /etc/yum.repos.d/epel-archive-8.repo

yum clean all && yum makecache


解法三

1. 先排除网络问题

检查网通不通,然后确定DNS解析是否正确

[root@zy yum.repos.d]# ping www.baidu.com 
PING www.a.shifen.com (14.215.177.39) 56(84) bytes of data.
64 bytes from 14.215.177.39 (14.215.177.39): icmp_seq=1 ttl=52 time=7.72 ms
64 bytes from 14.215.177.39 (14.215.177.39): icmp_seq=2 ttl=52 time=7.74 ms
64 bytes from 14.215.177.39 (14.215.177.39): icmp_seq=3 ttl=52 time=7.75 ms
64 bytes from 14.215.177.39 (14.215.177.39): icmp_seq=4 ttl=52 time=7.74 ms
^C
--- www.a.shifen.com ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 7ms
rtt min/avg/max/mdev = 7.716/7.736/7.751/0.088 ms

2. 更换国内yum源

我们无法使用CentOS原生yum源就是因为网络问题,你懂的。
为了快,更换国内yum源,推荐阿里云yum或者腾讯yum。网易没落了。

或者 此地址也可以 http://mirrors.aliyun.com/repo/Centos-8.repo
这里给出 shell 命令:

  • wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-8.repo
  • wget -O /etc/yum.repos.d/CentOS-AppStream.repo http://mirrors.aliyun.com/repo/Centos-8.repo
[root@zy yum.repos.d]#  wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.cloud.tencent.com/repo/centos8_base.repo
--2022-02-17 09:50:22--  http://mirrors.cloud.tencent.com/repo/centos8_base.repo
Resolving mirrors.cloud.tencent.com (mirrors.cloud.tencent.com)... 42.194.157.107
Connecting to mirrors.cloud.tencent.com (mirrors.cloud.tencent.com)|42.194.157.107|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1792 (1.8K) [application/octet-stream]
Saving to: ‘/etc/yum.repos.d/CentOS-Base.repo’
 
/etc/yum.repos.d/CentOS-Base.repo                    100%[====================================================================================================================>]   1.75K  --.-KB/s    in 0s      
 
2022-02-17 09:50:22 (345 MB/s) - ‘/etc/yum.repos.d/CentOS-Base.repo’ saved [1792/1792]
 
[root@zy yum.repos.d]# ls
bak                          CentOS-Linux-BaseOS.repo             CentOS-Linux-Devel.repo   CentOS-Linux-FastTrack.repo         CentOS-Linux-Plus.repo
CentOS-Base.repo             CentOS-Linux-ContinuousRelease.repo  CentOS-Linux-epel.repo    CentOS-Linux-HighAvailability.repo  CentOS-Linux-PowerTools.repo
CentOS-Linux-AppStream.repo  CentOS-Linux-Debuginfo.repo          CentOS-Linux-Extras.repo  CentOS-Linux-Media.repo 
[root@zy yum.repos.d]# vi CentOS-Base.repo 
[root@zy yum.repos.d]# rm -rf CentOS-Linux-BaseOS.repo 
[root@zy yum.repos.d]# mv CentOS-Base.repo CentOS-Linux-BaseOS.repo
[root@zy yum.repos.d]# ls
bak                          CentOS-Linux-ContinuousRelease.repo  CentOS-Linux-epel.repo       CentOS-Linux-HighAvailability.repo  CentOS-Linux-PowerTools.repo
CentOS-Linux-AppStream.repo  CentOS-Linux-Debuginfo.repo          CentOS-Linux-Extras.repo     CentOS-Linux-Media.repo             CentOS-Linux-Sources.repo
CentOS-Linux-BaseOS.repo     CentOS-Linux-Devel.repo              CentOS-Linux-FastTrack.repo  CentOS-Linux-Plus.repo

使用yum建立缓存还是报错

[root@zy yum.repos.d]# yum makecache
Repository extras is listed more than once in the configuration
Repository fasttrack is listed more than once in the configuration
CentOS Linux 8 - AppStream                                                                                                                                                        8.0 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

3. 解决makecahe报错

  • Failed to download metadata for repo ‘appstream’
  • Error: Failed to download metadata for repo ‘appstream’ # 下载meta信息失败

问题的原因

先看看CentOS7的 yum.repos.d

[root@zy-1 ~]#ll /etc/yum.repos.d/
total 44
-rw-r--r--. 1 root root 2523 Oct 27 22:47 CentOS-Base.repo
-rw-r--r--. 1 root root 1664 Sep  5  2019 CentOS-Base.repo.bak
-rw-r--r--. 1 root root 1309 Sep  5  2019 CentOS-CR.repo
-rw-r--r--. 1 root root  649 Sep  5  2019 CentOS-Debuginfo.repo
-rw-r--r--. 1 root root  314 Sep  5  2019 CentOS-fasttrack.repo
-rw-r--r--. 1 root root  630 Sep  5  2019 CentOS-Media.repo
-rw-r--r--. 1 root root 1331 Sep  5  2019 CentOS-Sources.repo
-rw-r--r--. 1 root root 6639 Sep  5  2019 CentOS-Vault.repo
-rw-r--r--. 1 root root  951 Oct  2  2017 epel.repo
-rw-r--r--. 1 root root 1050 Oct  2  2017 epel-testing.repo

再看看CentOS8的yum.repos.d

[root@zy-3 ~]# ll /etc/yum.repos.d/
total 56
-rw-r--r--. 1 root root  815 Oct 28 02:33 CentOS-AppStream.repo
-rw-r--r--. 1 root root 1792 Mar 25  2020 CentOS-Base.repo
-rw-r--r--. 1 root root  712 Jan  2  2020 CentOS-Base.repo.backup
-rw-r--r--. 1 root root 1792 Mar 25  2020 CentOS-Base.repo.backup.3
-rw-r--r--. 1 root root  798 Jan  2  2020 CentOS-centosplus.repo
-rw-r--r--. 1 root root 1043 Jan  2  2020 CentOS-CR.repo
-rw-r--r--. 1 root root  668 Jan  2  2020 CentOS-Debuginfo.repo
-rw-r--r--. 1 root root  756 Jan  2  2020 CentOS-Extras.repo
-rw-r--r--. 1 root root  338 Jan  2  2020 CentOS-fasttrack.repo
-rw-r--r--. 1 root root  738 Jan  2  2020 CentOS-HA.repo
-rw-r--r--. 1 root root  928 Jan  2  2020 CentOS-Media.repo
-rw-r--r--. 1 root root  736 Jan  2  2020 CentOS-PowerTools.repo
-rw-r--r--. 1 root root 1382 Jan  2  2020 CentOS-Sources.repo
-rw-r--r--. 1 root root   74 Jan  2  2020 CentOS-Vault.repo

CentOS 8 多了一个 CentOS-AppStream.repo

这是出问题的关键

查看一下CentOS-AppStream.repo

[root@zy-3 ~]# vi CentOS-Linux-AppStream.repo
# CentOS-Linux-AppStream.repo
#
# The mirrorlist system uses the connecting IP address of the client and the
# update status of each mirror to pick current mirrors that are geographically
# close to the client.  You should use this for CentOS updates unless you are
# manually picking other mirrors.
#
# If the mirrorlist does not work for you, you can try the commented out
# baseurl line instead.
 
[appstream]
name=CentOS Linux $releasever - AppStream
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=AppStream&infra=$infra
baseurl=http://mirrors.cloud.aliyuncs.com/$contentdir/$releasever/AppStream/$basearch/os/
gpgcheck=1
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial

解决问题的方法

我们在替换yum源的时候,按照镜像网站的操作方式,只替换了CentOS-Base.repo。
可是在CentOS8中,CentOS-AppStream.repo的内容没有更新。

替换更新

  1. 找到跟新后CentOS-Linux-BaseOS.repo中[appstream]标签内的内容并复制
[root@zy yum.repos.d]# vi CentOS-Linux-AppStream.repo 
 
# CentOS-Linux-AppStream.repo
#
# The mirrorlist system uses the connecting IP address of the client and the
# update status of each mirror to pick current mirrors that are geographically
# close to the client.  You should use this for CentOS updates unless you are
# manually picking other mirrors.
#
# If the mirrorlist does not work for you, you can try the commented out
# baseurl line instead.
 
[appstream]
name=Qcloud centos AppStream - $basearch
baseurl=http://mirrors.cloud.tencent.com/centos/$releasever/AppStream/$basearch/os/
enabled=0
gpgcheck=1
gpgkey=http://mirrors.cloud.tencent.com/centos/RPM-GPG-KEY-CentOS-Official
  1. 打开CentOS-AppStream.repo,注释掉原有内容,并插入新内容
[root@zy-3 ~]# vim /etc/yum.repos.d/CentOS-AppStream.repo
# [appstream]
# name=CentOS Linux $releasever - AppStream
# mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=AppStream&infra=$infra
# baseurl=http://mirrors.cloud.aliyuncs.com/$contentdir/$releasever/AppStream/$basearch/os/
# gpgcheck=1
# enabled=1
# gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
 
[appstream]
name=Qcloud centos AppStream - $basearch
baseurl=http://mirrors.cloud.tencent.com/centos/$releasever/AppStream/$basearch/os/
enabled=0
gpgcheck=1
gpgkey=http://mirrors.cloud.tencent.com/centos/RPM-GPG-KEY-CentOS-Official

我们要养成修改内容时使用注释而不是删除的操作方法,用来对比前后差异,出问题了取消掉注释就可以了。

问题解决

重新运行yum makecache

[root@zy yum.repos.d]# yum makecache
Repository extras is listed more than once in the configuration
Repository fasttrack is listed more than once in the configuration
Qcloud centos OS - x86_64                                                                                                                                                         4.2 MB/s | 4.6 MB     00:01    
Qcloud centos extras - x86_64                                                                                                                                                      23 kB/s |  10 kB     00:00    
Extra Packages for Enterprise Linux 8 - x86_64                                                                                                                                     61 MB/s |  11 MB     00:00    
Metadata cache created.

  • 6
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

ZC~Reunion

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值