Linux 运行 Yum mirrorlist.centos.org异常

一、Linux 版本

1.RedHat系列:Centos x86_64

2.CPU - 2核 内存 - 2GB

二、Linux 输入 yum 异常报错

[root@VM-8-15-centos ~]# yum update

报异常

Loaded plugins: fastestmirror, langpacks
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

三、原因分析与解决

1.原因

CentOS7的SCL源在2024年6月30日就停止维护了。 当scl源里面默认使用了centos官方的地址http://mirrorlist.centos.org就无法连接,这里我们需要替换为阿里云的默认地址https://mirrors.aliyun.com

2.解决

(1). 找到 CentOS-SCLo-scl.repo 和 CentOS-SCLo-scl-rh.repo

[root@VM-8-15-centos yum.repos.d]# cd /etc/yum.repos.d/
[root@VM-8-15-centos yum.repos.d]# ll
total 56
-rw-r--r-- 1 root root 2523 Nov 12 14:13 CentOS-Base.repo
-rw-r--r-- 1 root root  614 Nov 12 14:13 CentOS-Base.repo.bak
-rw-r--r-- 1 root root 1309 May 21 22:48 CentOS-CR.repo
-rw-r--r-- 1 root root  649 May 21 22:48 CentOS-Debuginfo.repo
-rw-r--r-- 1 root root  230 Nov  8 15:32 CentOS-Epel.repo
-rw-r--r-- 1 root root  314 Nov 12 14:22 CentOS-fasttrack.repo
-rw-r--r-- 1 root root  630 May 21 22:48 CentOS-Media.repo
-rw-r--r-- 1 root root 1063 Nov 12 14:37 CentOS-SCLo-scl.repo
-rw-r--r-- 1 root root 1034 Nov 12 14:38 CentOS-SCLo-scl-rh.repo
-rw-r--r-- 1 root root 1331 May 21 22:48 CentOS-Sources.repo
-rw-r--r-- 1 root root 9454 May 21 22:48 CentOS-Vault.repo
-rw-r--r-- 1 root root  616 May 21 22:48 CentOS-x86_64-kernel.repo

(2)将里面的 mirrorlist=  注释掉,再将baseurl= 取消注释,并把baseurl的域名地址改为阿里云 https://mirrors.aliyun.com

CentOS-SCLo-scl.repo 文本修改后如下


[centos-sclo-sclo]
name=CentOS-7 - SCLo sclo
# baseurl=http://mirror.centos.org/centos/7/sclo/$basearch/sclo/
#mirrorlist=http://mirrorlist.centos.org?arch=$basearch&release=7&repo=sclo-sclo
baseurl=http://mirrors.aliyun.com/centos/7/sclo/$basearch/sclo/
gpgcheck=1
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-SIG-SCLo

[centos-sclo-sclo-testing]
name=CentOS-7 - SCLo sclo Testing
baseurl=http://buildlogs.centos.org/centos/7/sclo/$basearch/sclo/
gpgcheck=0
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-SIG-SCLo

[centos-sclo-sclo-source]
name=CentOS-7 - SCLo sclo Sources
baseurl=http://vault.centos.org/centos/7/sclo/Source/sclo/
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-SIG-SCLo

[centos-sclo-sclo-debuginfo]
name=CentOS-7 - SCLo sclo Debuginfo
baseurl=http://debuginfo.centos.org/centos/7/sclo/$basearch/
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-SIG-SCLo

CentOS-SCLo-scl-rh.repo 文本修改如下

[centos-sclo-rh]
name=CentOS-7 - SCLo rh
#baseurl=http://mirror.centos.org/centos/7/sclo/$basearch/rh/
#mirrorlist=http://mirrorlist.centos.org?arch=$basearch&release=7&repo=sclo-rh
baseurl=http://mirrors.aliyun.com/centos/7/sclo/$basearch/rh/
gpgcheck=1
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-SIG-SCLo

[centos-sclo-rh-testing]
name=CentOS-7 - SCLo rh Testing
baseurl=http://buildlogs.centos.org/centos/7/sclo/$basearch/rh/
gpgcheck=0
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-SIG-SCLo

[centos-sclo-rh-source]
name=CentOS-7 - SCLo rh Sources
baseurl=http://vault.centos.org/centos/7/sclo/Source/rh/
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-SIG-SCLo

[centos-sclo-rh-debuginfo]
name=CentOS-7 - SCLo rh Debuginfo
baseurl=http://debuginfo.centos.org/centos/7/sclo/$basearch/
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-SIG-SCLo

(3)测试 

运行 yum update 就成功了

[root@VM-8-15-centos yum.repos.d]# yum update

### 解决方案 `mirrorlist.centos.org` 是 CentOS 官方镜像列表的服务地址,但由于某些原因可能无法正常解析。以下是针对该问题的具体解决方案: #### 方法一:修改 `baseurl` 配置文件 可以手动替换掉默认的 `mirrorlist` 地址为具体的镜像源 URL。 1. 编辑 `/etc/yum.repos.d/CentOS-Base.repo` 文件: ```bash vi /etc/yum.repos.d/CentOS-Base.repo ``` 2. 将所有的 `[base]`, `[appstream]`, `[extras]` 等部分中的 `mirrorlist=` 替换为具体可用的 `baseurl=` 地址。例如: ```ini baseurl=http://vault.centos.org/7.9.2009/os/$basearch/ ``` 3. 清除缓存并重建索引: ```bash sudo yum clean all sudo yum makecache ``` 此方法通过指定固定的镜像站点来绕过不可用的 `mirrorlist`[^1]。 --- #### 方法二:更换国内镜像源 如果官方镜像源不稳定,可以选择更稳定的国内镜像源(如阿里云、腾讯云等)。以下以阿里云为例说明操作步骤: 1. 备份原始配置文件: ```bash mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup ``` 2. 下载新的阿里云镜像配置文件: ```bash wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo ``` 3. 更新缓存: ```bash sudo yum clean all sudo yum makecache ``` 这种方法利用了国内加速镜像,通常能显著提升下载速度和稳定性[^2]。 --- #### 方法三:DNS 设置调整 有时 DNS 服务器可能导致域名解析失败。可以通过更改系统的 DNS 来解决问题。 1. 修改 `/etc/resolv.conf` 文件: ```bash nameserver 8.8.8.8 nameserver 8.8.4.4 ``` 或者使用国内公共 DNS: ```bash nameserver 114.114.114.114 nameserver 223.5.5.5 ``` 2. 测试网络连通性和域名解析能力: ```bash ping mirrorlist.centos.org nslookup mirrorlist.centos.org ``` 如果能够成功解析,则尝试再次运行 `yum` 命令测试效果[^3]。 --- #### 方法四:升级到 RHEL 或其他替代发行版 由于 CentOS 已停止更新维护 (EOL),建议考虑迁移到 Red Hat Enterprise Linux (RHEL) 或其社区版本 AlmaLinux、Rocky Linux。这些系统提供了长期支持和技术保障。 执行迁移前需备份重要数据,并按照目标操作系统文档逐步完成切换过程。 --- ```python print("以上四种方式均可有效解决 'cannot resolve mirrorlist.centos.org' 的问题,请根据实际需求选择适合的方法实施修复。") ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值