解决Centos8 yum 官方源下线后无法使用问题
1、错误情况
Centos8.2及以上版本,8.1.2009版暂无此问题
更新yum时报错:
1 CentOS-8 - Base - mirrors.aliyun.com 299 B/s | 2.3 kB 00:07
2 Errors during downloading metadata for repository 'base':
3 - Status code: 404 for https://mirrors.aliyun.com/centos/8/BaseOS/x86_64/os/repodata/repomd.xml (IP: 39.96.118.194)
4 - Curl error (7): Couldn't connect to server for http://mirrors.aliyuncs.com/centos/8/BaseOS/x86_64/os/repodata/repomd.xml [Failed to connect to mirrors.aliyuncs.com port 80: Connection timed out]
5 - Status code: 404 for http://mirrors.cloud.aliyuncs.com/centos/8/BaseOS/x86_64/os/repodata/repomd.xml (IP: 100.100.2.148)
6 Error: Failed to download metadata for repo 'base': Cannot download repomd.xml: Cannot download repodata/repomd.xml: All mirrors were tried
- 按照网上教程,更换阿里源、清华源都还是无法使用。
2、原因分析
centos8项目官方已于2021年底停止,相关源已无法使用,所以网上22年前的换源教程都已无法使用。
3、解决方案
进入配置文件内,备份所有的.repo文件(也可以)
#进入配置文件夹
1 mv /etc/yum.repos.d/ /etc/yum.repos.d_bak && mkdir /etc/yum.repos.d/
2 wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo
- 如果你没有安装wget,也可以用下面命令:
1curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo
- 运行 dnf makecache 生成缓存
1dnf makecache
- 大功告成!
4、其他
如果你是非阿里云ECS用户,可能回会出现 Couldn’t resolve host ‘mirrors.cloud.aliyuncs.com’ 的信息,不过不影响使用。你可以修改相关的配置:
1 sed -i -e '/mirrors.cloud.aliyuncs.com/d' -e '/mirrors.aliyuncs.com/d' /etc/yum.repos.d/CentOS-Base.repo