centos官方镜像源(`mirrorlist.centos.org`)已经彻底关闭,无法访问

复制代码
[root@192 ~]# sudo yum install -y yum-utils device-mapper-persistent-data lvm2
已加载插件:fastestmirror, product-id, search-disabled-repos, subscription-manager

This system is not registered with an entitlement server. You can use subscription-manager to register.

Loading mirror speeds from cached hostfile
Could not retrieve mirrorlist http://mirrorlist.centos.org?arch=x86_64&release=7&repo=sclo-rh error was
14: curl#7 - "Failed connect to mirrorlist.centos.org:80; 拒绝连接"


 One of the configured repositories failed (未知),
 and yum doesn't have enough cached data to continue. At this point the only
 safe thing yum can do is fail. There are a few ways to work "fix" this:

     1. Contact the upstream for the repository and get them to fix the problem.

     2. Reconfigure the baseurl/etc. for the repository, to point to a working
        upstream. This is most often useful if you are using a newer
        distribution release than is supported by the repository (and the
        packages for the previous distribution release still work).

     3. Run the command with the repository temporarily disabled
            yum --disablerepo=<repoid> ...

     4. Disable the repository permanently, so yum won't use it by default. Yum
        will then just ignore the repository until you permanently enable it
        again or use --enablerepo for temporary usage:

            yum-config-manager --disable <repoid>
        or
            subscription-manager repos --disable=<repoid>

     5. Configure the failing repository to be skipped, if it is unavailable.
        Note that yum will try to contact the repo. when it runs most commands,
        so will have to try and fail each time (and thus. yum will be be much
        slower). If it is a very temporary problem though, this is often a nice
        compromise:

            yum-config-manager --save --setopt=<repoid>.skip_if_unavailable=true

Cannot find a valid baseurl for repo: centos-sclo-rh/x86_64

这个报错很经典,是因为 CentOS 7 在 2024 年 6 月 30 日已经全面停止维护(EOL) ,官方镜像源(mirrorlist.centos.org)已经彻底关闭,无法访问了。

你需要将 yum 源全部替换为国内可用的存档镜像(vault)阿里/腾讯云镜像

请按以下步骤操作,先修复 yum 源,再安装 Docker

🛠️ 第一步:修复 CentOS 7.9 yum 源

由于 yum-utils 还没装上,我们要手动修改源配置文件。

  1. 备份原有源配置(好习惯):

    bash 复制代码
    sudo mv /etc/yum.repos.d /etc/yum.repos.d.bak
    sudo mkdir /etc/yum.repos.d
  2. 写入可用的阿里云 Vault 源 (CentOS 7 的归档源):

    直接复制下面整段命令,一次性执行,它会创建一个能用的 CentOS-Base.repo 文件。

    bash 复制代码
    sudo tee /etc/yum.repos.d/CentOS-Base.repo <<-'EOF'
    # CentOS-Base.repo
    [base]
    name=CentOS-7 - Base - mirrors.aliyun.com
    baseurl=http://mirrors.aliyun.com/centos-vault/7.9.2009/os/$basearch/
    gpgcheck=1
    gpgkey=http://mirrors.aliyun.com/centos-vault/7.9.2009/RPM-GPG-KEY-CentOS-7
    
    [updates]
    name=CentOS-7 - Updates - mirrors.aliyun.com
    baseurl=http://mirrors.aliyun.com/centos-vault/7.9.2009/updates/$basearch/
    gpgcheck=1
    gpgkey=http://mirrors.aliyun.com/centos-vault/7.9.2009/RPM-GPG-KEY-CentOS-7
    
    [extras]
    name=CentOS-7 - Extras - mirrors.aliyun.com
    baseurl=http://mirrors.aliyun.com/centos-vault/7.9.2009/extras/$basearch/
    gpgcheck=1
    gpgkey=http://mirrors.aliyun.com/centos-vault/7.9.2009/RPM-GPG-KEY-CentOS-7
    EOF
  3. 清理并重建 yum 缓存

    bash 复制代码
    sudo yum clean all
    sudo yum makecache

    这次执行应该不会报错了。


🚀 第二步:重新安装 Docker CE

源修好后,现在可以按正常流程走了。

  1. 安装依赖工具(刚才失败的那步,现在重试):

    bash 复制代码
    sudo yum install -y yum-utils device-mapper-persistent-data lvm2
  2. 添加 Docker 阿里云镜像源

    bash 复制代码
    sudo yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
  3. 安装 Docker CE

    bash 复制代码
    sudo yum install -y docker-ce docker-ce-cli containerd.io
  4. 启动 Docker 并设置开机自启

    bash 复制代码
    sudo systemctl start docker
    sudo systemctl enable docker
  5. 验证安装

    bash 复制代码
    docker version

⚠️ 特别提醒

  • 由于 CentOS 7 已停止维护,后续 yum install 安装任何软件都可能会遇到依赖包缺失的问题。如果出现这种情况,通常需要手动下载老版本的 rpm 包,会比较麻烦。
  • 强烈建议 :如果业务环境允许,可以考虑尽快迁移到 AlmaLinux 8/9Rocky Linux 8/9,它们是 CentOS 的最佳替代品,且仍在活跃维护中。

先按上面的步骤试一下,如果执行 yum makecache 时还有报错,可以把新的提示发给我。