三三世界-百宝箱

文章 分类 标签
132 9 250

公告

暂无站点公告

CentOS执行yum命令错误:Error: Cannot find a valid baseurl for repo: base

三三 2021-11-22 3451 0条评论 Linux使用 错误提示yumrepo erroryum更换源

首页 / 正文

Yum(全称为 Yellow dog Updater,
Modified)是一个在Fedora和RedHat以及CentOS中的Shell前端软件包管理器。基于RPM包管理,能够从指定的服务器自动下载RPM包并且安装,可以自动处理依赖性关系,并且一次安装所有依赖的软件包,无须繁琐地一次次下载、安装。

首先,在yum安装过程中,如果不能执行,首先考虑是不是dns服务器的问题,如果是的话,去网卡设置里把dns设置一下即可解决。
参考连接:http://www.33f.net/build/centos_dns.html

本文主要介绍的错误提示为如下:

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/x86_64/7/base/mirrorlist.txt
Error: Cannot find a valid baseurl for repo: base

这种情况的一般问题就是由于镜像地址有问题,切换一个即可解决,比较长期有效的如下:

清华大学:https://mirrors.tuna.tsinghua.edu.cn/centos-vault/ 有centos 6.9的镜像
163:https://mirrors.163.com/centos/
阿里云:https://mirrors.aliyun.com/centos/
腾讯云:https://mirrors.tencent.com/centos/
他们对应的Repo :http://mirrors.网站.com/repo/

解决办法如下:

1、首先确定系统版本,输入命令

cat /etc/redhat-release

2、针对上述错误问题的路径,要记录好详细的地址:

/var/cache/yum/x86_64/7/base/mirrorlist.txt

3、这里针对centos 7.9.2009(其他版本的自行去目录里找一下)的系统,执行根据上述的反馈,执行如下三行代码:
注意,由于版面问题,请复制完整的一行命令,这是三行命令,不是六行。

1) echo "https://mirrors.163.com/centos/7.9.2009/os/x86_64/" > /var/cache/yum/x86_64/7/base/mirrorlist.txt
2) echo "https://mirrors.163.com/centos/7.9.2009/extras/x86_64/" > /var/cache/yum/x86_64/7/extras/mirrorlist.txt
3) echo "https://mirrors.163.com/centos/7.9.2009/updates/x86_64/" > /var/cache/yum/x86_64/7/updates/mirrorlist.txt

4、再次测试yum命令安装一些常用工具比如nano,vim,wget,update等,问题得以解决。

还有一种办法就是修改CentOS-Base.repo的文件配置,相对复杂一些,不过也可以用。

使用命令

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

打开文件后,在每一个#baseurl下面加上类似路径,具体的路径根据情况自己调整,比如OS,update,extras等等,

baseurl=https://mirrors.163.com/centos/7.9.2009/updates/x86_64/

具体操作过程:
1)备份原有的默认yum源

[root@33f ~]# cp /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak

2)修改CentOS-Base.repo文件。将文件中的baseurl地址修改为网易163的yum源地址即可!

[root@33f ~]# nano /etc/yum.repos.d/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-$releasever - Base
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os
baseurl=http://mirrors.163.com/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-6
  
#released updates
[updates]
name=CentOS-$releasever - Updates
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates
baseurl=http://mirrors.163.com/centos/$releasever/updates/$basearch/
gpgcheck=1
gpgkey=http://mirrors.163.com/centos/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
baseurl=http://mirrors.163.com/centos/$releasever/extras/$basearch/
gpgcheck=1
gpgkey=http://mirrors.163.com/centos/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
baseurl=http://mirrors.163.com/centos/$releasever/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://mirrors.163.com/centos/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
baseurl=http://mirrors.163.com/centos/$releasever/contrib/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-6

然后执行如下操作:

[root@33f~]# yum clean all
[root@33f~]# yum makecache          //将服务器上的软件包信息缓存到本地,以提高搜索安装软件的速度
[root@33f~]# yum update              //更新系统

依照上面操作后,yum源就更换成网易的了,并能正常使用。

要特别注意的是:如果要想CentOS使用yum update更新时不升级内核,方法如下:

[root@33f~]# cp /etc/yum.conf /etc/yum.confbak

方法一)修改yum的配置文件

[root@33f~]# nano /etc/yum.conf
在[main]的最后添加 exclude=kernel*

方法二)直接在yum的命令后面加上如下的参数:

[root@33f~]# yum --exclude=kernel* update

如果要更换成阿里云的yum源,只需要将/etc/yum.repos.d/CentOS-Base.repo内容替换成阿里云的源即可,
然后yum clean all、yum makecache、yum update

如果出现下面报错:

https://mirrors.aliyun.com/centos/$releasever/os/x86_64/repodata/repomd.xml: [Errno 14] PYCURL ERROR 22 - "The requested URL returned error: 404 Not Found"

原因分析:
$releasever这个变量在CentOS-Base.repo文件中没有被识别出来。可以去aliyun的镜像官网上查看下正确地址:

即正确地址是:https://mirrors.aliyun.com/centos/7.9.2009/os/x86_64/repodata/repomd.xml
解决办法:将$releasever换成7.9.2009

[root@bastion-IDC ~]# sed -i 's/$releasever/7.9.2009/g' CentOS-Base.repo

如果更换成163的yum源, 出现这种问题

"http://mirrors.163.com/centos/7.9.2009/os/x86_64/repodata/repomd.xml: [Errno 14] PYCURL ERROR 22 - "The requested URL returned error: 404 Not Found""

解决方法和上面是一样的, 也是到http://mirrors.163.com/centos下查看哪个7.x/os/x86_64/repodata/repomd.xml下存在这个文件, 然后把CentOS-Base.repo文件中的$releasever全部更换为这个7.x即可!

评论(0)

当前没有评论,还不快来留下第一个脚印吧



最新评论

  • 三三

    @Doug Shume it's ok for me , you can post here.

  • refugiaguenther

    Saved as a favorite, I like your website!

  • josefa

    If some one wishes to be updated with hottest technologies after that he must be visit this site and be up to date daily.

  • Penzu

    Heello would you mind sharing which blog platform you're using? I'm planning to start my own blog in the near future but I'm having a tough time making a decision between BlogEngine/Wordpress/B2evolution and Drupal. The reason I ask is because your layout seems different then moost blogs and I'm looking for something completely unique. P.S Apologies forr being off-topic butt I had to ask!

  • Yupoo Fendi

    Thanks to my father who shared with me regarding this webpage, this website is genuinely amazing.

  • Doug Shume

    Hi, I have an overflow of customers that I'd like to send to you but I want to make sure you can handle more leads, let me know if you'd like me to send you more info.

  • SuperWind

    zh.us.to 有效
    kms.03k.org 有效
    kms.chinancce.com
    kms.shuax.com 有效
    kms.dwhd.org 有效
    kms.luody.info 有效
    kms.digiboy.ir 有效
    kms.lotro.cc 有效
    www.zgbs.cc 有效
    cy2617.jios.org 有效

  • 三三

    @         权限问题,试试sudo 再加命令。

  •         

    你好提示Permission denied 怎么办啊

日历

2024年12月

1234567
891011121314
15161718192021
22232425262728
293031    

文章目录

上一张 下一张