一、遇到问题
刚安装的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 源仓库配置文件:
方案一:更新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
依赖关系解决。
==============================================================================================================================
软件包 架构 版本 仓库 大小
==============================================================================================================================
安装:
net-tools x86_64 2.0-0.52.20160912git.el8 baseos 322 k
事务概要
==============================================================================================================================
安装 1 软件包
总下载:322 k
安装大小:942 k
下载软件包:
net-tools-2.0-0.52.20160912git.el8.x86_64.rpm 613 kB/s | 322 kB 00:00
——————————————————————————————————————————
总计 610 kB/s | 322 kB 00:00
CentOS Linux 8 – BaseOS 148 kB/s | 1.6 kB 00:00
导入 GPG 公钥 0x8483C65D:
Userid: “CentOS (CentOS Official Signing Key) <security@centos.org>”
指纹: 99DB 70FA E1D7 CE22 7FB6 4882 05B5 55B3 8483 C65D
来自: /etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
导入公钥成功
运行事务检查
事务检查成功。
运行事务测试
事务测试成功。
运行事务
准备中 : 1/1
安装 : net-tools-2.0-0.52.20160912git.el8.x86_64 1/1
运行脚本: net-tools-2.0-0.52.20160912git.el8.x86_64 1/1
验证 : net-tools-2.0-0.52.20160912git.el8.x86_64 1/1
已安装:
net-tools-2.0-0.52.20160912git.el8.x86_64
完毕!
验证yum命令安装软件已正常可用!
阿里的yum源:https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo
先将已有的yum源仓库配置文件备份
[root@Chen yum.repos.d]# mkdir backup && mv CentOS-Linux-*.repo backup
[root@Chen yum.repos.d]# yum install wget
错误:在”/etc/yum.repos.d”, “/etc/yum/repos.d”, “/etc/distro.repos.d”中没有被启用的仓库。
使用 wget 或 curl 命令 下载阿里的yum源仓库配置文件
wget -O /etc/yum.repos.d/CentOS-Linux-Base-ali.repo https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo
curl -o /etc/yum.repos.d/CentOS-Linux-Base-ali.repo https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo
[root@Chen yum.repos.d]# curl -o /etc/yum.repos.d/CentOS-Linux-Base-ali.repo https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 2495 100 2495 0 0 4346 0 –:–:– –:–:– –:–:– 4339
[root@Chen yum.repos.d]# ls
backup CentOS-Linux-Base-ali.repo
# CentOS-Base.repo
#
# The mirror system uses the connecting IP address of the client and the
# update status of each mirror to pick mirrors that are updated to and
# 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, as a fall back you can try the
# remarked out baseurl= line instead.
#
#
[base]
name=CentOS-8.5.2111 – Base – mirrors.aliyun.com
baseurl=http://mirrors.aliyun.com/centos-vault/8.5.2111/BaseOS/$basearch/os/
http://mirrors.aliyuncs.com/centos-vault/8.5.2111/BaseOS/$basearch/os/
http://mirrors.cloud.aliyuncs.com/centos-vault/8.5.2111/BaseOS/$basearch/os/
gpgcheck=0
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-Official
#additional packages that may be useful
[extras]
name=CentOS-8.5.2111 – Extras – mirrors.aliyun.com
baseurl=http://mirrors.aliyun.com/centos-vault/8.5.2111/extras/$basearch/os/
http://mirrors.aliyuncs.com/centos-vault/8.5.2111/extras/$basearch/os/
http://mirrors.cloud.aliyuncs.com/centos-vault/8.5.2111/extras/$basearch/os/
gpgcheck=0
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-Official
#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-8.5.2111 – Plus – mirrors.aliyun.com
baseurl=http://mirrors.aliyun.com/centos-vault/8.5.2111/centosplus/$basearch/os/
http://mirrors.aliyuncs.com/centos-vault/8.5.2111/centosplus/$basearch/os/
http://mirrors.cloud.aliyuncs.com/centos-vault/8.5.2111/centosplus/$basearch/os/
gpgcheck=0
enabled=0
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-Official
[PowerTools]
name=CentOS-8.5.2111 – PowerTools – mirrors.aliyun.com
baseurl=http://mirrors.aliyun.com/centos-vault/8.5.2111/PowerTools/$basearch/os/
http://mirrors.aliyuncs.com/centos-vault/8.5.2111/PowerTools/$basearch/os/
http://mirrors.cloud.aliyuncs.com/centos-vault/8.5.2111/PowerTools/$basearch/os/
gpgcheck=0
enabled=0
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-Official
[AppStream]
name=CentOS-8.5.2111 – AppStream – mirrors.aliyun.com
baseurl=http://mirrors.aliyun.com/centos-vault/8.5.2111/AppStream/$basearch/os/
http://mirrors.aliyuncs.com/centos-vault/8.5.2111/AppStream/$basearch/os/
http://mirrors.cloud.aliyuncs.com/centos-vault/8.5.2111/AppStream/$basearch/os/
gpgcheck=0
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-Official
CentOS 执行yum命令报错【错误:为仓库 ‘appstream‘ 下载元数据失败: …】_小青龍的博客-CSDN博客
原创文章,作者:奋斗,如若转载,请注明出处:https://blog.ytso.com/306684.html