解决Centos7系统更新时报错:Could not resolve host: mirrorlist.centos.org; 未知的错误

1、背景

centos7系统在执行:sudo yum update,发生错误;

1.1、错误描述

root@localhost \~# sudo yum update

已加载插件:fastestmirror, langpacks 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; 未知的错误"

2、原因分析

原因是国内网络不能访问外网,所以需要将mirrorlist.centos.org替换为国内可以访问的镜像源。

3、解决问题

3.1、CentOS7 原生 yum 源修改为阿里 yum 源

3.1.1、备份原来的 yum 源

复制代码
sudo cp /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.back

3.1.2、下载阿里云的 yum 源文件并替换本地 yum 源文件

复制代码
sudo curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
#清理缓存
sudo yum clean all
#生成新的缓存
 sudo yum makecache
#更新yum
 sudo yum updata

3.1.3、添加 epel 源

3.1.3.1、epel源与yum源说明

epel源:(Extra Packages for Enterprise Linux) :epel是一个由Fedora项目支持的补充软件仓库,专为RHEL(Red Hat Enterprise Linux)及其衍生版如CentOS设计。它扩展了企业级Linux发行版的软件包库,提供大量不在官方库中的开源软件,增强了系统的功能性与灵活性。

yum源:(Yellowdog Updater, Modified)是Red Hat引入的包管理工具,它通过自动解决依赖关系,简化了软件的安装、更新和卸载过程。YUM源本质上是指向软件包仓库的配置信息,这些仓库包含了与特定Linux发行版(如RHEL/CentOS)兼容的官方软件包,确保了软件包的稳定性和兼容性。

3.1.3.2、查看一下系统是否已有 epel
复制代码
sudo rpm -qa |grep epel  
3.1.3.3、有则卸载

#如果有的话先用下面的命令卸载以前的 epel 以免受影响

复制代码
sudo rpm -e epel-release 
3.1.3.4、下载阿里的 epel 源
复制代码
sudo wget -P /etc/yum.repos.d/ http://mirrors.aliyun.com/repo/epel-7.repo
3.1.3.5、清洗缓存并生成新的缓存
复制代码
#清理缓存
sudo yum clean all
#生成新的缓存
sudo yum makecache
相关推荐
加油码1 分钟前
Linux 进程详解:从进程状态、调度到程序替换
linux·服务器
DeeplyMind1 分钟前
Linux 内核模块符号版本不匹配问题排查指南
linux·crc·module.symvers
小五传输2 分钟前
宏病毒查杀效率提升80%:2026年宏病毒查杀自动化方案详解
大数据·运维·安全
qq_163135755 分钟前
Linux查看组名
linux
ICT系统集成阿祥10 分钟前
SSH连接交换机慢的原因&优化方案
运维·服务器·ssh
Urbano13 分钟前
成套工装服饰生产工艺难点攻克与自动化设备应用研究
运维·自动化
烁34719 分钟前
Linux简单脚本
linux·运维·服务器
難釋懷22 分钟前
Nginx水平扩展
运维·nginx
森叶23 分钟前
Electron 多进程下的“库引入“全解析:核心模块、Electron API、第三方依赖与 utilityProcess 的依赖处理
运维·javascript·electron
hanbr26 分钟前
Linux 基础入门笔记:从零开始理解核心概念与常用操作
linux