当前位置: 首页 > news >正文

CentOS 7.x 的 YUM 仓库问题

背景

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

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


在这里插入代码片

相关文章:

  • 北京网站建设多少钱?
  • 辽宁网页制作哪家好_网站建设
  • 高端品牌网站建设_汉中网站制作
  • Poetry入门教程
  • Harmony学习(三)
  • Pandas筛选数据的10种方法
  • LVGL - RV1109 LVGL UI刷新效率优化-02
  • 洛谷 P1179 [NOIP2010 普及组] 数字统计 题解
  • Docker 相关命令
  • HarmonyOS应用开发者高级认证,Next版本发布后最新题库 - 单选题序号4
  • 【探索Linux】P.42(传输层 —— TCP面向字节流 | TCP粘包问题 | TCP异常情况 )
  • OpenWrt 为软件包和docker空间扩容
  • 【过滤器 vs 拦截器】SpringBoot中过滤器与拦截器:明智选择的艺术(如何在项目中做出明智选择)
  • html+css 实现水波纹按钮
  • TCP/IP协议(全的一b)应用层,数据链层,传输层,网络层,以及面试题
  • 披荆斩棘:Python开发者在市场低迷期快速找到工作的策略
  • C# 植物大战僵尸
  • 关于海康网络摄像头使用VLC或者Opencv拉流有延迟的问题
  • Angular6错误 Service: No provider for Renderer2
  • CSS进阶篇--用CSS开启硬件加速来提高网站性能
  • ES6之路之模块详解
  • js算法-归并排序(merge_sort)
  • Linux后台研发超实用命令总结
  • niucms就是以城市为分割单位,在上面 小区/乡村/同城论坛+58+团购
  • Octave 入门
  • Rancher如何对接Ceph-RBD块存储
  • SOFAMosn配置模型
  • WinRAR存在严重的安全漏洞影响5亿用户
  • 动态规划入门(以爬楼梯为例)
  • 什么是Javascript函数节流?
  • 实现简单的正则表达式引擎
  • 携程小程序初体验
  • 新版博客前端前瞻
  • 一些关于Rust在2019年的思考
  • 正则表达式
  • 浅谈sql中的in与not in,exists与not exists的区别
  • !$boo在php中什么意思,php前戏
  • ###C语言程序设计-----C语言学习(3)#
  • #Linux(权限管理)
  • #pragma once
  • (13)Latex:基于ΤΕΧ的自动排版系统——写论文必备
  • (4)(4.6) Triducer
  • (PWM呼吸灯)合泰开发板HT66F2390-----点灯大师
  • (pycharm)安装python库函数Matplotlib步骤
  • (附源码)php新闻发布平台 毕业设计 141646
  • (附源码)springboot“微印象”在线打印预约系统 毕业设计 061642
  • (附源码)springboot太原学院贫困生申请管理系统 毕业设计 101517
  • (三)终结任务
  • (算法)硬币问题
  • (转)自己动手搭建Nginx+memcache+xdebug+php运行环境绿色版 For windows版
  • .aanva
  • .MyFile@waifu.club.wis.mkp勒索病毒数据怎么处理|数据解密恢复
  • .NET 5种线程安全集合
  • .net core控制台应用程序初识
  • .NET/C# 解压 Zip 文件时出现异常:System.IO.InvalidDataException: 找不到中央目录结尾记录。
  • .Net7 环境安装配置
  • @vue-office/excel 解决移动端预览excel文件触发软键盘
  • [2021 蓝帽杯] One Pointer PHP