【已解决】Error: Failed to download metadata for repo ‘appstream’: Cannot prepare internal mirrorlist: No URLs in mirrorlist
出现问题
在学习docker技术和hadoop过程中,需要安装 net-tools,然而安装时出现了错误提示信息
[root@39afa23537e2 /]# ifconfig
bash: ifconfig: command not found
[root@39afa23537e2 /]# yum install net-tools
Failed to set locale, defaulting to C.UTF-8
CentOS Linux 8 - AppStream 70 B/s | 38 B 00:00
Error: Failed to download metadata for repo 'appstream': Cannot prepare internal mirrorlist: No URLs in mirrorlist
上述报错信息字面意思是:从仓库 ‘appstream’ 下载元数据失败:由于镜像列表中没有 URL,不能准备内部镜像列表。
问题分析
可能原因1:网络连接问题。检查是否可以连接外部网络,可以使用 ping baidu.com 查看是否有丢包情况。
[root@localhost ~]# ping baidu.com
PING baidu.com (110.242.68.66) 56(84) bytes of data.
64 bytes from 110.242.68.66 (110.242.68.66): icmp_seq=1 ttl=48 time=33.3 ms
64 bytes from 110.242.68.66 (110.242.68.66): icmp_seq=2 ttl=48 time=32.8 ms
64 bytes from 110.242.68.66 (110.242.68.66): icmp_seq=3 ttl=48 time=32.7 ms
64 bytes from 110.242.68.66 (110.242.68.66): icmp_seq=4 ttl=48 time=38.2 ms
^C
--- baidu.com ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3004ms
rtt min/avg/max/mdev = 32.727/34.263/38.202/2.291 ms
可能原因2: CentOS 已经停止维护的问题。2020 年 12 月 8 号,CentOS 官方宣布了停止维护 CentOS Linux 的计划,并推出了 CentOS Stream 项目,CentOS Linux 8 作为 RHEL 8 的复刻版本,生命周期缩短,于 2021 年 12 月 31 日停止更新并停止维护(EOL),更多的信息可以查看 CentOS 官方公告。如果需要更新 CentOS,需要将镜像从 mirror.centos.org 更改为 vault.centos.org
解决
1.进入到 yum 的 repos 目录
cd /etc/yum.repos.d/
2.修改文件内容
sed -i 's/mirrorlist/#mirrorlist/g' /etc/yum.repos.d/CentOS-*
sed -i 's|#baseurl=http://mirror.centos.org|baseurl=http://vault.centos.org|g' /etc/yum.repos.d/CentOS-*
3.生成缓存更新
yum makecache
4.更新yum
yum update -y
最后就可以重新安装net-tools了