CentOS7 官方镜像源不可用问题解决方法

背景

我在安装python3.7.16时遇到了问题,发现是cenos7官方镜像源不可用。通过查找,用一下方式解决。

[root@yxf Python-3.7.16]# sudo yum makecache
Loaded plugins: fastestmirror
Determining fastest mirrors
Could not retrieve mirrorlist http://mirrorlist.centos.org?arch=x86_64&release=7&repo=sclo-rh error was
14: curl#6 - "Could not resolve host: mirrorlist.centos.org; Unknown error"


 One of the configured repositories failed (Unknown),
 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

我使用centos7时遇到了无法访问 mirrorlist.centos.org 的问题,因为CentOS 官方镜像源不可用。鉴于 CentOS 7 已经停止官方支持,推荐的解决方案是更换为更稳定的第三方镜像源,如阿里云、腾讯云或其他国内镜像源。

解决方案

1. 禁用有问题的仓库

首先,禁用导致问题的仓库(如 centos-sclo-rh),以避免它干扰其他操作:

sudo yum-config-manager --disable centos-sclo-rh
2. 配置阿里云镜像源

接下来,我们将配置阿里云镜像源来替代官方的 CentOS 镜像源。以下是具体步骤:

备份现有的仓库配置文件

在修改之前,建议备份现有的仓库配置文件:

sudo cp -a /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak
sudo cp -a /etc/yum.repos.d/CentOS-SCLo-scl.repo /etc/yum.repos.d/CentOS-SCLo-scl.repo.bak
修改基础仓库配置

编辑或替换 /etc/yum.repos.d/CentOS-Base.repo 文件的内容为阿里云提供的 CentOS 7 源:

sudo tee /etc/yum.repos.d/CentOS-Base.repo <<-'EOF'
[base]
name=CentOS-$releasever - Base - mirrors.aliyun.com
failovermethod=priority
baseurl=https://mirrors.aliyun.com/centos/$releasever/os/$basearch/
gpgcheck=1
enabled=1
gpgkey=https://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7

[updates]
name=CentOS-$releasever - Updates - mirrors.aliyun.com
failovermethod=priority
baseurl=https://mirrors.aliyun.com/centos/$releasever/updates/$basearch/
gpgcheck=1
enabled=1
gpgkey=https://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7

[extras]
name=CentOS-$releasever - Extras - mirrors.aliyun.com
failovermethod=priority
baseurl=https://mirrors.aliyun.com/centos/$releasever/extras/$basearch/
gpgcheck=1
enabled=1
gpgkey=https://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7

[centosplus]
name=CentOS-$releasever - Plus - mirrors.aliyun.com
failovermethod=priority
baseurl=https://mirrors.aliyun.com/centos/$releasever/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=https://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
EOF
添加 SCL 仓库配置

创建或编辑 /etc/yum.repos.d/CentOS-SCLo-scl.repo 文件,添加阿里云的 SCL 仓库配置:

sudo tee /etc/yum.repos.d/CentOS-SCLo-scl.repo <<-'EOF'
[centos-sclo-rh]
name=CentOS-7 - SCLo rh
baseurl=https://mirrors.aliyun.com/centos-vault/7.9.2009/sclo/x86_64/rh/
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-SIG-SCLo

[centos-sclo-sclo]
name=CentOS-7 - SCLo sclo
baseurl=https://mirrors.aliyun.com/centos-vault/7.9.2009/sclo/x86_64/sclo/
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-SIG-SCLo
EOF
3. 清理缓存并刷新元数据

完成上述配置后,清理所有缓存并重新加载仓库元数据:

sudo yum clean all
sudo yum makecache

总结

这样就可以解决该问题,继续使用centos7了。

<think>嗯,用户想找CentOS 7在2023年可用镜像源列表。首先,我需要回忆一下CentOS 7镜像源配置方法。根据之前的引用内容,用户已经知道一些基本的命令,比如用`sudo yum repolist enabled`查看镜像源列表,以及备份现有配置文件的操作。过这些引用都是比较旧的,可能已经过时了,特别是用户提到2023年的可用源,所以需要确认最新的镜像源信息。 首先,CentOS官方在2021年之后将重心转向CentOS Stream,所以很多原来的镜像源可能已经停止维护。过,还有一些社区维护的镜像源,比如阿里云、腾讯云、华为云、清华大学的镜像站等,这些通常还会提供CentOS 7的镜像。需要检查这些镜像站是否在2023年仍然支持CentOS 7。 接下来,用户可能需要手动替换`/etc/yum.repos.d/CentOS-Base.repo`文件中的baseurl,指向可用镜像源地址。例如,阿里云的镜像地址是`https://mirrors.aliyun.com/centos/7/...`,清华的是`https://mirrors.tuna.tsinghua.edu.cn/centos/7/...`。需要确保这些地址在2023年仍然有效。 另外,考虑到CentOS 7官方支持周期,其官方源可能在2024年结束维护,但2023年应该还在支持期内。过,很多镜像站可能会提前调整,所以需要确认最新的情况。可能还需要指导用户如何测试镜像源的速度和可用性,比如使用`yum makecache`测试更新缓存,或者用`curl`检查URL的可访问性。 用户可能遇到的问题包括镜像源无法连接、速度慢或者软件包全。因此,建议用户先备份原有的配置文件,如引用3提到的`sudo cp /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup`,然后再进行修改。同时,要提醒用户替换完成后运行`yum clean all`和`yum makecache`来更新缓存。 另外,用户可能需要知道如何验证镜像源是否生效,可以通过`yum repolist`查看已启用的仓库列表。如果遇到GPG密钥验证问题,可能需要导入新的密钥,但大多数镜像源会使用与官方相同的密钥,所以可能需要额外操作。 最后,生成相关问题时要考虑用户可能的后续需求,比如如何测试镜像速度、如何处理更新失败的情况,或者如何恢复到默认配置等。</think>### CentOS 7 可用镜像源列表(2023年更新) #### 操作步骤: 1. **备份原有配置** 执行命令: ```bash sudo cp /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup ``` 此操作用于防止配置错误导致系统异常[^3]。 2. **替换镜像源** 以下是2023年可用的主流镜像源地址(选择其一): - **阿里云镜像** ```bash sudo sed -e 's|^mirrorlist=|#mirrorlist=|g' \ -e 's|^#baseurl=http://mirror.centos.org|baseurl=https://mirrors.aliyun.com|g' \ -i.bak /etc/yum.repos.d/CentOS-*.repo ``` - **清华大学镜像** ```bash sudo sed -e 's|^mirrorlist=|#mirrorlist=|g' \ -e 's|^#baseurl=http://mirror.centos.org|baseurl=https://mi
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值