二维码

已解决:Cannot find a valid baseurl for repo: base/7/x86_64

11 人阅读 | 时间:2025年08月25日 10:57

使用 Yum 命令遇到此错误,下图是报错信息:

已解决:Cannot find a valid baseurl for repo: base/7/x86_64

分析:由第二行报错信息得在尝试从 CentOS 镜像列表获取信息时遇到了问题,无法解析 mirrorlist.centos.org 这个域名。这可能是由于网络连接问题导致的。


以下是解决方法:

一、首先通过 ping 命令检查网络连接,确保网络能够正常访问外网。

ping www.baidu.com运行本项目bash

 Ctrl + c 停止访问

可以正常访问的结果如下图所示:

已解决:Cannot find a valid baseurl for repo: base/7/x86_64


二、如果网络正常,问题可能是当前的镜像源出现故障或者当前网络无法访问镜像源。可以尝试更换为其他可用的镜像源。

可以通过 vi 命令编辑 /etc/yum.repos.d/CentOS-Base.repo 文件,将其中的 mirrorlist 行用 # 号注释掉,并将 baseurl 行取消注释,并修改为其他可靠的镜像地址。

vi /etc/yum.repos.d/CentOS-Base.repo运行本项目bash

如将下图四个 baseurl 地址按顺序修改为阿里云的镜像地址:

baseurl=http://mirrors.aliyun.com/centos/$releasever/os/$basearch/运行本项目bash
baseurl=http://mirrors.aliyun.com/centos/$releasever/updates/$basearch/运行本项目bash
baseurl=http://mirrors.aliyun.com/centos/$releasever/extras/$basearch/运行本项目bash
baseurl=http://mirrors.aliyun.com/centos/$releasever/centosplus/$basearch/运行本项目bash

 已解决:Cannot find a valid baseurl for repo: base/7/x86_64

# 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=$infrabaseurl=http://mirrors.aliyun.com/centos/$releasever/os/$basearch/gpgcheck=1gpgkey=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=$infrabaseurl=http://mirrors.aliyun.com/centos/$releasever/updates/$basearch/gpgcheck=1gpgkey=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=$infrabaseurl=http://mirrors.aliyun.com/centos/$releasever/extras/$basearch/gpgcheck=1gpgkey=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=$infrabaseurl=http://mirrors.aliyun.com/centos/$releasever/centosplus/$basearch/gpgcheck=1enabled=0gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7运行本项目bash


三、如果还未解决,系统的 DNS 配置也可能有问题。可以尝试修改 /etc/resolv.conf 文件,添加可靠的 DNS 服务器地址,例如 8.8.8.8 和 8.8.4.4 。

vi /etc/resolv.conf运行本项目bash
nameserver 8.8.8.8nameserver 8.8.4.4运行本项目bash

已解决:Cannot find a valid baseurl for repo: base/7/x86_64


改完第二个之后都可以运行成功了

已解决:Cannot find a valid baseurl for repo: base/7/x86_64


©著作权归作者所有:来自ZhiKuGroup博客作者没文化的原创作品,如需转载,请注明出处,否则将追究法律责任 来源:ZhiKuGroup博客,欢迎分享。

评论专区
  • 昵 称必填
  • 邮 箱选填
  • 网 址选填
  • 验证码
◎已有 270 人评论
搜索
作者介绍
本站会员尊享VIP特权,现在就加入我们吧!登录注册×
»
会员登录
新用户注册
×
会员注册
已有账号登录
×