[Centos系统] CentOS 7 yum无法使用解决方法Could not retrieve mirrorlist http://mirro

1118 0
Honkers 2025-3-6 04:27:50 | 显示全部楼层 |阅读模式

报错:

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

依次执行:

  1. cp CentOS-Base.repo CentOS-Base.repo.backup
  2. vi CentOS-Base.repo
复制代码

进入后改为:

  1. # CentOS-Base.repo
  2. #
  3. # The mirror system uses the connecting IP address of the client and the
  4. # update status of each mirror to pick mirrors that are updated to and
  5. # geographically close to the client. You should use this for CentOS updates
  6. # unless you are manually picking other mirrors.
  7. #
  8. # If the mirrorlist= does not work for you, as a fall back you can try the
  9. # remarked out baseurl= line instead.
  10. #
  11. #
  12. [base]
  13. name=CentOS-$releasever - Base
  14. #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os&infra=$infra
  15. #baseurl=http://mirror.centos.org/centos/$releasever/os/$basearch/
  16. #baseurl=http://vault.centos.org/7.9.2009/x86_64/os/
  17. baseurl=http://vault.centos.org/7.9.2009/os/$basearch/
  18. gpgcheck=1
  19. gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
  20. #released updates
  21. [updates]
  22. name=CentOS-$releasever - Updates
  23. #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates&infra=$infra
  24. #baseurl=http://mirror.centos.org/centos/$releasever/updates/$basearch/
  25. #baseurl=http://vault.centos.org/7.9.2009/x86_64/os/
  26. baseurl=http://vault.centos.org/7.9.2009/updates/$basearch/
  27. gpgcheck=1
  28. gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
  29. #additional packages that may be useful
  30. [extras]
  31. name=CentOS-$releasever - Extras
  32. #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras&infra=$infra
  33. #$baseurl=http://mirror.centos.org/centos/$releasever/extras/$basearch/
  34. #baseurl=http://vault.centos.org/7.9.2009/x86_64/os/
  35. baseurl=http://vault.centos.org/7.9.2009/extras/$basearch/
  36. gpgcheck=1
  37. gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
  38. #additional packages that extend functionality of existing packages
  39. [centosplus]
  40. name=CentOS-$releasever - Plus
  41. #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus&infra=$infra
  42. #baseurl=http://mirror.centos.org/centos/$releasever/centosplus/$basearch/
  43. #baseurl=http://vault.centos.org/7.9.2009/x86_64/os/
  44. baseurl=http://vault.centos.org/7.9.2009/centosplus/$basearch/
  45. gpgcheck=1
  46. enabled=0
  47. gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
复制代码

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

  1. sudo yum clean all
  2. sudo yum makecache
复制代码

阿里云镜像源

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

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

执行

  1. cat CentOS-Base.repo
复制代码

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

  1. sudo yum clean all
  2. sudo yum makecache
复制代码

 

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

×
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

中国红客联盟公众号

联系站长QQ:5520533

admin@chnhonker.com
Copyright © 2001-2026 Discuz Team. Powered by Discuz! X3.5 ( 粤ICP备13060014号 )|天天打卡 本站已运行