CentOS6安装rpm时报错“Cannot find a valid baseurl for repo: centos-sclo-rh“的解决办法

CentOS release 6.9 (Final)安装RPM包时遇到如下报错:

Determining fastest mirrors
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/6/centos-sclo-rh/mirrorlist.txt
错误:Cannot find a valid baseurl for repo: centos-sclo-rh

原因:

2020年12月2日官方结束了对CentOS 6.x的支持,导致在使用yum安装或更新程序的时候出现404错误

解决办法:

  1. 清空CentOS-Base.repo文件
echo > /etc/yum.repos.d/CentOS-Base.repo
  1. 打开CentOS-Base.repo文件, 并且拷贝第3点的全部内容填入该文件
vi /etc/yum.repos.d/CentOS-Base.repo
  1. 需要拷贝的内容如下:
[base]
name=CentOS-$releasever - Base
#mirrorlist=http://#mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os&infra=$infra
baseurl=https://vault.centos.org/6.10/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://vault.centos.org/6.10/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://vault.centos.org/6.10/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://vault.centos.org/6.10/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://vault.centos.org/6.10/contrib/$basearch/
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6

  1. 删除/etc/yum.repos.d/目录下其他无关的repo文件 [只留下CentOS-Base.repo即可]
cd /etc/yum.repos.d/
ls | grep -v 'CentOS-Base.repo' | xargs rm
  1. 重建yum缓存, 更新并启用新的yum源
yum clean all && yum makecache

此时就大功告成了~

感谢观看,分享不易,有用请点赞~

你可能感兴趣的:(Linux,环境异常的解决方式,centos,centos6,yum)