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

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

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

以下是解决方法:

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

ping www.baidu.com

 Ctrl + c 停止访问

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

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

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

vi /etc/yum.repos.d/CentOS-Base.repo

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

baseurl=http://mirrors.aliyun.com/centos/$releasever/os/$basearch/
baseurl=http://mirrors.aliyun.com/centos/$releasever/updates/$basearch/
baseurl=http://mirrors.aliyun.com/centos/$releasever/extras/$basearch/
baseurl=http://mirrors.aliyun.com/centos/$releasever/centosplus/$basearch/

 

# 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://mirrors.aliyun.com/centos/$releasever/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://mirrors.aliyun.com/centos/$releasever/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://mirrors.aliyun.com/centos/$releasever/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://mirrors.aliyun.com/centos/$releasever/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

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

vi /etc/resolv.conf
nameserver 8.8.8.8
nameserver 8.8.4.4

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

评论 9
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值