centos8将yum源更换为国内(阿里云)源

背景

yum install 失败

更换源

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

你可能感兴趣的:(centos8将yum源更换为国内(阿里云)源)