CentOS原官方镜像终止服务问题
大家好,我是欧阳方超,可以扫描下方二维码关注我的公众号“欧阳方超”,后续内容将在公众号首发。
1、概述
某陈年老服务器很久不用了,现在要启用了,想安装个vim结果发现yum源的地址不可用了,这是因为官方镜像列表 URL 已停止服务(centos7已经在2024年6月30日官方停止维护)。
[root@localhost yum.repos.d]# yum install vim
Loaded plugins: fastestmirror
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; Unknown error"
One of the configured repositories failed (Unknown),
and yum doesn't have enough cached data to continue. At this point the only
safe thing yum can do is fail. There are a few ways to work "fix" this:
1. Contact the upstream for the repository and get them to fix the problem.
2. Reconfigure the baseurl/etc. for the repository, to point to a working
upstream. This is most often useful if you are using a newer
distribution release than is supported by the repository (and the
packages for the previous distribution release still work).
3. Run the command with the repository temporarily disabled
yum --disablerepo=<repoid> ...
4. Disable the repository permanently, so yum won't use it by default. Yum
will then just ignore the repository until you permanently enable it
again or use --enablerepo for temporary usage:
yum-config-manager --disable <repoid>
or
subscription-manager repos --disable=<repoid>
5. Configure the failing repository to be skipped, if it is unavailable.
Note that yum will try to contact the repo. when it runs most commands,
so will have to try and fail each time (and thus. yum will be be much
slower). If it is a very temporary problem though, this is often a nice
compromise:
yum-config-manager --save --setopt=<repoid>.skip_if_unavailable=true
Cannot find a valid baseurl for repo: base/7/x86_64
这个错误表明,系统无法访问 CentOS 的镜像列表服务,导致无法获取软件包信息。这可能是由于官方镜像列表 URL 停止服务或者 DNS 解析问题引起的。
2、解决方案
2.1、替换baseurl
CentOS 旧版本的软件包和已不再维护的 CentOS 版本都会被存储到 http://vault.centos.org,所以只需要将 repo 文件的 baseurl 由 http://mirrorlist.centos.org 改为 http://vault.centos.org 即可,可以使用如下命令:
[root@localhost yum.repos.d]#
sed -i s/mirror.centos.org/vault.centos.org/g /etc/yum.repos.d/*.repo
/#mirrorlist=http/g /etc/yum.repos.d/*.repo[root@localhost
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
2.2、清理 YUM 缓存
为了确保新的仓库配置生效,需要清除 YUM 缓存。可以使用以下命令:
sudo yum clean all
2.3、生成新的缓存
yum makecache
2.4、使用yum安装软件
之后可以正常安装:
[root@localhost yum.repos.d]# yum install vim
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
base | 3.6 kB 00:00:00
extras | 2.9 kB 00:00:00
updates | 2.9 kB 00:00:00
(1/4): base/7/x86_64/group_gz | 153 kB 00:00:02
(2/4): extras/7/x86_64/primary_db | 253 kB 00:00:02
(3/4): base/7/x86_64/primary_db | 6.1 MB 00:00:09
(4/4): updates/7/x86_64/primary_db | 27 MB 00:00:23
Resolving Dependencies
--> Running transaction check
---> Package vim-enhanced.x86_64 2:7.4.629-8.el7_9 will be installed
--> Processing Dependency: vim-common = 2:7.4.629-8.el7_9 for package: 2:vim-enhanced-7.4.629-8.el7_9.x86_64
--> Processing Dependency: libgpm.so.2()(64bit) for package: 2:vim-enhanced-7.4.629-8.el7_9.x86_64
--> Running transaction check
---> Package gpm-libs.x86_64 0:1.20.7-6.el7 will be installed
---> Package vim-common.x86_64 2:7.4.629-8.el7_9 will be installed
--> Processing Dependency: vim-filesystem for package: 2:vim-common-7.4.629-8.el7_9.x86_64
--> Running transaction check
---> Package vim-filesystem.x86_64 2:7.4.629-8.el7_9 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
==================================================================================================================================================================
Package Arch Version Repository Size
==================================================================================================================================================================
Installing:
vim-enhanced x86_64 2:7.4.629-8.el7_9 updates 1.1 M
Installing for dependencies:
gpm-libs x86_64 1.20.7-6.el7 base 32 k
vim-common x86_64 2:7.4.629-8.el7_9 updates 5.9 M
vim-filesystem x86_64 2:7.4.629-8.el7_9 updates 11 k
Transaction Summary
==================================================================================================================================================================
Install 1 Package (+3 Dependent packages)
Total download size: 7.0 M
Installed size: 23 M
Is this ok [y/d/N]: y
Downloading packages:
warning: /var/cache/yum/x86_64/7/base/packages/gpm-libs-1.20.7-6.el7.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID f4a80eb5: NOKEYB/s | 844 kB 00:00:16 ETA
Public key for gpm-libs-1.20.7-6.el7.x86_64.rpm is not installed
(1/4): gpm-libs-1.20.7-6.el7.x86_64.rpm | 32 kB 00:00:03
Public key for vim-enhanced-7.4.629-8.el7_9.x86_64.rpm is not installed[===================- ] 664 kB/s | 2.5 MB 00:00:07 ETA
(2/4): vim-enhanced-7.4.629-8.el7_9.x86_64.rpm | 1.1 MB 00:00:03
(3/4): vim-filesystem-7.4.629-8.el7_9.x86_64.rpm | 11 kB 00:00:00
(4/4): vim-common-7.4.629-8.el7_9.x86_64.rpm | 5.9 MB 00:00:06
------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total 1.1 MB/s | 7.0 MB 00:00:06
Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
Importing GPG key 0xF4A80EB5:
Userid : "CentOS-7 Key (CentOS 7 Official Signing Key) <security@centos.org>"
Fingerprint: 6341 ab27 53d7 8a78 a7c2 7bb1 24c6 a8a7 f4a8 0eb5
Package : centos-release-7-5.1804.el7.centos.x86_64 (@anaconda)
From : /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
Is this ok [y/N]: y
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : 2:vim-filesystem-7.4.629-8.el7_9.x86_64 1/4
Installing : 2:vim-common-7.4.629-8.el7_9.x86_64 2/4
Installing : gpm-libs-1.20.7-6.el7.x86_64 3/4
Installing : 2:vim-enhanced-7.4.629-8.el7_9.x86_64 4/4
Verifying : gpm-libs-1.20.7-6.el7.x86_64 1/4
Verifying : 2:vim-enhanced-7.4.629-8.el7_9.x86_64 2/4
Verifying : 2:vim-common-7.4.629-8.el7_9.x86_64 3/4
Verifying : 2:vim-filesystem-7.4.629-8.el7_9.x86_64 4/4
Installed:
vim-enhanced.x86_64 2:7.4.629-8.el7_9
Dependency Installed:
gpm-libs.x86_64 0:1.20.7-6.el7 vim-common.x86_64 2:7.4.629-8.el7_9 vim-filesystem.x86_64 2:7.4.629-8.el7_9
Complete!
3、总结
通过以上步骤,解决了 CentOS YUM 镜像列表无法访问的问题。手动配置 YUM 仓库并使用其他可用镜像,可以确保我们能够继续管理和更新软件包。
我是欧阳方超,把事情做好了自然就有兴趣了,如果你喜欢我的文章,欢迎点赞、转发、评论加关注。我们下次见。