CentOS 7.x 的 YUM 仓库问题

embedded/2024/10/22 14:31:30/

背景

CentOS Linux 7 的生命周期(EOL)已经于 2024 年 6 月 30 日终止这意味着 CentOS 7.x 的官方镜像站点将不再提供服务,导致在使用 yum 安装或更新程序时可能会遇到 错误。本文将介绍如何解决这一问题,使得你可以继续在 CentOS 7.x 系统上使用 yum 进行软件包管理。

问题描述

在尝试使用 yum 进行更新或安装软件包时,可能会遇到如下错误信息:

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"
...
Cannot find a valid baseurl for repo: centos-sclo-rh/x86_64

解决步骤

使用centos-vault作为停止支持的CentOS的yum源, 国内还有很多centos镜像网站,例如,阿里云,清华源、中科大、上海交大、电子科大源等等。
系统版本可以通过执行cat /etc/redhat-release命令查看,我的系统是CentOS 7.9.2009
在这里插入图片描述

决定选用清华源镜像, 官方说明文档: https://mirrors.tuna.tsinghua.edu.cn/help/centos-vault
为了修复上述问题,我们需要将 CentOS 7.x 的仓库配置指向新的镜像源 vault.centos.org

1. 清空现有的 CentOS-Base.repo 文件

首先,我们需要清空当前的 CentOS-Base.repo 文件,以便进行新的配置:

echo > /etc/yum.repos.d/CentOS-Base.repo
2. 编辑 CentOS-Base.repo 文件

接下来,打开 CentOS-Base.repo 文件并将新的仓库配置粘贴到文件中

sudo vim /etc/yum.repos.d/CentOS-Base.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-7 - Base - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/7/os/$basearch/http://mirrors.aliyuncs.com/centos/7/os/$basearch/http://mirrors.cloud.aliyuncs.com/centos/7/os/$basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7#released updates
[updates]
name=CentOS-7 - Updates - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/7/updates/$basearch/http://mirrors.aliyuncs.com/centos/7/updates/$basearch/http://mirrors.cloud.aliyuncs.com/centos/7/updates/$basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7#additional packages that may be useful
[extras]
name=CentOS-7 - Extras - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/7/extras/$basearch/http://mirrors.aliyuncs.com/centos/7/extras/$basearch/http://mirrors.cloud.aliyuncs.com/centos/7/extras/$basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-7 - Plus - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/7/centosplus/$basearch/http://mirrors.aliyuncs.com/centos/7/centosplus/$basearch/http://mirrors.cloud.aliyuncs.com/centos/7/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7#contrib - packages by Centos Users
[contrib]
name=CentOS-7 - Contrib - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/7/contrib/$basearch/http://mirrors.aliyuncs.com/centos/7/contrib/$basearch/http://mirrors.cloud.aliyuncs.com/centos/7/contrib/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
3. 删除其他无关的 .repo 文件

为了避免冲突,只保留 CentOS-Base.repo 文件,其它无关的 .repo 文件可以删除:

cd /etc/yum.repos.d/
ls | grep -v 'CentOS-Base.repo' | xargs rm
4. 重建 yum 缓存

最后,清理 yum 缓存并重新生成缓存,以确保新的配置生效:

sudo yum clean all
sudo yum makecache

结果

通过以上步骤,你应该能够成功地将 CentOS 7.x 的 YUM 仓库指向新的镜像源 vault.centos.org,并且可以继续使用 yum 进行软件包的安装和更新。

注意事项

  • 安全性:CentOS 7.x 已经不再受官方支持,建议尽快迁移到新的操作系统,这样才能继续获得安全更新、补丁和新功能。
  • 备份:在修改仓库配置文件之前,最好备份原有的配置文件,以便在需要时可以恢复。

希望这些信息对你有所帮助。如果你有任何问题或需要进一步的帮助,如果有任何调整或补充,欢迎告知!


在这里插入代码片

http://www.ppmy.cn/embedded/87421.html

相关文章

网络安全Sirius

关于Sirius Sirius是一款功能强大的通用漏洞扫描工具,该工具可以帮助广大研究人员在大多数场景下识别和验证应用程序中存在的安全漏洞。 现如今,信息安全社区仍然是收集网络安全情报数据最佳且最有利的来源,而且社区本身的表现经常会优于商…

Cocos Creator文档学习记录

Cocos Creator文档学习记录 一、什么是Cocos Creator 官方文档链接:Hello World | Cocos Creator 百度百科:Cocos Creator_百度百科 Cocos Creator包括开发和调试、商业化 SDK 的集成、多平台发布、测试、上线这一整套工作流程,可多次的迭…

JAVA学习笔记——第七章 面向对象中级(一)

🔥博客主页: A_SHOWY🎥系列专栏:力扣刷题总结录 数据结构 云计算 数字图像处理 力扣每日一题_ 1.关于IDEA 1.1 IDEA目录 Idea的项目编译后,其class文件会存在out文件重,src存放源文件。 1.2 快捷键 …

【解决方案】华普微汽车智能钥匙解决方案

一、方案概述 1.什么是被动式无钥匙进入 "被动式无钥匙进入"(Passive Keyless Entry)是一种用于车辆、建筑物或其他设施的访问控制系统。它利用无线射频技术自动判断用户是否接近,并进行身份识别以执行开锁或落锁动作&#xff0c…

学习008-02-04-08 Localize UI Elements(本地化UI元素)

Localize UI Elements(本地化UI元素) This lesson explains how to localize an XAF application. It describes how to translate UI elements into German and create a multi-language application. 本课介绍如何本地化XAF应用程序。它描述了如何将U…

Redis 序列化 GenericJackson2JsonRedisSerializer和Jackson2JsonRedisSerializer的区别

GenericJackson2JsonRedisSerializer 和 Jackson2JsonRedisSerializer 是 Spring Data Redis 提供的两种基于 Jackson 的 Redis 序列化器。 它们的主要区别在于序列化和反序列化的方式以及适用的场景。 GenericJackson2JsonRedisSerializer 序列化方式:在序列化对…

运维-6-采用LPG搭建轻量级日志收集系统

参考Grafana 安装配置教程 1 Grafana Grafana是一个通用的可视化工具。对于Grafana而言,Prometheus这类为其提供数据的对象均称为数据源(Data Source)。目前,Grafana官方提供了对:Graphite, InfluxDB, OpenTSDB, tde…

构建稳固与安全的网络环境:从微软蓝屏事件中的教训学习

近日,一场由微软视窗系统软件更新引发的全球性“微软蓝屏”事件震惊了整个科技界。这次事件不仅暴露了现代IT基础设施在面对大规模软件缺陷时的脆弱性,也引发了对网络安全与系统稳定性的深刻思考。在本文中,我们将探讨这次事件的根源、影响以…