刚安装的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-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
将 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
[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) "
指纹: 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源仓库配置文件备份
[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"中没有被启用的仓库。
1)使用 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
(我的Linux系统,wget命令不可用,我用curl)
[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
2)验证yum安装命令
[root@Chen yum.repos.d]# yum -y install wget
CentOS-8.5.2111 - Base - mirrors.aliyun.com 39 kB/s | 3.9 kB 00:00
CentOS-8.5.2111 - Extras - mirrors.aliyun.com 20 kB/s | 1.5 kB 00:00
CentOS-8.5.2111 - AppStream - mirrors.aliyun.com 31 kB/s | 4.3 kB 00:00
依赖关系解决。
==============================================================================================================================
软件包 架构 版本 仓库 大小
==============================================================================================================================
安装:
wget x86_64 1.19.5-10.el8 AppStream 734 k
安装依赖关系:
libmetalink x86_64 0.1.3-7.el8 base 32 k
事务概要
==============================================================================================================================
安装 2 软件包
总下载:766 k
安装大小:2.8 M
下载软件包:
(1/2): libmetalink-0.1.3-7.el8.x86_64.rpm 181 kB/s | 32 kB 00:00
(2/2): wget-1.19.5-10.el8.x86_64.rpm 2.5 MB/s | 734 kB 00:00
------------------------------------------------------------------------------------------------------------------------------
总计 2.6 MB/s | 766 kB 00:00
运行事务检查
事务检查成功。
运行事务测试
事务测试成功。
运行事务
准备中 : 1/1
安装 : libmetalink-0.1.3-7.el8.x86_64 1/2
安装 : wget-1.19.5-10.el8.x86_64 2/2
运行脚本: wget-1.19.5-10.el8.x86_64 2/2
验证 : libmetalink-0.1.3-7.el8.x86_64 1/2
验证 : wget-1.19.5-10.el8.x86_64 2/2
已安装:
libmetalink-0.1.3-7.el8.x86_64 wget-1.19.5-10.el8.x86_64
完毕!
1)新建一个 CentOS-Linux-Base-tsinghua.repo
文件,使用vi
命令编辑并保存如下内容:
[baseos]
name=CentOS-8.5.2111 - BaseOS - mirrors.163.com
baseurl=http://mirrors.163.com/centos-vault/8.5.2111/BaseOS/$basearch/os/
gpgcheck=0
gpgkey=http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-Official
#additional packages that may be useful
[extras]
name=CentOS-8.5.2111 - Extras - mirrors.163.com
baseurl=http://mirrors.163.com/centos-vault/8.5.2111/extras/$basearch/os/
gpgcheck=0
gpgkey=http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-Official
#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-8.5.2111 - Plus - mirrors.163.com
baseurl=http://mirrors.163.com/centos-vault/8.5.2111/centosplus/$basearch/os/
gpgcheck=0
enabled=0
gpgkey=http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-Official
[PowerTools]
name=CentOS-8.5.2111 - PowerTools - mirrors.163.com
baseurl=http://mirrors.163.com/centos-vault/8.5.2111/PowerTools/$basearch/os/
gpgcheck=0
enabled=0
gpgkey=http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-Official
[AppStream]
name=CentOS-8.5.2111 - AppStream - mirrors.163.com
baseurl=http://mirrors.163.com/centos-vault/8.5.2111/AppStream/$basearch/os/
gpgcheck=0
gpgkey=http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-Official
2)测试网易163的yum源
注意:在测试163的yum源之前,先把之前的阿里yum源仓库配置文件移动到backup目录
[root@Chen yum.repos.d]# mv CentOS-Linux-Base-ali.repo backup
[root@Chen yum.repos.d]# yum -y install tree
CentOS-8.5.2111 - BaseOS - mirrors.163.com 252 kB/s | 4.6 MB 00:18
CentOS-8.5.2111 - Extras - mirrors.163.com 27 kB/s | 10 kB 00:00
CentOS-8.5.2111 - AppStream - mirrors.163.com 131 kB/s | 8.4 MB 01:06
依赖关系解决。
==============================================================================================================================
软件包 架构 版本 仓库 大小
==============================================================================================================================
安装:
tree x86_64 1.7.0-15.el8 baseos 59 k
事务概要
==============================================================================================================================
安装 1 软件包
总下载:59 k
安装大小:109 k
下载软件包:
tree-1.7.0-15.el8.x86_64.rpm 59 kB/s | 59 kB 00:01
------------------------------------------------------------------------------------------------------------------------------
总计 59 kB/s | 59 kB 00:01
运行事务检查
事务检查成功。
运行事务测试
事务测试成功。
运行事务
准备中 : 1/1
安装 : tree-1.7.0-15.el8.x86_64 1/1
运行脚本: tree-1.7.0-15.el8.x86_64 1/1
验证 : tree-1.7.0-15.el8.x86_64 1/1
已安装:
tree-1.7.0-15.el8.x86_64
完毕!
1)新建一个 CentOS-Linux-Base-tsinghua.repo
文件,使用vi
命令编辑并保存如下内容:
[baseos]
name=CentOS-8.5.2111 - BaseOS - mirrors.tuna.tsinghua.edu.cn
baseurl=http://mirrors.tuna.tsinghua.edu.cn/centos-vault/8.5.2111/BaseOS/$basearch/os/
gpgcheck=0
gpgkey=http://mirrors.tuna.tsinghua.edu.cn/centos/RPM-GPG-KEY-CentOS-Official
#additional packages that may be useful
[extras]
name=CentOS-8.5.2111 - Extras - mirrors.tuna.tsinghua.edu.cn
baseurl=http://mirrors.tuna.tsinghua.edu.cn/centos-vault/8.5.2111/extras/$basearch/os/
gpgcheck=0
gpgkey=http://mirrors.tuna.tsinghua.edu.cn/centos/RPM-GPG-KEY-CentOS-Official
[AppStream]
name=CentOS-8.5.2111 - AppStream - mirrors.tuna.tsinghua.edu.cn
baseurl=http://mirrors.tuna.tsinghua.edu.cn/centos-vault/8.5.2111/AppStream/$basearch/os/
gpgcheck=0
gpgkey=http://mirrors.tuna.tsinghua.edu.cn/centos/RPM-GPG-KEY-CentOS-Official
[PowerTools]
name=CentOS-8.5.2111 - PowerTools - mirrors.tuna.tsinghua.edu.cn
baseurl=http://mirrors.tuna.tsinghua.edu.cn/centos-vault/8.5.2111/PowerTools/$basearch/os/
gpgcheck=0
enabled=0
gpgkey=http://mirrors.tuna.tsinghua.edu.cn/centos/RPM-GPG-KEY-CentOS-Official
2)测试清华的yum源
注意:在测试清华的yum源之前,先把之前的163的yum源仓库配置文件移动到backup目录
[root@Chen yum.repos.d]# mv CentOS-Linux-Base-163.repo backup
[root@Chen yum.repos.d]# vim
-bash: vim: 未找到命令
[root@Chen yum.repos.d]# yum -y install vim
CentOS-8.5.2111 - BaseOS - mirrors.tuna.tsinghua.edu.cn 5.3 MB/s | 4.6 MB 00:00
CentOS-8.5.2111 - Extras - mirrors.tuna.tsinghua.edu.cn 21 kB/s | 10 kB 00:00
CentOS-8.5.2111 - AppStream - mirrors.tuna.tsinghua.edu.cn 6.3 MB/s | 8.4 MB 00:01
依赖关系解决。
==============================================================================================================================
软件包 架构 版本 仓库 大小
==============================================================================================================================
安装:
vim-enhanced x86_64 2:8.0.1763-16.el8 AppStream 1.4 M
安装依赖关系:
gpm-libs x86_64 1.20.7-17.el8 AppStream 39 k
vim-common x86_64 2:8.0.1763-16.el8 AppStream 6.3 M
vim-filesystem noarch 2:8.0.1763-16.el8 AppStream 49 k
事务概要
==============================================================================================================================
安装 4 软件包
总下载:7.8 M
安装大小:30 M
下载软件包:
(1/4): gpm-libs-1.20.7-17.el8.x86_64.rpm 303 kB/s | 39 kB 00:00
(2/4): vim-filesystem-8.0.1763-16.el8.noarch.rpm 951 kB/s | 49 kB 00:00
(3/4): vim-enhanced-8.0.1763-16.el8.x86_64.rpm 3.0 MB/s | 1.4 MB 00:00
(4/4): vim-common-8.0.1763-16.el8.x86_64.rpm 7.2 MB/s | 6.3 MB 00:00
------------------------------------------------------------------------------------------------------------------------------
总计 8.8 MB/s | 7.8 MB 00:00
运行事务检查
事务检查成功。
运行事务测试
事务测试成功。
运行事务
准备中 : 1/1
安装 : vim-filesystem-2:8.0.1763-16.el8.noarch 1/4
安装 : vim-common-2:8.0.1763-16.el8.x86_64 2/4
安装 : gpm-libs-1.20.7-17.el8.x86_64 3/4
运行脚本: gpm-libs-1.20.7-17.el8.x86_64 3/4
安装 : vim-enhanced-2:8.0.1763-16.el8.x86_64 4/4
运行脚本: vim-enhanced-2:8.0.1763-16.el8.x86_64 4/4
运行脚本: vim-common-2:8.0.1763-16.el8.x86_64 4/4
验证 : gpm-libs-1.20.7-17.el8.x86_64 1/4
验证 : vim-common-2:8.0.1763-16.el8.x86_64 2/4
验证 : vim-enhanced-2:8.0.1763-16.el8.x86_64 3/4
验证 : vim-filesystem-2:8.0.1763-16.el8.noarch 4/4
已安装:
gpm-libs-1.20.7-17.el8.x86_64 vim-common-2:8.0.1763-16.el8.x86_64 vim-enhanced-2:8.0.1763-16.el8.x86_64
vim-filesystem-2:8.0.1763-16.el8.noarch
完毕!
mirrors.aliyun.com
为例:/etc/yum.repos.d/
中的相应文件,在 mirrorlist=
开头行前面加 #
注释掉;并将 #baseurl=
开头行取消#
注释mirror.centos.org/centos/$releasever
替换为 mirrors.aliyun.com/centos-vault/$minorver
mirror.centos.org/$contentdir/$releasever
替换为 mirrors.aliyun.com/centos-vault/$minorver
$minorver
为 centos 完整版本号,如 CentOS 7 的最后一个版本为 7.9.2009,CentOS 8 的最后一个版本为 8.5.2111)# Centos 8 之前版本
# 以 CentOS 7.9.2009 为例
minorver=7.9.2009
sudo sed -e "s|^mirrorlist=|#mirrorlist=|g" \
-e "s|^#baseurl=http://mirror.centos.org/centos/\$releasever|baseurl=https://mirrors.aliyun.com/centos-vault/$minorver|g" \
-i.bak \
/etc/yum.repos.d/CentOS-*.repo
# CentOS 8 版本
# 以 CentOS 8.5.2111 为例
minorver=8.5.2111
sudo sed -e "s|^mirrorlist=|#mirrorlist=|g" \
-e "s|^#baseurl=http://mirror.centos.org/\$contentdir/\$releasever|baseurl=https://mirrors.aliyun.com/centos-vault/$minorver|g" \
-i.bak \
/etc/yum.repos.d/CentOS-*.repo
enabled=0
改为 enabled=1
,enabled
省略默认等效为 enabled=1
yum clean all
,然后如果有需要再重新更新缓存 yum makecache
[root@Chen yum.repos.d]# ls
backup CentOS-Linux-Base-163.repo CentOS-Linux-Base-tsinghua.repo
[root@Chen yum.repos.d]# yum repolist
Repository baseos is listed more than once in the configuration
Repository extras is listed more than once in the configuration
Repository AppStream is listed more than once in the configuration
Repository PowerTools is listed more than once in the configuration
仓库 id 仓库名称
AppStream CentOS-8.5.2111 - AppStream - mirrors.163.com
baseos CentOS-8.5.2111 - BaseOS - mirrors.163.com
extras CentOS-8.5.2111 - Extras - mirrors.163.com
参考资料:
https://developer.aliyun.com/mirror/centos-vault
https://mirrors.163.com/.help/centos.html
https://mirrors.tuna.tsinghua.edu.cn/help/centos-vault/
阿里镜像
网易镜像
清华镜像