欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 财经 > 产业 > CentOS 操作系统切换 YUM 源

CentOS 操作系统切换 YUM 源

2025/9/18 11:27:18 来源:https://blog.csdn.net/segwyang/article/details/143366812  浏览:    关键词:CentOS 操作系统切换 YUM 源

注意说明

本文档适用于 CentOS 操作系统的多个版本,包括 CentOS 6、CentOS 7、CentOS 8 以及 CentOS 8-stream。这意味着无论您正在使用哪个版本的 CentOS,您都可以参考本文档来获取相关的帮助和指导。这为广大 CentOS 用户提供了极大的便利,无需担心版本差异带来的使用障碍。

操作背景

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 Stream 8 构建工作结束时间:2024年5月31日。

在2024年5月31日之后,CentOS Stream 8 将被归档,将不再提供更新。

迁移/升级选项:

迁移到 CentOS Stream 9。

转换为 RHEL 8,在某些条件下使用免费许可证。

将转换为企业 Linux 生态系统中的另一个操作系统。几个项目已经从 CentOS 和 RHEL 源代码派生出新的操作系统。

这些软件包将在2024年5月31日之后归档至 vault.centos.org(腾讯云地址 Index of /centos-vault/)。

详情请参见:

CentOSStream

CentOSLinux8

操作步骤(以 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。

说明:

您可参见 内网服务 及 公网服务 判断实例需使用的源:

内网访问需切换为:http://mirrors.tencentyun.com/centos-vault/6.x/ 源。

公网访问需切换为:https://mirrors.tencent.com/centos-vault/6.x/ 源。

本文以实例操作系统为 CentOS 6.9,使用内网访问为例。修改完成后 CentOS-Base.repo 文件如下图所示:



配置如下,您可按需获取:

[extras]

gpgcheck=1

gpgkey=http://mirrors.tencentyun.com/centos/RPM-GPG-KEY-CentOS-6

enabled=1

baseurl=http://mirrors.tencentyun.com/centos-vault/6.9/extras/$basearch/

name=Qcloud centos extras - $basearch

[os]

gpgcheck=1

gpgkey=http://mirrors.tencentyun.com/centos/RPM-GPG-KEY-CentOS-6

enabled=1

baseurl=http://mirrors.tencentyun.com/centos-vault/6.9/os/$basearch/

name=Qcloud centos os - $basearch

[updates]

gpgcheck=1

gpgkey=http://mirrors.tencentyun.com/centos/RPM-GPG-KEY-CentOS-6

enabled=1

baseurl=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 - $basearch

failovermethod=priority

gpgcheck=1

gpgkey=http://mirrors.tencentyun.com/epel-archive/RPM-GPG-KEY-EPEL-6

enabled=1

baseurl=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



版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

热搜词