Cento8默认的YUM源都是海外的服务器的,国内访问缓慢或者干脆无法访问,为了能正常使用,换源是必须的,同时为了保证软件的丰富性,添加EPEL扩展源会减少很多不必要的麻烦。
下面给Centos8换腾讯云的YUM源和EPEL扩展源,腾讯云的比阿里云的源快。
1.备份原来的YUM源:
mv /etc/yum.repos.d/CentOS-Linux-AppStream.repo /etc/yum.repos.d/CentOS-Linux-AppStream.repo.backup mv /etc/yum.repos.d/CentOS-Linux-BaseOS.repo /etc/yum.repos.d/CentOS-Linux-BaseOS.repo.backup mv /etc/yum.repos.d/CentOS-Linux-ContinuousRelease.repo /etc/yum.repos.d/CentOS-Linux-ContinuousRelease.repo.backup mv /etc/yum.repos.d/CentOS-Linux-Debuginfo.repo /etc/yum.repos.d/CentOS-Linux-Debuginfo.repo.backup mv /etc/yum.repos.d/CentOS-Linux-Devel.repo /etc/yum.repos.d/CentOS-Linux-Devel.repo.backup mv /etc/yum.repos.d/CentOS-Linux-Extras.repo /etc/yum.repos.d/CentOS-Linux-Extras.repo.backup mv /etc/yum.repos.d/CentOS-Linux-FastTrack.repo /etc/yum.repos.d/CentOS-Linux-FastTrack.repo.backup mv /etc/yum.repos.d/CentOS-Linux-HighAvailability.repo /etc/yum.repos.d/CentOS-Linux-HighAvailability.repo.backup mv /etc/yum.repos.d/CentOS-Linux-Media.repo /etc/yum.repos.d/CentOS-Linux-Media.repo.backup mv /etc/yum.repos.d/CentOS-Linux-Plus.repo /etc/yum.repos.d/CentOS-Linux-Plus.repo.backup mv /etc/yum.repos.d/CentOS-Linux-PowerTools.repo /etc/yum.repos.d/CentOS-Linux-PowerTools.repo.backup mv /etc/yum.repos.d/CentOS-Linux-Sources.repo /etc/yum.repos.d/CentOS-Linux-Sources.repo.backup
2.创建EPEL扩展源文件
touch epel.repo touch epel-modular.repo touch epel-playground.repo touch epel-testing.repo touch epel-testing-modular.repo
3.替换腾讯云的YUM源和EPEL扩展源:
cat > /etc/yum.repos.d/CentOS-Linux-AppStream.repo <<'EOF'
# CentOS-Linux-AppStream.repo
#
# The mirrorlist system uses the connecting IP address of the client and the
# update status of each mirror to pick current mirrors that are geographically
# close to the client. You should use this for CentOS updates unless you are
# manually picking other mirrors.
#
# If the mirrorlist does not work for you, you can try the commented out
# baseurl line instead.
[appstream]
name=CentOS Linux 8.5.2111 - AppStream
#mirrorlist=http://mirrorlist.centos.org/?release=8.5.2111&arch=$basearch&repo=AppStream&infra=$infra
baseurl=http://mirrors.cloud.tencent.com/centos-vault/8.5.2111/AppStream/$basearch/os/
gpgcheck=1
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
EOF
cat > /etc/yum.repos.d/CentOS-Linux-BaseOS.repo <<'EOF'
# CentOS-Linux-BaseOS.repo
#
# The mirrorlist system uses the connecting IP address of the client and the
# update status of each mirror to pick current mirrors that are geographically
# close to the client. You should use this for CentOS updates unless you are
# manually picking other mirrors.
#
# If the mirrorlist does not work for you, you can try the commented out
# baseurl line instead.
[baseos]
name=CentOS Linux 8.5.2111 - BaseOS
#mirrorlist=http://mirrorlist.centos.org/?release=8.5.2111&arch=$basearch&repo=BaseOS&infra=$infra
baseurl=http://mirrors.cloud.tencent.com/centos-vault/8.5.2111/BaseOS/$basearch/os/
gpgcheck=1
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
EOF
cat > /etc/yum.repos.d/CentOS-Linux-ContinuousRelease.repo <<'EOF'
# CentOS-Linux-ContinuousRelease.repo
#
# The mirrorlist system uses the connecting IP address of the client and the
# update status of each mirror to pick current mirrors that are geographically
# close to the client. You should use this for CentOS updates unless you are
# manually picking other mirrors.
#
# If the mirrorlist does not work for you, you can try the commented out
# baseurl line instead.
#
# The Continuous Release (CR) repository contains packages for the next minor
# release of CentOS Linux. This repository only has content in the time period
# between an upstream release and the official CentOS Linux release. These
# packages have not been fully tested yet and should be considered beta
# quality. They are made available for people willing to test and provide
# feedback for the next release.
[cr]
name=CentOS Linux 8.5.2111 - ContinuousRelease
#mirrorlist=http://mirrorlist.centos.org/?release=8.5.2111&arch=$basearch&repo=cr&infra=$infra
baseurl=http://mirrors.cloud.tencent.com/centos-vault/8.5.2111/cr/$basearch/os/
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
EOF
cat > /etc/yum.repos.d/CentOS-Linux-Debuginfo.repo <<'EOF'
# CentOS-Linux-Debuginfo.repo
#
# All debug packages are merged into a single repo, split by basearch, and are
# not signed.
[debuginfo]
name=CentOS Linux 8.5.2111 - Debuginfo
baseurl=http://debuginfo.centos.org/8.5.2111/$basearch/
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
EOF
cat > /etc/yum.repos.d/CentOS-Linux-Devel.repo <<'EOF'
# CentOS-Linux-Devel.repo
#
# The mirrorlist system uses the connecting IP address of the client and the
# update status of each mirror to pick current mirrors that are geographically
# close to the client. You should use this for CentOS updates unless you are
# manually picking other mirrors.
#
# If the mirrorlist does not work for you, you can try the commented out
# baseurl line instead.
[devel]
name=CentOS Linux 8.5.2111 - Devel WARNING! FOR BUILDROOT USE ONLY!
#mirrorlist=http://mirrorlist.centos.org/?release=8.5.2111&arch=$basearch&repo=Devel&infra=$infra
baseurl=http://mirrors.cloud.tencent.com/centos-vault/8.5.2111/Devel/$basearch/os/
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
EOF
cat > /etc/yum.repos.d/CentOS-Linux-Extras.repo <<'EOF'
# CentOS-Linux-Extras.repo
#
# The mirrorlist system uses the connecting IP address of the client and the
# update status of each mirror to pick current mirrors that are geographically
# close to the client. You should use this for CentOS updates unless you are
# manually picking other mirrors.
#
# If the mirrorlist does not work for you, you can try the commented out
# baseurl line instead.
[extras]
name=CentOS Linux 8.5.2111 - Extras
#mirrorlist=http://mirrorlist.centos.org/?release=8.5.2111&arch=$basearch&repo=extras&infra=$infra
baseurl=http://mirrors.cloud.tencent.com/centos-vault/8.5.2111/extras/$basearch/os/
gpgcheck=1
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
EOF
cat > /etc/yum.repos.d/CentOS-Linux-FastTrack.repo <<'EOF'
# CentOS-Linux-FastTrack.repo
#
# The mirrorlist system uses the connecting IP address of the client and the
# update status of each mirror to pick current mirrors that are geographically
# close to the client. You should use this for CentOS updates unless you are
# manually picking other mirrors.
#
# If the mirrorlist does not work for you, you can try the commented out
# baseurl line instead.
[fasttrack]
name=CentOS Linux 8.5.2111 - FastTrack
#mirrorlist=http://mirrorlist.centos.org/?release=8.5.2111&arch=$basearch&repo=fasttrack&infra=$infra
baseurl=http://mirrors.cloud.tencent.com/centos-vault/8.5.2111/fasttrack/$basearch/os/
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
EOF
cat > /etc/yum.repos.d/CentOS-Linux-HighAvailability.repo <<'EOF'
# CentOS-Linux-HighAvailability.repo
#
# The mirrorlist system uses the connecting IP address of the client and the
# update status of each mirror to pick current mirrors that are geographically
# close to the client. You should use this for CentOS updates unless you are
# manually picking other mirrors.
#
# If the mirrorlist does not work for you, you can try the commented out
# baseurl line instead.
[ha]
name=CentOS Linux 8.5.2111 - HighAvailability
#mirrorlist=http://mirrorlist.centos.org/?release=8.5.2111&arch=$basearch&repo=HighAvailability&infra=$infra
baseurl=http://mirrors.cloud.tencent.com/centos-vault/8.5.2111/HighAvailability/$basearch/os/
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
EOF
cat > /etc/yum.repos.d/CentOS-Linux-Media.repo <<'EOF'
# CentOS-Linux-Media.repo
#
# You can use this repo to install items directly off the installation media.
# Verify your mount point matches one of the below file:// paths.
[media-baseos]
name=CentOS Linux 8.5.2111 - Media - BaseOS
baseurl=file:///media/CentOS/BaseOS
file:///media/cdrom/BaseOS
file:///media/cdrecorder/BaseOS
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
[media-appstream]
name=CentOS Linux 8.5.2111 - Media - AppStream
baseurl=file:///media/CentOS/AppStream
file:///media/cdrom/AppStream
file:///media/cdrecorder/AppStream
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
EOF
cat > /etc/yum.repos.d/CentOS-Linux-Plus.repo <<'EOF'
# CentOS-Linux-Plus.repo
#
# The mirrorlist system uses the connecting IP address of the client and the
# update status of each mirror to pick current mirrors that are geographically
# close to the client. You should use this for CentOS updates unless you are
# manually picking other mirrors.
#
# If the mirrorlist does not work for you, you can try the commented out
# baseurl line instead.
[plus]
name=CentOS Linux 8.5.2111 - Plus
#mirrorlist=http://mirrorlist.centos.org/?release=8.5.2111&arch=$basearch&repo=centosplus&infra=$infra
baseurl=http://mirrors.cloud.tencent.com/centos-vault/8.5.2111/centosplus/$basearch/os/
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
EOF
cat > /etc/yum.repos.d/CentOS-Linux-PowerTools.repo <<'EOF'
# CentOS-Linux-PowerTools.repo
#
# The mirrorlist system uses the connecting IP address of the client and the
# update status of each mirror to pick current mirrors that are geographically
# close to the client. You should use this for CentOS updates unless you are
# manually picking other mirrors.
#
# If the mirrorlist does not work for you, you can try the commented out
# baseurl line instead.
[powertools]
name=CentOS Linux 8.5.2111 - PowerTools
#mirrorlist=http://mirrorlist.centos.org/?release=8.5.2111&arch=$basearch&repo=PowerTools&infra=$infra
baseurl=http://mirrors.cloud.tencent.com/centos-vault/8.5.2111/PowerTools/$basearch/os/
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
EOF
cat > /etc/yum.repos.d/CentOS-Linux-Sources.repo <<'EOF'
# CentOS-Linux-Sources.repo
[baseos-source]
name=CentOS Linux 8.5.2111 - BaseOS - Source
baseurl=http://vault.centos.org/$contentdir/8.5.2111/BaseOS/Source/
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
[appstream-source]
name=CentOS Linux 8.5.2111 - AppStream - Source
baseurl=http://vault.centos.org/$contentdir/8.5.2111/AppStream/Source/
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
[extras-source]
name=CentOS Linux 8.5.2111 - Extras - Source
baseurl=http://vault.centos.org/$contentdir/8.5.2111/extras/Source/
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
[plus-source]
name=CentOS Linux 8.5.2111 - Plus - Source
baseurl=http://vault.centos.org/$contentdir/8.5.2111/centosplus/Source/
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
EOF
cat > /etc/yum.repos.d/epel.repo <<'EOF'
[epel]
name=Extra Packages for Enterprise Linux $releasever - $basearch
baseurl=http://mirrors.cloud.tencent.com/epel/8/Everything/$basearch
#metalink=https://mirrors.fedoraproject.org/metalink?repo=epel-$releasever&arch=$basearch&infra=$infra&content=$contentdir
enabled=1
gpgcheck=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-8
[epel-debuginfo]
name=Extra Packages for Enterprise Linux $releasever - $basearch - Debug
baseurl=http://mirrors.cloud.tencent.com/epel/8/Everything/$basearch/debug
#metalink=https://mirrors.fedoraproject.org/metalink?repo=epel-debug-$releasever&arch=$basearch&infra=$infra&content=$contentdir
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-8
gpgcheck=0
[epel-source]
name=Extra Packages for Enterprise Linux $releasever - $basearch - Source
baseurl=http://mirrors.cloud.tencent.com/epel/8/Everything/SRPMS
#metalink=https://mirrors.fedoraproject.org/metalink?repo=epel-source-$releasever&arch=$basearch&infra=$infra&content=$contentdir
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-8
gpgcheck=0
EOF
cat > /etc/yum.repos.d/epel-modular.repo <<'EOF'
[epel-modular]
name=Extra Packages for Enterprise Linux Modular $releasever - $basearch
baseurl=http://mirrors.cloud.tencent.com/epel/8/Modular/$basearch
#metalink=https://mirrors.fedoraproject.org/metalink?repo=epel-modular-$releasever&arch=$basearch&infra=$infra&content=$contentdir
enabled=1
gpgcheck=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-8
[epel-modular-debuginfo]
name=Extra Packages for Enterprise Linux Modular $releasever - $basearch - Debug
baseurl=http://mirrors.cloud.tencent.com/epel/8/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=0
[epel-modular-source]
name=Extra Packages for Enterprise Linux Modular $releasever - $basearch - Source
baseurl=http://mirrors.cloud.tencent.com/epel/8/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=0
EOF
cat > /etc/yum.repos.d/epel-playground.repo <<'EOF'
[epel-playground]
name=Extra Packages for Enterprise Linux $releasever - Playground - $basearch
baseurl=http://mirrors.cloud.tencent.com/epel/playground/$releasever/Everything/$basearch/os
#metalink=https://mirrors.fedoraproject.org/metalink?repo=playground-epel$releasever&arch=$basearch&infra=$infra&content=$contentdir
enabled=0
gpgcheck=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-8
[epel-playground-debuginfo]
name=Extra Packages for Enterprise Linux $releasever - Playground - $basearch - Debug
baseurl=http://mirrors.cloud.tencent.com/epel/playground/$releasever/Everything/$basearch/debug
#metalink=https://mirrors.fedoraproject.org/metalink?repo=playground-debug-epel$releasever&arch=$basearch&infra=$infra&content=$contentdir
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-8
gpgcheck=0
[epel-playground-source]
name=Extra Packages for Enterprise Linux $releasever - Playground - $basearch - Source
baseurl=http://mirrors.cloud.tencent.com/epel/playground/$releasever/Everything/source/tree/
#metalink=https://mirrors.fedoraproject.org/metalink?repo=playground-source-epel$releasever&arch=$basearch&infra=$infra&content=$contentdir
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-8
gpgcheck=0
EOF
cat > /etc/yum.repos.d/epel-testing.repo <<'EOF'
[epel-testing]
name=Extra Packages for Enterprise Linux $releasever - Testing - $basearch
baseurl=http://mirrors.cloud.tencent.com/epel/testing/$releasever/Everything/$basearch
#metalink=https://mirrors.fedoraproject.org/metalink?repo=testing-epel$releasever&arch=$basearch&infra=$infra&content=$contentdir
enabled=0
gpgcheck=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-8
[epel-testing-debuginfo]
name=Extra Packages for Enterprise Linux $releasever - Testing - $basearch - Debug
baseurl=http://mirrors.cloud.tencent.com/epel/testing/$releasever/Everything/$basearch/debug
#metalink=https://mirrors.fedoraproject.org/metalink?repo=testing-debug-epel$releasever&arch=$basearch&infra=$infra&content=$contentdir
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-8
gpgcheck=0
[epel-testing-source]
name=Extra Packages for Enterprise Linux $releasever - Testing - $basearch - Source
baseurl=http://mirrors.cloud.tencent.com/epel/testing/$releasever/Everything/SRPMS
#metalink=https://mirrors.fedoraproject.org/metalink?repo=testing-source-epel$releasever&arch=$basearch&infra=$infra&content=$contentdir
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-8
gpgcheck=0
EOF
cat > /etc/yum.repos.d/epel-testing-modular.repo <<'EOF'
[epel-testing-modular]
name=Extra Packages for Enterprise Linux Modular $releasever - Testing - $basearch
baseurl=http://mirrors.cloud.tencent.com/epel/testing/$releasever/Modular/$basearch
#metalink=https://mirrors.fedoraproject.org/metalink?repo=testing-modular-epel$releasever&arch=$basearch&infra=$infra&content=$contentdir
enabled=0
gpgcheck=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-8
[epel-testing-modular-debuginfo]
name=Extra Packages for Enterprise Linux Modular $releasever - Testing - $basearch - Debug
baseurl=http://mirrors.cloud.tencent.com/epel/testing/$releasever/Modular/$basearch/debug
#metalink=https://mirrors.fedoraproject.org/metalink?repo=testing-modular-debug-epel$releasever&arch=$basearch&infra=$infra&content=$contentdir
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-8
gpgcheck=0
[epel-testing-modular-source]
name=Extra Packages for Enterprise Linux Modular $releasever - Testing - $basearch - Source
baseurl=http://mirrors.cloud.tencent.com/epel/testing/$releasever/Modular/SRPMS
#metalink=https://mirrors.fedoraproject.org/metalink?repo=testing-modular-source-epel$releasever&arch=$basearch&infra=$infra&content=$contentdir
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-8
gpgcheck=0
EOF
4.清理老的DNF源缓存并重新生成DNF源和EPEL源的缓存:
dnf clean all && dnf makecache
5.安装常用软件工具:
#安装Wget dnf install -y wget #安装vim dnf install -y vim #安装net-tools dnf install -y net-tools #安装gcc dnf -y install gcc make #安装自动补全命令工具bash-completion dnf -y install bash-completion #杀死僵尸进程工具psmisc dnf -y install psmisc
6.完成
还有一键换源脚本:
bash <(curl -sSL https://gitee.com/SuperManito/LinuxMirrors/raw/main/ChangeMirrors.sh)
上文中第三步其实也可以直通上传替换到的文件来实现。