如何将CentOS8更换国内源

59e2e73770ddb56af93ec6959b79108c.png

CentOS 8操作系统版本在2021年12月31日结束了生命周期(EOL),Linux社区已不再维护该操作系统版本。因此,CentOS 8的源地址http://mirror.centos.org/centos/8/的内容已被移除。

在这种情况下,如果业务在过渡期仍需使用CentOS 8,那么就需要更新备用源。而由于官方的源已经去掉,第三方也就无法再同步,所以第三方的源也就不复存在了。但是大部分第三方都把最后的源做了备份并弄了个新的地址,方便过渡期使用。阿里云的源镜像服务器在国内,使用yum安装服务时下载速度会更快些。

12a2a11e0d3f610a85d5378a5bd02db1.png

更换源

cd /etc/yum.repos.d

建议先进行备份:

mv CentOS-Base.repo CentOS-Base.repo.bak

更换 CentOS-Base.repo 为 阿里云的 CentOS-Base.repo

wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo

更新yum缓存

yum clean all
yum makecache

若 yum makecache 出现以下错误,则需更换 epel.repo

- Status code: 404 for http://archives.fedoraproject.org/pub/archive/epel/8/Everything/x86_64/repodata/repomd.xml (IP: 38.145.60.23)
Error: Failed to download metadata for repo 'epel': Cannot download repomd.xml: Cannot download repodata/repomd.xml: All mirrors were tried

更换 epel.repo 为 阿里云的 epel.repo

wget -O /etc/yum.repos.d/epel.repo https://mirrors.aliyun.com/repo/epel-7.repo

注:更新源/镜像后,记得更新yum缓存~

若 yum makecache 再次出现以下错误,则需更换 epel-modular.repo

Errors during downloading metadata for repository 'epel-modular':
  - Status code: 404 for https://mirrors.fedoraproject.org/metalink?repo=epel-modular-3&arch=x86_64&infra=$infra&content=$contentdir (IP: 38.145.60.20)
Error: Failed to download metadata for repo 'epel-modular': Cannot prepare internal mirrorlist: Interrupted by signal

更换 epel-modular.repo 为 阿里云的 epel-modular.repo

由于笔者在https://mirrors.aliyun.com/repo上未找到epel-modular.repo,因此手动将epel-modular.repo中的baseurl替换为aliyun(与epel.repo的相同)。如下:注释的 baseurl 是旧的 url,当前 epel-modular.repo 使用的 baseurl 同 epel.repo 中的 baseurl 。

[epel-modular]
name=Extra Packages for Enterprise Linux Modular $releasever - $basearch
# It is much more secure to use the #metalink, but if you wish to use a local mirror
# place it's address here.
baseurl=http://mirrors.aliyun.com/epel/7/$basearch
#baseurl=http://archives.fedoraproject.org/pub/archive/epel/$releasever/Modular/$basearch
#metalink=https://mirrors.fedoraproject.org/#metalink?repo=epel-modular-$releasever&arch=$basearch&infra=$infra&content=$contentdir
enabled=1
gpgcheck=1
countme=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-8
[epel-modular-debuginfo]
name=Extra Packages for Enterprise Linux Modular $releasever - $basearch - Debug
# It is much more secure to use the #metalink, but if you wish to use a local mirror
# place it's address here.
baseurl=http://mirrors.aliyun.com/epel/7/$basearch/debug
#baseurl=http://archives.fedoraproject.org/pub/archive/epel/$releasever/Modular/$basearch/debug
#metalink=https://mirrors.fedoraproject.org/#metalink?repo=epel-modular-debug-$releasever&arch=$basearch&infra=$infra&content=$contentdir
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-8
gpgcheck=1
[epel-modular-source]
name=Extra Packages for Enterprise Linux Modular $releasever - $basearch - Source
# It is much more secure to use the #metalink, but if you wish to use a local mirror
# place it's address here.
baseurl=http://mirrors.aliyun.com/epel/7/SRPMS
#baseurl=http://archives.fedoraproject.org/pub/archive/epel/$releasever/Modular/SRPMS
#metalink=https://mirrors.fedoraproject.org/#metalink?repo=epel-modular-source-$releasever&arch=$basearch&infra=$infra&content=$contentdir
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-8
gpgcheck=1


猜你喜欢

转载自blog.csdn.net/zhangkunls/article/details/134820644