已解决:Cannot find a valid baseurl for repo: base/7/x86_64
用心解决每个bug 2024-09-07 15:37:03 阅读 89
使用 Yum 命令遇到此错误,下图是报错信息:
分析:由第二行报错信息得在尝试从 CentOS 镜像列表获取信息时遇到了问题,无法解析 <code>mirrorlist.centos.org 这个域名。这可能是由于网络连接问题导致的。
以下是解决方法:
一、首先通过 ping 命令检查网络连接,确保网络能够正常访问外网。
ping www.baidu.com
Ctrl + c 停止访问
可以正常访问的结果如下图所示:
二、如果网络正常,问题可能是当前的镜像源出现故障或者当前网络无法访问镜像源。可以尝试更换为其他可用的镜像源。
可以通过 vi 命令编辑 <code>/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/
#
# 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
改完第二个之后都可以运行成功了
本文标签
声明
本文内容仅代表作者观点,或转载于其他网站,本站不以此文作为商业用途
如有涉及侵权,请联系本站进行删除
转载本站原创文章,请注明来源及作者。