0%

centos8 换源

centos8 换源

1、运行以下命令备份之前的repo文件。

1
rename '.repo' '.repo.bak' /etc/yum.repos.d/*.repo

2、运行以下命令下载最新的repo文件。

1
2
wget https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo -O /etc/yum.repos.d/Centos-vault-8.5.2111.repo
wget https://mirrors.aliyun.com/repo/epel-archive-8.repo -O /etc/yum.repos.d/epel-archive-8.repo

3、运行以下命令替换repo文件中的链接。

1
2
sed -i 's/mirrors.cloud.aliyuncs.com/url_tmp/g'  /etc/yum.repos.d/Centos-vault-8.5.2111.repo &&  sed -i 's/mirrors.aliyun.com/mirrors.cloud.aliyuncs.com/g' /etc/yum.repos.d/Centos-vault-8.5.2111.repo && sed -i 's/url_tmp/mirrors.aliyun.com/g' /etc/yum.repos.d/Centos-vault-8.5.2111.repo
sed -i 's/mirrors.aliyun.com/mirrors.cloud.aliyuncs.com/g' /etc/yum.repos.d/epel-archive-8.repo

4、运行以下命令重新创建缓存。

1
yum clean all && yum makecache

yum源和epel源切换完成后,即可使用yum install命令在实例上安装您所需要的软件包。

可能会报错

1
2
3
4
5
[root@k8smaster ~]# yum clean all && yum makecache

Errors during downloading metadata for repository 'epel-archive':
- Curl error (6): Couldn't resolve host name for http://mirrors.cloud.aliyuncs.com/epel-archive/8/Everything/x86_64/repodata/repomd.xml [Could not resolve host: mirrors.cloud.aliyuncs.com]
错误:为仓库 'epel-archive' 下载元数据失败 : Cannot download repomd.xml: Cannot download repodata/repomd.xml: All mirrors were tried

运行以下命令替换repo文件中的链接,就是这一步出错了
官方提供的命令:

1
2
sed -i 's/mirrors.cloud.aliyuncs.com/url_tmp/g' /etc/yum.repos.d/Centos-vault-8.5.2111.repo && sed -i 's/mirrors.aliyun.com/mirrors.cloud.aliyuncs.com/g' /etc/yum.repos.d/Centos-vault-8.5.2111.repo && sed -i 's/url_tmp/mirrors.aliyun.com/g' /etc/yum.repos.d/Centos-vault-8.5.2111.repo
sed -i 's/mirrors.aliyun.com/mirrors.cloud.aliyuncs.com/g' /etc/yum.repos.d/epel-archive-8.repo

http://mirrors.cloud.aliyuncs.com 需要替换为http://mirrors.aliyun.com,但是官方提供的命令没替换完,如果有执行官方提供的命令还是不行的话执行下面的命令:

1
2
sed -i 's/mirrors.cloud.aliyuncs.com/mirrors.aliyun.com/g' /etc/yum.repos.d/Centos-vault-8.5.2111.repo
sed -i 's/mirrors.cloud.aliyuncs.com/mirrors.aliyun.com/g' /etc/yum.repos.d/epel-archive-8.repo

运行以下命令重新创建缓存
yum clean all && yum makecache
1

执行成果,yum install也可以正常使用了

参考文档

[CentOS 8 EOL如何切换源?](https://help.aliyun.com/document_detail/405635.html?spm=5176.21213303.J_6704733920.7.5f853edaVvXmqu&scm=20140722.S_help%40%40%E6%96%87%E6%A1%A3%40%40405635.S_os%2Bhot.ID_405635-RL_centos8%20%20All%20mirrors%20were%20tried-LOC_helpmain-OR_ser-V_2-P0_0_

https://www.cnblogs.com/wjma/p/15926966.html

------------- 本文结束 感谢您的阅读-------------