解决centos 本地yum源不可用 报Cannot find a valid baseurl for repo: base

本地装机成功后配置完网络执行yum 的时候报:Cannot find a valid baseurl for repo: base
如下图
在这里插入图片描述
百度了一下查了好多有的说换DNS地址,有的说网络问题,DNS地址我更换了 问题没有解决,网络的话我不管是ping 192.168.1.1 还是 www.baidu.com 都没问题,都有返回
在这里插入图片描述
说明网络也没问题
然后就有更换yum 源的 随便捞了一个repo结果不行,提示yum源有问题,仔细观察发现是这个目录找不到文件
在这里插入图片描述
就到目录下看了一下果然缺少文件
在这里插入图片描述
然后看了下配置文件使用的不是url访问的是本地的
在这里插入图片描述
在这里插入图片描述

然后就查询更换yum源,我这里使用的是阿里云的
下载命令如下

wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo

我这里报错了,因为我没有装 wget
所以我使用的是

curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo

配置完按顺序执行

yum clean all

yum makecache

yum -y update

结果执行到 yum makecache又报错了
是因为还需要更改etc/yum.repos.d/CentOS-Base.repo此文件中的

$releasever参数

因为我本地使用的是centos6.8 所以我将CentOS-Base.repo文件中的所有

$releasever参数

都更换为了 6然后执行依旧报错
在这里插入图片描述
然后我直接拿这个在谷歌里面访问了一下果然无法访问
在这里插入图片描述
然后我又再谷歌中尝试了其他几个版本6.几的都访问不到,直到我改为7的时候终于可以访问到了
在这里插入图片描述
然后修改CentOS-Base.repo文件将6修改为7然后再执行

yum clean all

yum makecache

yum -y update

成功
在这里插入图片描述
我本地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-7 - Base - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/7/os/$basearch/
        http://mirrors.aliyuncs.com/centos/7/os/$basearch/
        http://mirrors.cloud.aliyuncs.com/centos/7/os/$basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7

#released updates
[updates]
name=CentOS-7 - Updates - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/7/updates/$basearch/
        http://mirrors.aliyuncs.com/centos/7/updates/$basearch/
        http://mirrors.cloud.aliyuncs.com/centos/7/updates/$basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7

#additional packages that may be useful
[extras]
name=CentOS-7 - Extras - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/7/extras/$basearch/
        http://mirrors.aliyuncs.com/centos/7/extras/$basearch/
        http://mirrors.cloud.aliyuncs.com/centos/7/extras/$basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7

#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-7 - Plus - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/7/centosplus/$basearch/
        http://mirrors.aliyuncs.com/centos/7/centosplus/$basearch/
        http://mirrors.cloud.aliyuncs.com/centos/7/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7

#contrib - packages by Centos Users
[contrib]
name=CentOS-7 - Contrib - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/7/contrib/$basearch/
        http://mirrors.aliyuncs.com/centos/7/contrib/$basearch/
        http://mirrors.cloud.aliyuncs.com/centos/7/contrib/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7

猜你喜欢

转载自blog.csdn.net/G_whang/article/details/111054605