CentOS8官方源失效 如何更换阿里源或升级至Centos Stream?

吾爱分享 建站运维评论1,894字数 3775阅读12分35秒阅读模式

来自阿里云官方的帮助文档(更新时间:2022-05-19 14:06)

CentOS 8操作系统版本结束了生命周期(EOL),Linux社区已不再维护该操作系统版本。建议您切换到Anolis或Alinux。如果您的业务过渡期仍需要使用CentOS 8系统中的一些安装包,请根据下文切换CentOS 8的源。

背景信息

2021年12月31日CentOS 8 EOL。按照社区规则,CentOS 8的源地址http://mirror.centos.org/centos/8/内容已移除,目前第三方的镜像站中均已移除CentOS 8的源。阿里云的源http://mirrors.cloud.aliyuncs.com和http://mirrors.aliyun.com也无法同步到CentOS 8的源。当您在阿里云上继续使用默认配置的CentOS 8的源会发生报错。报错示例如下图所示:CentOS8官方源失效 如何更换阿里源或升级至Centos Stream?

您可以通过下文的操作步骤,在CentOS 8操作系统的ECS实例中将源配置按照网络环境不同进行切换。文章源自 吾爱分享 吾爱分享网-https://www.wuaishare.cn/2261.html

  • yum源
    • 专有网络VPC类型实例需切换为http://mirrors.cloud.aliyuncs.com/centos-vault/8.5.2111/源。
    • 经典网络类型实例需切换为http://mirrors.aliyuncs.com/centos-vault/8.5.2111/源。
  • epel源:
    • 专有网络VPC类型实例需切换为http://mirrors.cloud.aliyuncs.com/epel-archive/8/源。
    • 经典网络类型实例需切换为http://mirrors.aliyuncs.com/epel-archive/8/源。

说明 本文主要说明ECS实例中的相关操作与配置。如果您的服务器不是ECS实例,需保证服务器具有公网访问能力,并且源地址http://mirrors.cloud.aliyuncs.com需要替换为http://mirrors.aliyun.com。例如,切换yum源为http://mirrors.aliyun.com/centos-vault/8.5.2111/;切换epel源为http://mirrors.aliyun.com/epel-archive/8/
文章源自 吾爱分享 吾爱分享网-https://www.wuaishare.cn/2261.html

操作步骤

  1. 登录CentOS 8系统的ECS实例。具体操作,请参见连接方式概述
  2. 运行以下命令备份之前的repo文件。
    rename '.repo' '.repo.bak' /etc/yum.repos.d/*.repo
  3. 运行以下命令下载最新的repo文件。
    wget http://mirrors.cloud.aliyuncs.com/repo/Centos-vault-8.5.2111.repo -O /etc/yum.repos.d/Centos-vault-8.5.2111.repo
    wget http://mirrors.cloud.aliyuncs.com/repo/epel-archive-8.repo -O /etc/yum.repos.d/epel-archive-8.repo
    说明 如果您的服务器具备公网访问能力,请将命令中的源地址http://mirrors.cloud.aliyuncs.com替换为http://mirrors.aliyun.com您也可以直接参考CentOS 镜像社区说明进行下载。
  4. 运行以下命令替换repo文件中的链接。
    sed -i 's/mirrors.cloud.aliyuncs.com/url_tmp/g' /etc/yum.repos.d/Centos-vault-8.5.2111.repo && sed -i 's/mirrors.aliyun.com/mirrors.cloud.aliyuncs.com/g' /etc/yum.repos.d/Centos-vault-8.5.2111.repo && sed -i 's/url_tmp/mirrors.aliyun.com/g' /etc/yum.repos.d/Centos-vault-8.5.2111.repo 
    sed -i 's/mirrors.aliyun.com/mirrors.cloud.aliyuncs.com/g' /etc/yum.repos.d/epel-archive-8.repo
  5. 运行以下命令重新创建缓存。
    yum clean all && yum makecache
    yum源和epel源切换完成后,即可使用yum install命令在实例上安装您所需要的软件包。

吾爱补充

上述操作步骤中的第三步只适用于阿里云的服务器,非阿里云服务器需要用下面代码文章源自 吾爱分享 吾爱分享网-https://www.wuaishare.cn/2261.html

wget https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo -O /etc/yum.repos.d/Centos-vault-8.5.2111.repo
wget https://mirrors.aliyun.com/repo/epel-archive-8.repo -O /etc/yum.repos.d/epel-archive-8.repo

因为mirrors.cloud.aliyuncs.com这个域名是阿里云内网专用的,非阿里云服务器无法解析,所以需要换成mirrors.aliyun.com这个公网可访问的域名。文章源自 吾爱分享 吾爱分享网-https://www.wuaishare.cn/2261.html

我这边在本地虚拟机测试后依然有问题,最后看了下面这个文章后解决的文章源自 吾爱分享 吾爱分享网-https://www.wuaishare.cn/2261.html

https://developer.aliyun.com/mirror/centos?spm=a2c4g.11186623.0.0.6b56786889zYU4文章源自 吾爱分享 吾爱分享网-https://www.wuaishare.cn/2261.html

Centos 8升级至Centos 8 Stream教程【宝塔】

背景:

2020年12月08日,CentOS官方宣布CentOS Linux项目将停止,并推出了Centos Stream项目。详情请看官方公告文章源自 吾爱分享 吾爱分享网-https://www.wuaishare.cn/2261.html

经此Centos8生命周期将缩短、2021年12月31日以后,CentOS Linux 8的使用者将无法获得包括问题修复和功能更新在内的任何软件维护和支持。文章源自 吾爱分享 吾爱分享网-https://www.wuaishare.cn/2261.html

对于宝塔面板的影响,可能将无法正常安装面板或面板内的环境软件等文章源自 吾爱分享 吾爱分享网-https://www.wuaishare.cn/2261.html

  • *Centos 7不受影响  官方将继续支持至2024年7月30日
  • *Centos 8 Sream 官方支持至2024年5月31日

对此宝塔官方的建议:

1.正在使用Centos 8的系统,转换至至Centos 8 Stream确保能获取修复和功能更新在内的任何软件维护和支持(亦可自行选择转换至Rocky/Alma/Anolis/Oracle linux 8)文章源自 吾爱分享 吾爱分享网-https://www.wuaishare.cn/2261.html

2.新安装机器建议使用Centos7安装宝塔面板,如想延用Centos8使用情况可以使用Rocky/Alma/Oracle linux 8。如需使用Debian或Ubuntu,建议选择Debian-11/Ubuntu-20安装面板
*宝塔面板均支持以上所述系统

Centos 8.3及以上用户可进入ssh执行以下命令转换至Centos 8 Stream系统(升级前建议做好服务器快照或数据备份)
#执行以下命令查看系统版本 为8.3及以上即可执行以下命令

cat /etc/redhat-release

CentOS8官方源失效 如何更换阿里源或升级至Centos Stream?

dnf --disablerepo '*' --enablerepo extras swap centos-linux-repos centos-stream-repos
dnf distro-sync

非Centos 8.3以上版本可参考以下教程替换已过期的yum源升级至Centos-8.5,然后再转换至Centos 8 Stream系统

  • 阿里云服务器替换教程:https://help.aliyun.com/document_detail/405635.html(替换后执行yum update更新系统至Centos 8.5 执行上述命令即可)
  • 腾讯云CVM服务器可以直接yum update更新至Centos 8.5
  • 其余机器可以参考以下进行替换可用yum源,如果不懂进行如何操作强烈建议联系服务器运营商提交工单进行升级,升级系统前务必做好服务器备份或快照。

#备份当前repo配置文件

\cp -rpa /etc/yum.repos.d/ /etc/yumBak

#注释mirrorlist

sed -i 's/mirrorlist/#mirrorlist/g' /etc/yum.repos.d/CentOS-*.repo

#指向baseurl至vault.epel.cloud存储库

sed -i 's|#baseurl=http://mirror.centos.org|baseurl=http://vault.epel.cloud|g' /etc/yum.repos.d/CentOS-*.repo

注:以上的默认存储库地址为mirror.centos.org
可以执行以下命令查看地址 查找appstream及baseos中的url地址
如果非mirror.centos.org将上面的sed指向命令中的mirror.centos.org替换为匹配的地址即可

grep baseurl /etc/yum.repos.d/CentOS-*.repo

CentOS8官方源失效 如何更换阿里源或升级至Centos Stream?

#升级系统至Centos 8.5

yum update

如有其他疑问或系统兼容性问题可前往原贴留言:原帖地址

吾爱分享

发表评论