CentOS修改yum.repos.d源,避免“Could not resolve host: mirrorlist.centos.org”错误

1、问题现象

由于CentOS停止维护,mirrorlist.centos.org网站也关闭不可访问。导致CentOS默认配置的yum.repos.d源也不可用,所以执行yum命令会报"Could not resolve host: mirrorlist.centos.org"错误。具体如下:

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; 未知的错误"

One of the configured repositories failed (未知),

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).

  1. Run the command with the repository temporarily disabled

yum --disablerepo=<repoid> ...

  1. 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>

  1. 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

二、解决办法

通过一下命令,使用新文件替换CentOS原有的CentOS-Base.repo文件,。

bash 复制代码
#先备份原来的CentOS-Base.repo文件
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo_old

#从阿里云下载新文件,替代CentOS-Base.repo
curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo

#重建yum元数据缓存(大约需1分钟)
yum makecache

以上完成后,yum命令即可正常使用。

相关推荐
wanhengidc21 分钟前
云手机 网络连接与持续性的表现如何
运维·服务器·科技·游戏·智能手机
小猿成长23 分钟前
Ubuntu搭建物联网平台(ThingsBoard)教程
linux·运维·ubuntu
代码不行的搬运工27 分钟前
RFC6811:BGP前缀源验证
运维·服务器·bgp网络
Archie_IT28 分钟前
openEuler 软件生态深度勘探:从六万软件包到多语言融合
linux·容器·性能测试·openeuler·多语言开发
tokepson2 小时前
香橙派AI Pro个人云平台 - 从零搭建全记录
linux·服务器·技术·记录
月亮!2 小时前
移动端测试重磅升级:跨平台自动化测试框架深度对比
运维·网络·人工智能·测试工具·容器·自动化·测试用例
fengyehongWorld2 小时前
Linux wget命令
linux
凯子坚持 c2 小时前
Docker 容器全生命周期管理与运维命令深度解析
运维·docker·php
fpcc3 小时前
跟我学C++中级篇——Linux系统信号分析
linux
楼田莉子3 小时前
基于Linux的个人制作的文件库+标准输出和标准错误
linux·c语言·c++·学习·vim