CentOS 6、Debian 9/10操作系统版本结束生命周期(EOL)后,Linux社区不再维护该操作系统版本,如果您还在使用CentOS 6、Debian 9/10操作系统则需要先切换源地址。本文将指导您如何切换源地址。
切换源地址
CentOS 6
背景信息
2020年11月30日CentOS 6 EOL。按照社区规则,CentOS 6的源地址http://mirror.centos.org/centos-6/
内容已移除,目前第三方的镜像站中均已移除CentOS 6的源。阿里云的源http://mirrors.cloud.aliyuncs.com
和http://mirrors.aliyun.com
也无法同步到CentOS 6的源。当您在阿里云上继续使用默认配置的CentOS 6的源会发生报错。报错示例如下图所示:
您可以通过以下步骤,在CentOS 6操作系统的ECS实例中将源配置按照网络环境不同进行切换。
yum源
专有网络VPC类型实例需切换为
http://mirrors.cloud.aliyuncs.com/centos-vault/6.10/
源经典网络类型实例需切换为
http://mirrors.aliyuncs.com/centos-vault/6.10/
源
epel源
专有网络VPC类型实例需切换为
http://mirrors.cloud.aliyuncs.com/epel-archive/6/
源经典网络类型实例需切换为
http://mirrors.aliyuncs.com/epel-archive/6/
源
本文主要说明ECS实例中的相关操作与配置。如果您的服务器不是ECS实例,需保证服务器具有公网访问能力,并且源地址http://mirrors.cloud.aliyuncs.com
需要替换为http://mirrors.aliyun.com
。例如,切换yum源为http://mirrors.aliyun.com/centos-vault/6.10/
;切换epel源为http://mirrors.aliyun.com/epel-archive/6/
。
操作步骤
登录CentOS 6系统的ECS实例。
具体操作,请参见ECS远程连接方式概述。
运行以下命令编辑
CentOS-Base.repo
文件。sudo vim /etc/yum.repos.d/CentOS-Base.repo
按i进入编辑模式,修改以下内容切换源。
请根据实例不同的网络类型进行修改,具体内容如下:
专有网络VPC类型实例
[base] name=CentOS-6.10 enabled=1 failovermethod=priority baseurl=http://mirrors.cloud.aliyuncs.com/centos-vault/6.10/os/$basearch/ gpgcheck=1 gpgkey=http://mirrors.cloud.aliyuncs.com/centos-vault/RPM-GPG-KEY-CentOS-6 [updates] name=CentOS-6.10 enabled=1 failovermethod=priority baseurl=http://mirrors.cloud.aliyuncs.com/centos-vault/6.10/updates/$basearch/ gpgcheck=1 gpgkey=http://mirrors.cloud.aliyuncs.com/centos-vault/RPM-GPG-KEY-CentOS-6 [extras] name=CentOS-6.10 enabled=1 failovermethod=priority baseurl=http://mirrors.cloud.aliyuncs.com/centos-vault/6.10/extras/$basearch/ gpgcheck=1 gpgkey=http://mirrors.cloud.aliyuncs.com/centos-vault/RPM-GPG-KEY-CentOS-6
经典网络类型实例
[base] name=CentOS-6.10 enabled=1 failovermethod=priority baseurl=http://mirrors.aliyuncs.com/centos-vault/6.10/os/$basearch/ gpgcheck=1 gpgkey=http://mirrors.aliyuncs.com/centos-vault/RPM-GPG-KEY-CentOS-6 [updates] name=CentOS-6.10 enabled=1 failovermethod=priority baseurl=http://mirrors.aliyuncs.com/centos-vault/6.10/updates/$basearch/ gpgcheck=1 gpgkey=http://mirrors.aliyuncs.com/centos-vault/RPM-GPG-KEY-CentOS-6 [extras] name=CentOS-6.10 enabled=1 failovermethod=priority baseurl=http://mirrors.aliyuncs.com/centos-vault/6.10/extras/$basearch/ gpgcheck=1 gpgkey=http://mirrors.aliyuncs.com/centos-vault/RPM-GPG-KEY-CentOS-6
编辑完成后,按Esc键,并输入
:wq
保存退出文件。运行以下命令编辑
epel.repo
文件。sudo vim /etc/yum.repos.d/epel.repo
按i进入编辑模式,修改以下内容切换源。
请根据实例不同的网络类型进行修改,具体内容如下:
专有网络VPC类型实例
[epel] name=Extra Packages for Enterprise Linux 6 - $basearch enabled=1 failovermethod=priority baseurl=http://mirrors.cloud.aliyuncs.com/epel-archive/6/$basearch gpgcheck=0 gpgkey=http://mirrors.cloud.aliyuncs.com/epel-archive/RPM-GPG-KEY-EPEL-6
经典网络类型实例
[epel] name=Extra Packages for Enterprise Linux 6 - $basearch enabled=1 failovermethod=priority baseurl=http://mirrors.aliyuncs.com/epel-archive/6/$basearch gpgcheck=0 gpgkey=http://mirrors.aliyuncs.com/epel-archive/RPM-GPG-KEY-EPEL-6
编辑完成后,按Esc键,并输入
:wq
保存退出文件。
yum源和epel源切换完成后,即可使用sudo yum install命令安装所需软件包。
如何在CentOS 6实例中切换源配置
使用自定义镜像创建新的ECS实例,在启动实例时cloud-init
会自动初始化系统的源配置。如果您后续需要通过已切换源的ECS实例创建自定义镜像,并且需要保留已切换的源配置,需要您在创建自定义镜像前,按照以下操作在已切换源的ECS实例中修改cloud-init
的配置文件/etc/cloud/cloud.cfg。
运行以下命令编辑/etc/cloud/cloud.cfg文件。
sudo vim /etc/cloud/cloud.cfg
按i进入编辑模式,使用
#
注释掉cloud_init_modules:
下的- source-address
模块。注释后,文件内的配置信息如下所示:
编辑完成后,按Esc键,并输入
:wq
保存退出文件。
Debian 9/10
背景信息
2020年07月18日Debian 9和2022年09月10日Debian 10分别EOL。按照社区规则,Debian 9/10的源地址内容已移除,目前第三方的镜像站中均已移除Debian 9/10的源。阿里云的源http://mirrors.cloud.aliyuncs.com
和http://mirrors.aliyun.com
也无法同步到Debian 9/10的源。当您在阿里云上继续使用默认配置的CentOS 6的源会发生报错。
您可以通过以下步骤,在Debian 9/10操作系统的ECS实例中根据网络环境切换源配置。
专有网络VPC类型实例使用
http://mirrors.cloud.aliyuncs.com/debian-archive/debian
源经典网络类型实例使用
http://mirrors.aliyuncs.com/debian-archive/debian
源
本文主要说明ECS实例中的相关操作与配置,如果您的服务器不是ECS实例,需保证服务器具有公网访问能力,请将源地址http://mirrors.cloud.aliyuncs.com
替换为http://mirrors.aliyun.com
。
操作步骤
登录Debian 9/10系统的ECS实例。
具体操作,请参见使用Workbench工具以SSH协议登录Linux实例。
运行以下命令编辑
sources.list
文件。sudo vim /etc/apt/sources.list
按i键进入编辑模式,修改以下内容切换源。
请根据实例不同的网络类型进行修改,具体内容如下:
专有网络VPC类型实例
Debian 9
deb http://mirrors.cloud.aliyuncs.com/debian-archive/debian stretch main contrib non-free deb http://mirrors.cloud.aliyuncs.com/debian-archive/debian-security stretch/updates main contrib non-free deb-src http://mirrors.cloud.aliyuncs.com/debian-archive/debian stretch main contrib non-free deb-src http://mirrors.cloud.aliyuncs.com/debian-archive/debian-security stretch/updates main contrib non-free
Debian 10
deb http://mirrors.cloud.aliyuncs.com/debian-archive/debian/ buster main non-free contrib deb http://mirrors.cloud.aliyuncs.com/debian-security buster/updates main deb http://mirrors.cloud.aliyuncs.com/debian-archive/debian/ buster-updates main non-free contrib deb-src http://mirrors.cloud.aliyuncs.com/debian-archive/debian/ buster main non-free contrib deb-src http://mirrors.cloud.aliyuncs.com/debian-security buster/updates main deb-src http://mirrors.cloud.aliyuncs.com/debian-archive/debian/ buster-updates main non-free contrib
经典网络类型实例
Debian 9
deb http://mirrors.aliyuncs.com/debian-archive/debian stretch main contrib non-free deb http://mirrors.aliyuncs.com/debian-archive/debian-security stretch/updates main contrib non-free deb-src http://mirrors.aliyuncs.com/debian-archive/debian stretch main contrib non-free deb-src http://mirrors.aliyuncs.com/debian-archive/debian-security stretch/updates main contrib non-free
Debian 10
deb http://mirrors.aliyuncs.com/debian-archive/debian/ buster main non-free contrib deb http://mirrors.aliyuncs.com/debian-security buster/updates main deb http://mirrors.aliyuncs.com/debian-archive/debian/ buster-updates main non-free contrib deb-src http://mirrors.aliyuncs.com/debian-archive/debian/ buster main non-free contrib deb-src http://mirrors.aliyuncs.com/debian-security buster/updates main deb-src http://mirrors.aliyuncs.com/debian-archive/debian/ buster-updates main non-free contrib
编辑完成后,按Esc键,并输入
:wq
保存退出文件。运行以下命令更新源缓存。
sudo apt update
源切换完成后,即可使用sudo apt install
命令安装所需软件包。
如何在Debian 9/10 ECS实例中切换源配置
使用自定义镜像创建新的ECS实例,在启动实例时cloud-init
会自动初始化系统的源配置。如果您后续需要通过已切换源的ECS实例创建自定义镜像,并且需保留已切换的源配置,请在创建自定义镜像前,按以下步骤修改cloud-init
的配置文件/etc/cloud/cloud.cfg。
运行以下命令编辑/etc/cloud/cloud.cfg文件。
sudo vim /etc/cloud/cloud.cfg
按i进入编辑模式,使用
#
注释掉cloud_init_modules:
下的- source-address
模块。注释后,文件内的配置信息如下所示:
编辑完成后,按Esc键,并输入
:wq
保存退出文件。
相关文档
建议您尽快将处于EOL的操作系统升级或者迁移到主流支持阶段的操作系统,请参见CentOS操作系统生命周期、Debian操作系统生命周期。