问题
CentOS 8 yum安装软件时,提示无法从 appstream \ base
下载
[root@zy ]# 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 /centos/8/BaseOS/x86_64/os/repodata/ (IP: 101.6.15.130)
Error: Failed to download metadata for repo 'BaseOS': Cannot download : Cannot download repodata/: 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 /centos/8/AppStream/x86_64/os/repodata/ (IP: 100.100.2.148)
Error: Failed to download metadata for repo 'AppStream': Cannot download : Cannot download repodata/: All mirrors were tried
Content
- 问题
- 解法一
- 首先备份原有数据
- 执行以下命令
- 最后! 解决!!!
- 解法二
- 解法三
- 1. 先排除网络问题
- 2. 更换国内yum源
- 3. 解决makecahe报错
- 问题的原因
- 查看一下
- 解决问题的方法
- 替换更新
- 问题解决
本人为
第一种解法
解决了云主机无法使用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 /centos/8/AppStream/x86_64/os/repodata/ (IP: 100.100.2.148)
Error: Failed to download metadata for repo 'AppStream': Cannot download : Cannot download repodata/: All mirrors were tried
首先备份原有数据
cp /etc// /etc//CentOS-Base.repo1
cp /etc// /etc//CentOS-AppStream.repo1
执行以下命令
vim /etc//
# esc 键盘 : 命令模式下执行:
(进入文件后直接输入冒号,粘贴如下两个命令即可)
%s///g
# 继续执行:
%s/$releasever/$releasever-stream/g
### 执行如上
vim /etc//
# esc 键盘 : 命令模式下执行:
%s///g
# 继续执行:
%s/$releasever/$releasever-stream/g
最后! 解决!!!
yum makecache
yum update
解法二
- 备份文件
rename '.repo' '.' /etc//*.repo
- 下载最新的repo文件
wget /repo/Centos-vault-8.5. -O /etc//Centos-vault-8.5.
#如果后期 yum clean all && yum makecache报错下载xml文件404,则不需要执行这一句
wget /repo/ -O /etc//
- 替换 repo 文件中的链接 并重新创建缓存
sed -i 's//url_tmp/g' /etc//Centos-vault-8.5. && sed -i 's///g' /etc//Centos-vault-8.5. && sed -i 's/url_tmp//g' /etc//Centos-vault-8.5.
#如果后期 yum clean all && yum makecache报错下载xml文件404,则不需要执行这一句
sed -i 's///g' /etc//
yum clean all && yum makecache
解法三
1. 先排除网络问题
检查网通不通,然后确定DNS解析是否正确
[root@zy yum.repos.d]# ping
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。网易没落了。
- 阿里yum源: centos镜像-centos下载地址-centos安装教程-阿里巴巴开源镜像站
或者 此地址也可以 /repo/
这里给出shell
命令:
- wget -O /etc// /repo/
- wget -O /etc// /repo/
- 腾云yum源: CentOS
[root@zy ]# wget -O /etc// /repo/centos8_base.repo
--2022-02-17 09:50:22-- /repo/centos8_base.repo
Resolving ()... 42.194.157.107
Connecting to ()|42.194.157.107|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1792 (1.8K) [application/octet-stream]
Saving to: ‘/etc//’
/etc// 100%[====================================================================================================================>] 1.75K -.KB/s in 0s
2022-02-17 09:50:22 (345 MB/s) - ‘/etc//’ saved [1792/1792]
[root@zy ]# ls
bak
[root@zy ]# vi
[root@zy ]# rm -rf
[root@zy ]# mv
[root@zy ]# ls
bak
使用yum建立缓存还是报错
[root@zy ]# 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 /centos/8/AppStream/x86_64/os/repodata/ (IP: 100.100.2.148)
Error: Failed to download metadata for repo 'appstream': Cannot download : Cannot download repodata/: All mirrors were tried
3. 解决makecahe报错
- Failed to download metadata for repo ‘appstream’
- Error: Failed to download metadata for repo ‘appstream’ # 下载meta信息失败
问题的原因
先看看CentOS7的
[root@zy-1 ~]#ll /etc//
total 44
-rw-r--r--. 1 root root 2523 Oct 27 22:47
-rw-r--r--. 1 root root 1664 Sep 5 2019
-rw-r--r--. 1 root root 1309 Sep 5 2019
-rw-r--r--. 1 root root 649 Sep 5 2019
-rw-r--r--. 1 root root 314 Sep 5 2019
-rw-r--r--. 1 root root 630 Sep 5 2019
-rw-r--r--. 1 root root 1331 Sep 5 2019
-rw-r--r--. 1 root root 6639 Sep 5 2019
-rw-r--r--. 1 root root 951 Oct 2 2017
-rw-r--r--. 1 root root 1050 Oct 2 2017
再看看CentOS8的
[root@zy-3 ~]# ll /etc//
total 56
-rw-r--r--. 1 root root 815 Oct 28 02:33
-rw-r--r--. 1 root root 1792 Mar 25 2020
-rw-r--r--. 1 root root 712 Jan 2 2020
-rw-r--r--. 1 root root 1792 Mar 25 2020 .3
-rw-r--r--. 1 root root 798 Jan 2 2020
-rw-r--r--. 1 root root 1043 Jan 2 2020
-rw-r--r--. 1 root root 668 Jan 2 2020
-rw-r--r--. 1 root root 756 Jan 2 2020
-rw-r--r--. 1 root root 338 Jan 2 2020
-rw-r--r--. 1 root root 738 Jan 2 2020
-rw-r--r--. 1 root root 928 Jan 2 2020
-rw-r--r--. 1 root root 736 Jan 2 2020
-rw-r--r--. 1 root root 1382 Jan 2 2020
-rw-r--r--. 1 root root 74 Jan 2 2020
CentOS 8 多了一个
这是出问题的关键
查看一下
[root@zy-3 ~]# vi
#
#
# 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=/?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源的时候,按照镜像网站的操作方式,只替换了。
可是在CentOS8中,的内容没有更新。
替换更新
- 找到跟新后中[appstream]标签内的内容并复制
[root@zy ]# vi
#
#
# 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=/centos/$releasever/AppStream/$basearch/os/
enabled=0
gpgcheck=1
gpgkey=/centos/RPM-GPG-KEY-CentOS-Official
- 打开,注释掉原有内容,并插入新内容
[root@zy-3 ~]# vim /etc//
# [appstream]
# name=CentOS Linux $releasever - AppStream
# mirrorlist=/?release=$releasever&arch=$basearch&repo=AppStream&infra=$infra
# baseurl=/$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=/centos/$releasever/AppStream/$basearch/os/
enabled=0
gpgcheck=1
gpgkey=/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.