2022最新 CentOS6 yum报错Error: Cannot find a valid baseurl for repo: base

问题描述

Centos6使用yum install * 或者yum * 相关命令时,

提示

Loaded plugins: fastestmirror, refresh-packagekit, security
Setting up Install Process
Loading mirror speeds from cached hostfile
YumRepo Error: All mirror URLs are not using ftp, http[s] or file.
 Eg. Invalid release/repo/arch combination/
removing mirrorlist with no valid mirrors: /var/cache/yum/i386/6/base/mirrorlist.txt
Error: Cannot find a valid baseurl for repo: base

或提示

Error: Cannot retrieve repository metadata (repomd.xml) for repository: base. Please verify its path and try again


解决方法

一、使用 cat /etc/issue 命令看看自己系统版本是6.几,先找个小本本记下来

二、备份出问题的文件,以免出错后可以恢复。

1.mkdir /etc/yum.repos.d/bakk //新建文件夹

2.mv /etc/yum.repos.d/* /etc/yum.repos.d/bakk //会出现报错,不用管

三、如下打开配置文件CentOS-Base.repo

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

清空!

把下方代码复制进去

注意:如果你的系统版本不是6.7版本

需要先把代码中5个“baseurl“里的“6.7”更换成你自己的系统版本

# 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=https://mirrorlist.centos.org/centos/$releasever/os/$basearch/
baseurl=https://mirrors.aliyun.com/centos-vault/6.7/os/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
 
#released updates 
[updates]
name=CentOS-$releasever - Updates
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates&infra=$infra
#baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos-vault/$releasever/updates/$basearch/
baseurl=https://mirrors.aliyun.com/centos-vault/6.7/updates/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
 
#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=https://mirrors.tuna.tsinghua.edu.cn/centos-vault/$releasever/extras/$basearch/
baseurl=https://mirrors.aliyun.com/centos-vault/6.7/extras/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
 
#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=https://mirrors.tuna.tsinghua.edu.cn/centos-vault/$releasever/centosplus/$basearch/
baseurl=https://mirrors.aliyun.com/centos-vault/6.7/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
 
#contrib - packages by Centos Users
[contrib]
name=CentOS-$releasever - Contrib
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=contrib&infra=$infra
#baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos-vault/$releasever/contrib/$basearch/
baseurl=https://mirrors.aliyun.com/centos-vault/6.7/contrib/$basearch/
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
 

四、清除yum缓存。

yum clean all

五、将服务器上的软件包信息缓存到本地,提高搜索、安装软件的速度

yum makecache

到这一步yum功能就正常开启了。

如果是CentOS的其他版本,可以尝试将代码中“baseurl”里的“/6.7/”和“gpgkey”里的“CentOS-6”更换为自己相应的版本,大概率可以解决问题(没有亲测,不敢确定)。


问题原因

该问题困扰了我两天的时间,翻阅众多帖子发现原因就是出在etc文件下yum.repos.d内CentOS-Base.repo文件上

具体原因是:centos6的yum不维护了,所以各种第三方的yum源也不能用了。而CentOS-Base.repo配置文件存放的就是yum地址,所以将阿里云的地址替换掉CentOS-Base.repo中原本的地址。


写在后面的话

1、找解决方案一定要找最近时间的答案,中途看19年20年的回答走了不少的弯路。

2、如果以后本篇文章的回答也没办法解决这个问题了,多半还是CentOS-Base.repo出了问题。


Error如漫漫长夜,你我的答案是不灭的流星

  • 9
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 6
    评论
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值