2024-12-28 17:48:16
,某些文章具有时效性,若有错误或已失效,请在下方留言!前言
由于CentOS 7 官方已于2024年6月30日停止维护,这意味着不再有安全更新和功能更新,因此,继续使用 CentOS 7 的用户需要切换到社区或第三方提供的 YUM 源,以获得必要的更新和软件包支持,本文将介绍如何在 CentOS 7 停止维护后更换 YUM 源。
注意:本文仅适用于Centos7系统,请勿将本文用于其它版本系统!
部署教程
备份现有yum源
1. 进入 /etc/yum.repos.d/
目录
cd /etc/yum.repos.d/
2. 备份现有的yum源文件
mkdir backup
mv *.repo backup/
我在这里整理了多个Centos7国内镜像的源,任选其一即可,在Centos7停服后,默认的源已从centos改成了centos-vault,这里所有的源都是我二次配置修改过的
更换yum源(x86_64架构)
阿里云源(curl方式)
curl -o /etc/yum.repos.d/Centos7-aliyun.repo https://mirrors.wlnmp.com/centos/Centos7-aliyun-x86_64.repo
阿里云源(wget方式)
wget https://mirrors.wlnmp.com/centos/Centos7-aliyun-x86_64.repo -P /etc/yum.repos.d/
网易源(curl方式)
curl -o /etc/yum.repos.d/Centos7-163.repo https://mirrors.wlnmp.com/centos/Centos7-163-x86_64.repo
网易源(wget方式)
wget https://mirrors.wlnmp.com/centos/Centos7-163-x86_64.repo -P /etc/yum.repos.d/
腾讯源(curl方式)
curl -o /etc/yum.repos.d/Centos7-tencent.repo https://mirrors.wlnmp.com/centos/Centos7-tencent-x86_64.repo
腾讯源(wget方式)
wget https://mirrors.wlnmp.com/centos/Centos7-tencent-x86_64.repo -P /etc/yum.repos.d/
中国科学技术大学源(curl方式)
curl -o /etc/yum.repos.d/Centos7-ustc.repo https://mirrors.wlnmp.com/centos/Centos7-ustc-x86_64.repo
中国科学技术大学源(wget方式)
wget https://mirrors.wlnmp.com/centos/Centos7-ustc-x86_64.repo -P /etc/yum.repos.d/
清华源(curl方式)
curl -o /etc/yum.repos.d/Centos7-tuna.repo https://mirrors.wlnmp.com/centos/Centos7-tuna-x86_64.repo
清华源(wget方式)
wget https://mirrors.wlnmp.com/centos/Centos7-tuna-x86_64.repo -P /etc/yum.repos.d/
附:x86_64架构系统,Centos7-aliyun.repo配置文件内容
[base]
name=CentOS-$releasever - base - mirrors.aliyun.com
baseurl=http://mirrors.aliyun.com/centos-vault/centos/$releasever/os/$basearch/
enabled=1
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos-vault/RPM-GPG-KEY-CentOS-7
[updates]
name=CentOS-$releasever - updates - mirrors.aliyun.com
baseurl=http://mirrors.aliyun.com/centos-vault/centos/$releasever/updates/$basearch/
enabled=1
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos-vault/RPM-GPG-KEY-CentOS-7
[extras]
name=CentOS-$releasever - extras - mirrors.aliyun.com
baseurl=http://mirrors.aliyun.com/centos-vault/centos/$releasever/extras/$basearch/
enabled=1
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos-vault/RPM-GPG-KEY-CentOS-7
[centosplus]
name=CentOS-$releasever - centosplus - mirrors.aliyun.com
baseurl=http://mirrors.aliyun.com/centos-vault/centos/$releasever/centosplus/$basearch/
enabled=0
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos-vault/RPM-GPG-KEY-CentOS-7
[fasttrack]
name=CentOS-$releasever - fasttrack - mirrors.aliyun.com
baseurl=http://mirrors.aliyun.com/centos-vault/centos/$releasever/fasttrack/$basearch/
enabled=0
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos-vault/RPM-GPG-KEY-CentOS-7
[atomic]
name=CentOS-$releasever - atomic - mirrors.aliyun.com
baseurl=http://mirrors.aliyun.com/centos-vault/centos/$releasever/atomic/$basearch/
enabled=0
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos-vault/RPM-GPG-KEY-CentOS-7
[dotnet]
name=CentOS-$releasever - dotnet - mirrors.aliyun.com
baseurl=http://mirrors.aliyun.com/centos-vault/centos/$releasever/dotnet/$basearch/
enabled=0
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos-vault/RPM-GPG-KEY-CentOS-7
[rt]
name=CentOS-$releasever - rt - mirrors.aliyun.com
baseurl=http://mirrors.aliyun.com/centos-vault/centos/$releasever/rt/$basearch/
enabled=0
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos-vault/RPM-GPG-KEY-CentOS-7
[sclo-rh]
name=CentOS-$releasever - sclo-rh - mirrors.aliyun.com
baseurl=http://mirrors.aliyun.com/centos-vault/centos/$releasever/sclo/$basearch/rh/
enabled=0
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos-vault/RPM-GPG-KEY-CentOS-7
[sclo-sclo]
name=CentOS-$releasever - sclo-sclo - mirrors.aliyun.com
baseurl=http://mirrors.aliyun.com/centos-vault/centos/$releasever/sclo/$basearch/sclo/
enabled=0
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos-vault/RPM-GPG-KEY-CentOS-7
更换yum源(只要当前不是x86_64架构的,都使用以下配置,适用于aarch64、i386、ppc64等)
阿里云源(curl方式)
curl -o /etc/yum.repos.d/Centos7-aliyun.repo https://mirrors.wlnmp.com/centos/Centos7-aliyun-altarch.repo
阿里云源(wget方式)
wget https://mirrors.wlnmp.com/centos/Centos7-aliyun-altarch.repo -P /etc/yum.repos.d/
网易源(curl方式)
curl -o /etc/yum.repos.d/Centos7-163.repo https://mirrors.wlnmp.com/centos/Centos7-163-altarch.repo
网易源(wget方式)
wget https://mirrors.wlnmp.com/centos/Centos7-163-altarch.repo -P /etc/yum.repos.d/
腾讯源(curl方式)
curl -o /etc/yum.repos.d/Centos7-tencent.repo https://mirrors.wlnmp.com/centos/Centos7-tencent-altarch.repo
腾讯源(wget方式)
wget https://mirrors.wlnmp.com/centos/Centos7-tencent-altarch.repo -P /etc/yum.repos.d/
中国科学技术大学源(curl方式)
curl -o /etc/yum.repos.d/Centos7-ustc.repo https://mirrors.wlnmp.com/centos/Centos7-ustc-altarch.repo
中国科学技术大学源(wget方式)
wget https://mirrors.wlnmp.com/centos/Centos7-ustc-altarch.repo -P /etc/yum.repos.d/
清华源(curl方式)
curl -o /etc/yum.repos.d/Centos7-tuna.repo https://mirrors.wlnmp.com/centos/Centos7-tuna-altarch.repo
清华源(wget方式)
wget https://mirrors.wlnmp.com/centos/Centos7-tuna-altarch.repo -P /etc/yum.repos.d/
附:Centos7-aliyun.repo配置文件内容(非x86_64架构系统),配置文件通过$basearch变量自动识别系统架构
[base]
name=CentOS-$releasever - base - mirrors.aliyun.com
baseurl=http://mirrors.aliyun.com/centos-vault/altarch/$releasever/os/$basearch/
enabled=1
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos-vault/RPM-GPG-KEY-CentOS-7
[updates]
name=CentOS-$releasever - updates - mirrors.aliyun.com
baseurl=http://mirrors.aliyun.com/centos-vault/altarch/$releasever/updates/$basearch/
enabled=1
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos-vault/RPM-GPG-KEY-CentOS-7
[extras]
name=CentOS-$releasever - extras - mirrors.aliyun.com
baseurl=http://mirrors.aliyun.com/centos-vault/altarch/$releasever/extras/$basearch/
enabled=1
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos-vault/RPM-GPG-KEY-CentOS-7
[centosplus]
name=CentOS-$releasever - centosplus - mirrors.aliyun.com
baseurl=http://mirrors.aliyun.com/centos-vault/altarch/$releasever/centosplus/$basearch/
enabled=0
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos-vault/RPM-GPG-KEY-CentOS-7
[fasttrack]
name=CentOS-$releasever - fasttrack - mirrors.aliyun.com
baseurl=http://mirrors.aliyun.com/centos-vault/altarch/$releasever/fasttrack/$basearch/
enabled=0
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos-vault/RPM-GPG-KEY-CentOS-7
[atomic]
name=CentOS-$releasever - atomic - mirrors.aliyun.com
baseurl=http://mirrors.aliyun.com/centos-vault/altarch/$releasever/atomic/$basearch/
enabled=0
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos-vault/RPM-GPG-KEY-CentOS-7
[dotnet]
name=CentOS-$releasever - dotnet - mirrors.aliyun.com
baseurl=http://mirrors.aliyun.com/centos-vault/altarch/$releasever/dotnet/$basearch/
enabled=0
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos-vault/RPM-GPG-KEY-CentOS-7
[rt]
name=CentOS-$releasever - rt - mirrors.aliyun.com
baseurl=http://mirrors.aliyun.com/centos-vault/altarch/$releasever/rt/$basearch/
enabled=0
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos-vault/RPM-GPG-KEY-CentOS-7
[sclo-rh]
name=CentOS-$releasever - sclo-rh - mirrors.aliyun.com
baseurl=http://mirrors.aliyun.com/centos-vault/altarch/$releasever/sclo/$basearch/rh/
enabled=0
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos-vault/RPM-GPG-KEY-CentOS-7
[sclo-sclo]
name=CentOS-$releasever - sclo-sclo - mirrors.aliyun.com
baseurl=http://mirrors.aliyun.com/centos-vault/altarch/$releasever/sclo/$basearch/sclo/
enabled=0
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos-vault/RPM-GPG-KEY-CentOS-7
常见问题解决
1. 更换源后仍无法安装更新:检查 YUM 源是否配置正确,并确保执行了 `yum clean all` 和 `yum makecache`。
yum clean all
yum makecache
2. YUM 源速度慢:可以尝试切换到离自己服务器更近的镜像源,或者使用 CDN 支持的源。
总结
CentOS 7 停止维护后,及时更换 YUM 源可以保证系统持续获得安全和软件包更新。建议用户尽量选择国内镜像源,以保证更好的速度和稳定性。同时,也可以考虑升级到 CentOS Stream 或其他受支持的发行版,如 Rocky Linux 或 AlmaLinux,以获得长期的安全和功能支持。
- 最新
- 最热
只看作者