文章目录
一、遇到问题
刚安装的CentOS 8
服务器,在使用一些常见命令时,发现找不到这些命令,然后使用yum
在线安装这些命令时报错:【错误:为仓库 ‘appstream’ 下载元数据失败 : Cannot prepare internal mirrorlist: No URLs in mirrorlist】
[root@Chen ~]# ifconfig
-bash: ifconfig: 未找到命令
[root@Chen ~]# wget
-bash: wget: 未找到命令
[root@Chen ~]# vim test.txt
-bash: vim: 未找到命令
[root@Chen ~]# yum -y install net-tools
CentOS Linux 8 - AppStream 15 B/s | 38 B 00:02
错误:为仓库 'appstream' 下载元数据失败 : Cannot prepare internal mirrorlist: No URLs in mirrorlist
[root@Chen ~]# yum list
CentOS Linux 8 - AppStream 79 B/s | 38 B 00:00
错误:为仓库 'appstream' 下载元数据失败 : Cannot prepare internal mirrorlist: No URLs in mirrorlist
二、原因分析
在网上查阅资料得知,CentOS Linux 8
版本的操作系统在 2021-12-31 就结束了生命周期(EOL),Linux 社区不再维护该版本的操作系统,CentOS Linux 8
的镜像及yum源一起迁移到了 https://vault.centos.org
三、解决问题
原因已经明确了,CentOS 8 的yum源失效了,那就更新下yum源呗,下边提供几个解决方案供参考。
CentOS Linux 8
的 yum
源仓库配置文件:
[root@Chen ~]# cd /etc/yum.repos.d/
[root@Chen yum.repos.d]# ls
CentOS-Linux-AppStream.repo CentOS-Linux-Devel.repo CentOS-Linux-Media.repo
CentOS-Linux-BaseOS.repo CentOS-Linux-Extras.repo CentOS-Linux-Plus.repo
CentOS-Linux-ContinuousRelease.repo CentOS-Linux-FastTrack.repo CentOS-Linux-PowerTools.repo
CentOS-Linux-Debuginfo.repo CentOS-Linux-HighAvailability.repo CentOS-Linux-Sources.repo
方案一:更新centos提供的yum源新地址
1. yum源仓库配置文件内容
先来看下源文件内容(删掉了一些注释),以CentOS-Linux-BaseOS.repo
为例。
[root@Chen yum.repos.d]# cat CentOS-Linux-BaseOS.repo
[baseos]
name=CentOS Linux $releasever - BaseOS
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=BaseOS&infra=$infra
#baseurl=http://mirror.centos.org/$contentdir/$releasever/BaseOS/$basearch/os/
gpgcheck=1
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
2. 更新yum源新地址
将 CentOS-Linux-*.repo
所有文件内容做如下修改:
1)注释掉 "mirrorlist=..."
配置内容
2)取消 "baseurl=..."
的注释,同时将 mirror.centos.org
替换为 vault.centos.org
执行如下命令,完成上述修改
[root@Chen yum.repos.d]# sed -i -e "s/mirrorlist=/#mirrorlist=/g" /etc/yum.repos.d/CentOS-Linux-*.repo
[root@Chen yum.repos.d]# sed -i -e "s|#baseurl=http://mirror.centos.org|baseurl=http://vault.centos.org|g" /etc/yum.repos.d/CentOS-Linux-*.repo
[root@Chen yum.repos.d]# cat CentOS-Linux-BaseOS.repo
[baseos]
name=CentOS Linux $releasever - BaseOS
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=BaseOS&infra=$infra
baseurl=http://vault.centos.org/$contentdir/$releasever/BaseOS/$basearch/os/
gpgcheck=1
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
3. 测试yum安装命令
[root@Chen yum.repos.d]# yum -y install net-tools
CentOS Linux 8 - AppStream 3.1 MB/s | 8.4 MB 00:02
CentOS Linux 8 - BaseOS 2.6 MB/s | 4.6 MB 00:01
CentOS Linux 8 - Extras 11 kB/s | 10 kB 00:00
依赖关系解决。
==============================================================================================================================
软件包 架构 版本 仓库 大小
=========================================================