CentOS8不维护了如何更新源

公司IT给我虚拟机装了个CentOS8,因为CentOS项目已经不维护了,无法下载软件,所以需要更新下源。

CentOS中/etc/yum.repos.d/下包含很多源。

CentOS-Linux-AppStream.repo          CentOS-Linux-FastTrack.repo

CentOS-Linux-BaseOS.repo             CentOS-Linux-HighAvailability.repo

CentOS-Linux-ContinuousRelease.repo  CentOS-Linux-Media.repo

CentOS-Linux-Debuginfo.repo          CentOS-Linux-Plus.repo

CentOS-Linux-Devel.repo              CentOS-Linux-PowerTools.repo

CentOS-Linux-Extras.repo             CentOS-Linux-Sources.repo

要更新源的话,只能一个个更新。比较麻烦。我按照传统的办法更新了BaseOS.repo,往里添加了以下内容:

[base]

name=CentOS-8.5.2111 – Base – mirrors.aliyun.com

baseurl=http://mirrors.aliyun.com/centos-vault/8.5.2111/BaseOS/$basearch/os/

        http://mirrors.aliyuncs.com/centos-vault/8.5.2111/BaseOS/$basearch/os/

        http://mirrors.cloud.aliyuncs.com/centos-vault/8.5.2111/BaseOS/$basearch/os/

gpgcheck=0

gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-Official

#additional packages that may be useful

[extras]

name=CentOS-8.5.2111 – Extras – mirrors.aliyun.com

baseurl=http://mirrors.aliyun.com/centos-vault/8.5.2111/extras/$basearch/os/

        http://mirrors.aliyuncs.com/centos-vault/8.5.2111/extras/$basearch/os/

        http://mirrors.cloud.aliyuncs.com/centos-vault/8.5.2111/extras/$basearch/os/

gpgcheck=0

gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-Official

#additional packages that extend functionality of existing packages

[centosplus]

name=CentOS-8.5.2111 – Plus – mirrors.aliyun.com

baseurl=http://mirrors.aliyun.com/centos-vault/8.5.2111/centosplus/$basearch/os/

        http://mirrors.aliyuncs.com/centos-vault/8.5.2111/centosplus/$basearch/os/

        http://mirrors.cloud.aliyuncs.com/centos-vault/8.5.2111/centosplus/$basearch/os/

gpgcheck=0

enabled=0

gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-Official

[PowerTools]

name=CentOS-8.5.2111 – PowerTools – mirrors.aliyun.com

baseurl=http://mirrors.aliyun.com/centos-vault/8.5.2111/PowerTools/$basearch/os/

        http://mirrors.aliyuncs.com/centos-vault/8.5.2111/PowerTools/$basearch/os/

        http://mirrors.cloud.aliyuncs.com/centos-vault/8.5.2111/PowerTools/$basearch/os/

gpgcheck=0

enabled=0

gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-Official

[AppStream]

name=CentOS-8.5.2111 – AppStream – mirrors.aliyun.com

baseurl=http://mirrors.aliyun.com/centos-vault/8.5.2111/AppStream/$basearch/os/

        http://mirrors.aliyuncs.com/centos-vault/8.5.2111/AppStream/$basearch/os/

        http://mirrors.cloud.aliyuncs.com/centos-vault/8.5.2111/AppStream/$basearch/os/

之后报错提示重复的appstream定义。

Errors during downloading metadata for repository ‘appstream’:

  – Curl error (6): Couldn’t resolve host name for http://mirrorlist.centos.org/?release=8&arch=x86_64&repo=AppStream&infra=stock [Could not resolve host: mirrorlist.centos.org]

Error: Failed to download metadata for repo ‘appstream’: Cannot prepare internal mirrorlist: Curl error (6): Couldn’t resolve host name for http://mirrorlist.centos.org/?release=8&arch=x86_64&repo=AppStream&infra=stock [Could not resolve host: mirrorlist.centos.org]

更新centos源后appstream冲突报错提示

图 更新centos源后appstream冲突报错提示

我将报错提交给deepseek,才发现是appstream.repo中也有相关的定义,和我刚才更新的文件冲突。

DeepSeek还能给出解决方案,即移除默认的多个repo文件,然后在一个文件中定义,为了方便我直接贴上来:

  • 步骤 1:备份原有仓库配置

    sudo mkdir /etc/yum.repos.d/backup

    sudo mv /etc/yum.repos.d/CentOS-*.repo /etc/yum.repos.d/backup/


    • 步骤 2:下载阿里云仓库配置文件
    1. 下载 CentOS 8 阿里源基础配置
    2. sudo curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo
      • 注:因 CentOS 8 已停止维护,需使用历史版本(如 8.5.2111)的仓库配置。
    3. 可选:添加 EPEL 阿里源(扩展包)
    4. sudo curl -o /etc/yum.repos.d/epel.repo https://mirrors.aliyun.com/repo/epel-archive-8.repo

    • 步骤 3:清理并重建缓存

    sudo yum clean all        # 清理旧缓存

    sudo yum makecache        # 生成新缓存

    sudo yum repolist         # 检查仓库列表

    发表评论