Loading mirror speeds from cached hostfile
Could not retrieve mirrorlist http://mirrorlist.centos.org/?release=7&arch=x86_64&repo=os&infra=stock error was
14: curl#6 - "Could not resolve host: mirrorlist.centos.org; 未知的错误"
问题原因
之所以会出现这种错误,是因为 CentOS 7 的相关仓库已被归档处理,当前使用的镜像地址无法获取到所需文件。要知道,CentOS 7 的官方支持早已终止,其部分仓库也随之被转移到了归档库中。特别是在 2024 年 6 月 30 日之后,CentOS 7 的官方仓库就停止了维护,这也使得使用最新的 CentOS 7 官方仓库时,很容易出现类似无法找到元数据文件的问题,进而导致 yum 命令无法正常执行。
解决方法
进入/etc/yum.repos.d目录下找到 CentOS-Base.repo
进入目录:
cd /etc/yum.repos.d
cp CentOS-Base.repo CentOS-Base.repo.backup
vi CentOS-Base.repo #替换为以下内容
[base]
name=CentOS-$releasever - Base
baseurl=http://vault.centos.org/7.9.2009/os/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
[updates]
name=CentOS-$releasever - Updates
baseurl=http://vault.centos.org/7.9.2009/updates/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
[extras]
name=CentOS-$releasever - Extras
baseurl=http://vault.centos.org/7.9.2009/extras/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
[centosplus]
name=CentOS-$releasever - Plus
baseurl=http://vault.centos.org/7.9.2009/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
然后ESC 冒号:wq保存下,依次执行:
sudo yum clean all
sudo yum makecache
阿里云镜像源
以下两个命令都可以,执行完成后进入/etc/yum.repos.d
wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
然后执行:
cat CentOS-Base.repo
wget没有则先进行下载:yum install wget
然后执行:
sudo yum clean all
sudo yum makecache