在centos7中使用yum命令时候报错:

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

问题原因

出现这个错误是因为使用的 CentOS 7 仓库已经被归档,当前的镜像地址无法找到所需的文件。CentOS 7 的官方支持已经结束,部分仓库已被移至归档库。这导致了你的 yum 命令无法找到所需的元数据文件。CentOS 7 的官方仓库在 2024 年 6 月 30 日之后已经停止维护。因此,使用最新的 CentOS 7 官方仓库可能会遇到问题。

解决方法

进入/etc/yum.repos.d目录下找到 CentOS-Base.repo

进入目录:

cd /etc/yum.repos.d



之后依次执行:

cp  CentOS-Base.repo   CentOS-Base.repo.backup
vi 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-$releasever - Base
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os&infra=$infra
#baseurl=http://mirror.centos.org/centos/$releasever/os/$basearch/
#baseurl=http://vault.centos.org/7.9.2009/x86_64/os/
baseurl=http://vault.centos.org/7.9.2009/os/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7 #released updates
[updates]
name=CentOS-$releasever - Updates
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates&infra=$infra
#baseurl=http://mirror.centos.org/centos/$releasever/updates/$basearch/
#baseurl=http://vault.centos.org/7.9.2009/x86_64/os/
baseurl=http://vault.centos.org/7.9.2009/updates/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7 #additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras&infra=$infra
#$baseurl=http://mirror.centos.org/centos/$releasever/extras/$basearch/
#baseurl=http://vault.centos.org/7.9.2009/x86_64/os/
baseurl=http://vault.centos.org/7.9.2009/extras/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7 #additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever - Plus
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus&infra=$infra
#baseurl=http://mirror.centos.org/centos/$releasever/centosplus/$basearch/
#baseurl=http://vault.centos.org/7.9.2009/x86_64/os/
baseurl=http://vault.centos.org/7.9.2009/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

然后wq保存下,依次执行:

sudo yum clean all
sudo yum makecache

之后等待加载:

阿里云镜像源

以下两个命令都可以,执行完成后进入/etc/yum.repos.d

curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo

然后执行:

 cat CentOS-Base.repo



看着镜像是阿里云的即可。 建议在执行下

sudo yum clean all
sudo yum makecache

欢迎关注公众号:愚生浅末

CentOS 7 yum无法使用解决方法Could not retrieve mirrorlist http://mirrorlist.centos.org/?release=7&arch=的更多相关文章

  1. VMware虚拟机的CentOS无法上网的解决方法

    前言:由于Linux下很多软件安装必须网络环境下进行,因此,对于如何在VMware下进行上网,我折腾了至少三天,今天上午,也即五一劳动节,终于搜到一遍技术文章,经过自己实践,VMware下Linux的 ...

  2. 树莓派(Raspberry Pi 3)安装centos7后yum无法使用解决办法

    树莓派(Raspberry Pi 3)安装centos7后yum无法使用解决办法 人穷,闲鱼淘了个二手的树莓派3 英国版,无奈咱也不会用,很无奈~ 安装教程百度到的差不多都可以,找个格式正常的一步一步 ...

  3. 001. 使用ssh连接不上centos 6.5的解决方法及其解决中文乱码

    1. 使用ssh连接不上centos 6.5的解决方法: 错误显示: Connecting to 192.168.1.106:22... Could not connect to '192.168.1 ...

  4. CentOS 大量的TIME_WAIT解决方法

    CentOS 大量的TIME_WAIT解决方法 最近个人博客总是出现无法打开的现象,具体表现为,打开页面需要等待n长时间,登陆系统后发现系统存在大量TIME_WAIT状态的连接,google了一下解决 ...

  5. VMware workstation虚拟机配置文件不兼容无法使用解决方法

    VMware workstation虚拟机配置文件不兼容无法使用解决方法打开VMware workstation虚拟机提示:配置文件"--.vmx"是由Vmware产品创建,但该产 ...

  6. centos在yum install报错:Another app is currently holding the yum lock解决方法

    centos在yum install报错:Another app is currently holding the yum lock,这个问题可能是很多的新手经常遇到问题,之前也有人问我,包括本人在刚 ...

  7. yum出现“No module named yum”错误解决方法

    安装了一个Python2.7,隔天发现yum无法使用,报错信息如下,应该是系统是使用的默认的python2.6的版本 解决办法修改yum文件#vi /usr/bin/yum将 #!/usr/bin/p ...

  8. centos 更换yum源 (解决下载慢的问题)

    先看有没有安装wget         wget -V 如果没有执行   yum -y install wget    进行安装 然后进行配置的备份 mv /etc/yum.repos.d/CentO ...

  9. Another app is currently holding the yum lock解决方法

    用yum安装包有时候会提示 ``` Another app is currently holding the yum lock; waiting for it to exit...   The oth ...

  10. mac os ssh远程链接centos提示证书错误解决方法

    下面是错误提示 IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY! Someone could be eavesdropping on you ...

随机推荐

  1. npm基本操作手册

    查看npm版本 npm -v 设置仓库地址 # 默认仓库地址 npm config set registry https://registry.npmjs.org/ # 淘宝镜像地址 npm conf ...

  2. Java int/int 保留2位小数

    @Test public void txfloat() { // TODO 自动生成的方法存根 int a=9; int b=7; DecimalFormat df=new DecimalFormat ...

  3. BootStrap Table 添加序列号

    js $('#table').bootstrapTable({ striped: true,//隔行换色 columns: [ { field: '', title: '序号', sortable: ...

  4. SpringSecurity安全管理

    SpringSecurity安全管理 一.安全简介 在 Web 开发中,安全一直是非常重要的一个方面,因此从应用开发的第一天就应该把安全相关的因素考虑进来,并在整个应用的开发过程中. 主要安全框架:S ...

  5. 使用requests库实现http请求

    1.发送请求 import requests url = 'http://www.tipdm.com/tipdm/index.html' rqq = requests.get(url) In [ ]: ...

  6. Unity无法安装Entities 1.2.0 Package的解决方法

    会出现如下的错误提示: 本质原因是国内版的Unity使用了自己的Package加速CDN:packages.unity.cn,而不是官方的packages.unity.com.而这个CDN更新了Ent ...

  7. C#:SqlSugar中时间戳(TimeStamp)的使用

    1.数据库建表 CREATE TABLE dbo.Test ( tId INT IDENTITY NOT NULL , tName NVARCHAR (20) NOT NULL , tSalary D ...

  8. 公共的网络云盘的存储真的安全吗?—— 百度云盘上的PDF文件无故被改名

    在百度云盘上上传了一个PDF文件,内容: 本来是没有啥问题的,但是今天使用百度云盘发现这个PDF文件居然被改名,被取消掉了扩展名: 简直是离谱离了一个大谱,太可怕了,看来这种公共云盘真的不太靠谱,虽然 ...

  9. Ubuntu18.04下 修改conda环境和缓存默认路径

    查看conda 的默认环境和缓存默认路径:conda info  conda环境和缓存的默认路径(envs directories 和 package cache) envs directories  ...

  10. ubuntu18.04 安装wine64出现错误: X 64-bit development files not found.

    ubuntu18.04 编译源码方式安装  wine6.11 ,   报错: 缺少依赖,解决方法如下: sudo apt install xserver-xorg-dev 参考: https://bl ...