解决 CentOS 7 官方 yum 仓库无法使用的方法

解决 CentOS 7 官方 yum 仓库无法使用的方法

2024 年 7 月 1 日,在编译基于 CentOS 7.6.1810 镜像的 Dockerfile 过程中,执行 yum install 指令时,遇到了错误:Could not resolve host: mirrorlist.centos.org; Unknown error

在做更新 yum -y update 时,遇到Could not retrieve mirrorlist http://mirrorlist.centos.org?arch=x86_64&release=7&repo=sclo-rh error was
14: curl#6 – “Could not resolve host: mirrorlist.centos.org; Unknown error”

原因: 2024 年 7 月 1 日 官方停止维护 CentOS 7。该系统内置的 yum.repo 所使用的域名 mirrorlist.centos.org 已不再提供 A 记录。

解决 CentOS 7 官方 yum 仓库无法使用的方法
dig mirrorlist.centos.org +trace
解决 CentOS 7 官方 yum 仓库无法使用的方法

解决方案:

最佳方案 – 更新及启用 CentOS-Vault.repo 存档仓库

CentOS-Vault.repo 是 CentOS 发行版中自带的一个 YUM 软件仓库。它定义了一系列旧版本的软件包和更新,这些软件包和更新不再由 CentOS 项目的主要仓库维护。当 CentOS 发布新的版本(例如,从 CentOS 7.4 升级到 CentOS 7.5)时,旧版本的软件包通常会被移动到 Vault 仓库中。vault.centos.org 是 CentOS-Vault.repo 关联的仓库站点,因此,启用 CentOS-Vault.repo 并将仓库站点配置为 vault.centos.org 是 CentOS 内置的处理预案及最佳方案。

配置操作:

# 文件路径 /etc/yum.repos.d/CentOS-Vault.repo
# Vault
[Vault-base]
name=Vault - CentOS-$releasever - Base
baseurl=http://vault.centos.org/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-$releasever

[Vault-updates]
name=Vault - CentOS-$releasever - Updates
baseurl=http://vault.centos.org/centos/$releasever/updates/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-$releasever

[Vault-extras]
name=Vault - CentOS-$releasever - Extras
baseurl=http://vault.centos.org/centos/$releasever/extras/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-$releasever

使用 enabled=0 禁用 CentOS-Base.repo 中的所有仓库,修改后配置如下:

[base]
name=CentOS-$releasever - Base
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os&infra=$infra
#baseurl=http://mirror.centos.org/centos/$releasever/os/$basearch/
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

# 下同

清除 YUM 缓存,如有需要可再生成新的缓存

yum clean all
yum makecache

验证:

[root@93b1bbdc2e60 /]# yum repolist
Loaded plugins: fastestmirror, ovl
Loading mirror speeds from cached hostfile
repo id                                                                  repo name                                                                    status
!Vault-base/7/x86_64                                                     Vault - CentOS-7 - Base                                                      10,072
!Vault-extras/7/x86_64                                                   Vault - CentOS-7 - Extras                                                       526
!Vault-updates/7/x86_64                                                  Vault - CentOS-7 - Updates                                                    6,173
repolist: 16,771

临时解决方案1:

启用 *.repo 中的 baseurl,注释 mirrorlist,将 baseurl 仓库地址替换为 vault.centos.org 存档站点。

sed -i s/^#.*baseurl=http/baseurl=http/g /etc/yum.repos.d/*.repo
sed -i s/^mirrorlist=http/#mirrorlist=http/g /etc/yum.repos.d/*.repo
sed -i s/mirror.centos.org/vault.centos.org/g /etc/yum.repos.d/*.repo

清除和更新缓存。

临时解决方案2:

将 CentOS 7 基础仓库修改为阿里云仓库

cp /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/CentOS-7.repo
yum clean all ; yum makecache

原创文章,作者:Gary,如若转载,请注明出处:https://www.cpw5.top/155.html

淘宝小店:陈皮王五工作室

(0)
GaryGary
上一篇 2024-09-01 上午11:47
下一篇 2024-09-09 下午1:53

相关推荐

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注