CentOS 执行yum命令报错【错误:为仓库 ‘appstream‘ 下载元数据失败: ...】

本文介绍了在CentOS系统中遇到执行yum命令时因仓库‘appstream’元数据下载失败的错误,分析了原因(CentOS版本已结束生命周期)。提供了两种解决方案:一是更新CentOS提供的yum源新地址,二是切换到国内的阿里、网易、清华的yum源。每种方案详细说明了操作步骤,并强调了不推荐混用不同yum源,以避免潜在错误。
摘要由CSDN通过智能技术生成

一、遇到问题

刚安装的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
End of Life

三、解决问题

原因已经明确了,CentOS 8 的yum源失效了,那就更新下yum源呗,下边提供几个解决方案供参考。
CentOS Linux 8yum 源仓库配置文件:

[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
依赖关系解决。
==============================================================================================================================
 软件包                     架构                    版本                                        仓库                     大小
=======================================================
  • 62
    点赞
  • 156
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 6
    评论
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小青龍

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值