问题

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

  1. [root@zy yum.repos.d]# yum -y install epel-release
  2. CentOS-8 - Base 443 B/s | 153 B 00:00
  3. Errors during downloading metadata for repository 'BaseOS':
  4. - Status code: 404 for https://mirrors.tuna.tsinghua.edu.cn/centos/8/BaseOS/x86_64/os/repodata/repomd.xml (IP: 101.6.15.130)
  5. Error: Failed to download metadata for repo 'BaseOS': Cannot download repomd.xml: Cannot download repodata/repomd.xml: All mirrors were tried
  6. # 或者以下错误
  7. CentOS-8 - AppStream 8.8 kB/s | 2.3 kB 00:00
  8. Errors during downloading metadata for repository 'AppStream':
  9. - Status code: 404 for http://mirrors.cloud.aliyuncs.com/centos/8/AppStream/x86_64/os/repodata/repomd.xml (IP: 100.100.2.148)
  10. Error: Failed to download metadata for repo 'AppStream': Cannot download repomd.xml: Cannot download repodata/repomd.xml: All mirrors were tried

本人为第二种解法 解决了本机的问题

解法一

1. 先排除网络问题

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

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

2. 更换国内yum源

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

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

使用yum建立缓存还是报错

  1. [root@zy yum.repos.d]# yum makecache
  2. Repository extras is listed more than once in the configuration
  3. Repository fasttrack is listed more than once in the configuration
  4. CentOS Linux 8 - AppStream 8.0 kB/s | 2.3 kB 00:00
  5. Errors during downloading metadata for repository 'appstream':
  6. - Status code: 404 for http://mirrors.cloud.aliyuncs.com/centos/8/AppStream/x86_64/os/repodata/repomd.xml (IP: 100.100.2.148)
  7. Error: Failed to download metadata for repo 'appstream': Cannot download repomd.xml: Cannot download repodata/repomd.xml: All mirrors were tried

解决makecahe报错

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

问题的原因

先看看CentOS7的 yum.repos.d

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

再看看CentOS8的yum.repos.d

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

CentOS 8 多了一个 CentOS-AppStream.repo

这是出问题的关键

查看一下CentOS-AppStream.repo

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

解决问题的方法

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

替换更新

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

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

问题解决

重新运行yum makecache

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

解法二

错误信息如下:

  1. [root@zy nginx-1.19.0]# yum install node:16
  2. CentOS-8 - AppStream 8.8 kB/s | 2.3 kB 00:00
  3. Errors during downloading metadata for repository 'AppStream':
  4. - Status code: 404 for http://mirrors.cloud.aliyuncs.com/centos/8/AppStream/x86_64/os/repodata/repomd.xml (IP: 100.100.2.148)
  5. Error: Failed to download metadata for repo 'AppStream': Cannot download repomd.xml: Cannot download repodata/repomd.xml: All mirrors were tried

首先备份原有数据

  1. cp /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo1
  2. cp /etc/yum.repos.d/CentOS-AppStream.repo /etc/yum.repos.d/CentOS-AppStream.repo1
  3. # 此处没有文件的使用以下地址下载!
  4. wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-8.repo
  5. wget -O /etc/yum.repos.d/CentOS-AppStream.repo http://mirrors.aliyun.com/repo/Centos-8.repo

编辑如下文件

  1. vim /etc/yum.repos.d/CentOS-Base.repo
  2. # esc 键盘 : 命令模式下执行:
  3. %s/mirrors.cloud.aliyuncs.com/mirrors.aliyun.com/g
  4. # 继续执行:
  5. %s/$releasever/$releasever-stream/g
  6. vim /etc/yum.repos.d/CentOS-AppStream.repo
  7. # esc 键盘 : 命令模式下执行:
  8. %s/mirrors.cloud.aliyuncs.com/mirrors.aliyun.com/g
  9. # 继续执行:
  10. %s/$releasever/$releasever-stream/g

最后

  1. yum makecache
  2. yum update