问题
CentOS 8 yum安装软件时,提示无法从appstream下载
[root@iZwz99xeomvq1omj9cu7tuZ 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
先排除网络问题
检查网通不通,然后确定DNS解析是否正确
[root@iZwz99xeomvq1omj9cu7tuZ 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
更换国内yum源
我们无法使用CentOS原生yum源就是因为网络问题,你懂的。
为了快,更换国内yum源,推荐阿里云yum或者腾讯yum。网易没落了。
- 阿里yum源: centos镜像-centos下载地址-centos安装教程-阿里巴巴开源镜像站
- 腾云yum源: CentOS
[root@iZwz99xeomvq1omj9cu7tuZ 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@iZwz99xeomvq1omj9cu7tuZ 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@iZwz99xeomvq1omj9cu7tuZ yum.repos.d]# vi CentOS-Base.repo
[root@iZwz99xeomvq1omj9cu7tuZ yum.repos.d]# rm -rf CentOS-Linux-BaseOS.repo
[root@iZwz99xeomvq1omj9cu7tuZ yum.repos.d]# mv CentOS-Base.repo CentOS-Linux-BaseOS.repo
[root@iZwz99xeomvq1omj9cu7tuZ 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@iZwz99xeomvq1omj9cu7tuZ 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
解决makecahe报错
- Failed to download metadata for repo 'appstream'
- Error: Failed to download metadata for repo 'appstream' # 下载meta信息失败
问题的原因
先看看CentOS7的yum.repos.d
[21:19:17 root@C7-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@C8-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@C8-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的内容没有更新。
替换更新
- 找到跟新后CentOS-Linux-BaseOS.repo中[appstream]标签内的内容并复制
[root@iZwz99xeomvq1omj9cu7tuZ 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
- 打开CentOS-AppStream.repo,注释掉原有内容,并插入新内容
[root@C8-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@iZwz99xeomvq1omj9cu7tuZ 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.