一、操作背景
CentOS 6、7、8、8-stream 操作系统当前已进入版本生命周期终止状态(EOL),Linux 社区不再维护该操作系统版本。按照社区规则,对应版本的源地址 http://mirror.centos.org/centos/x/ 内容已移除,且目前第三方的镜像站中均已移除相关仓库。腾讯云的源 https://mirrors.tencent.com/ 和http://mirrors.tencentyun.com/ 也无法同步到 ,当你在腾讯云上继续使用旧路径的源会发生报错。
注意:说明(以 CentOS Stream 8为例):
二、操作步骤(以 centos 6为例)
1. 使用标准方式登录 Linux 实例(推荐)。你也可以根据实际操作习惯,选择其他不同的登录方式:
·使用远程登录软件登录 Linux 实例
·使用 SSH 登录 Linux 实例
2. 执行以下命令,查看当前操作系统 CentOS 版本。
cat /etc/centos-release
返回结果如下所示,则说明当前操作系统版本为 CentOS 6.9。
3. 执行以下命令,编辑 CentOS-Base.repo 文件。
vim /etc/yum.repos.d/CentOS-Base.repo
4. 按 i 进入编辑模式,根据 CentOS 版本及网络环境修改 baseurl。
注意:说明:
注意:你可参见 内网服务 及 公网服务 判断实例需使用的源:
这篇以实例操作系统为 CentOS 6.9,使用内网访问为例。修改完成后 CentOS-Base.repo 文件如下:
配置如下,你可按需获取:
[extras]gpgcheck=1gpgkey=http://mirrors.tencentyun.com/centos/RPM-GPG-KEY-CentOS-6enabled=1baseurl=http://mirrors.tencentyun.com/centos-vault/6.9/extras/$basearch/name=Qcloud centos extras – $basearch[os]gpgcheck=1gpgkey=http://mirrors.tencentyun.com/centos/RPM-GPG-KEY-CentOS-6enabled=1baseurl=http://mirrors.tencentyun.com/centos-vault/6.9/os/$basearch/name=Qcloud centos os – $basearch[updates]gpgcheck=1gpgkey=http://mirrors.tencentyun.com/centos/RPM-GPG-KEY-CentOS-6enabled=1baseurl=http://mirrors.tencentyun.com/centos-vault/6.9/updates/$basearch/name=Qcloud centos updates – $basearch
5. 按 ESC 输入 :wq 后,按 Enter 保存修改。
6. 执行以下命令,修改 CentOS-Epel.repo 文件。
vim /etc/yum.repos.d/CentOS-Epel.repo
7. 按 i 进入编辑模式,根据实例网络环境修改 baseurl。
这篇以使用内网访问为例,则将 baseurl=http://mirrors.tencentyun.com/epel/$releasever/$basearch/ 修改为 baseurl=http://mirrors.tencentyun.com/epel-archive/6/$basearch/ 即可。修改完成后如下:
配置如下,你可按需获取:
[epel]name=epel for redhat/centos $releasever – $basearchfailovermethod=prioritygpgcheck=1gpgkey=http://mirrors.tencentyun.com/epel-archive/RPM-GPG-KEY-EPEL-6enabled=1baseurl=http://mirrors.tencentyun.com/epel-archive/6/$basearch/
8. 按 ESC 输入 :wq 后,按 Enter 保存修改。
9. 至此已完成 YUM 源切换,你可使用 yum install 命令安装所需软件。
三、一键配置(操作前请清理 /etc/yum.repos.d/ 目录下的残留配置)
CentOS 7 使用命令:
curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.tencent.com/repo/centos7_base.repo
CentOS 8 使用命令:
curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.tencent.com/repo/centos8_base.repo
CentOS 8-Stream 使用命令:
curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.tencent.com/repo/centos8-stream.repo