Could not retrieve mirrorlist http://mirrorlist.centos.org/?release=7&arch=x86_64&repo=os&infra=stoc

本文介绍了在使用yum进行系统更新时遇到的连接超时错误,并提供了详细的解决步骤,包括修改resolv.conf文件来更换DNS服务器。

今天在使用yum安装文件时,出现了以下问题:

root@localhost opt]# yum update
Loaded plugins: fastestmirror
Could not retrieve mirrorlist http://mirrorlist.centos.org/?release=7&arch=x86_64&repo=os&infra=stock error was
12: Timeout on http://mirrorlist.centos.org/?release=7&arch=x86_64&repo=os&infra=stock: (28, 'Resolving timed out after 30568 milliseconds')


 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: base/7/x86_64

解决方案:
编辑/etc/resolv.conf这个文件,在文件末尾添加nameserver 114.114.114.114这即可
命令:

vim /etc/resolv.conf

修改后的文件如下图:
这里写图片描述

参考链接:http://www.landui.com/help/show-2739.html

### 问题分析 用户在使用 `yum` 命令时遇到错误,提示 `Could not retrieve mirrorlist http://mirrorlist.centos.org`,具体错误信息为: ``` error was 14: curl#6 - “Could not resolve host: mirrorlist.centos.org; Unknown error” ``` 此错误表明系统无法解析 `mirrorlist.centos.org` 的主机地址,从而无法获取镜像列表。根据提供的引用,可能的原因包括网络配置问题、DNS 解析失败、或者镜像服务器已不可用。 --- ### 解决方案 #### 1. 检查网络连接和 DNS 配置 确保服务器的网络连接正常,并且 DNS 配置正确。可以通过以下命令测试网络连通性和 DNS 解析: ```bash ping 8.8.8.8 nslookup mirrorlist.centos.org ``` 如果 `ping` 或 `nslookup` 失败,则需要检查网络接口是否启用,并调整 `/etc/resolv.conf` 文件中的 DNS 设置。例如: ```bash nameserver 8.8.8.8 nameserver 8.8.4.4 ``` #### 2. 更换镜像源 如果 `mirrorlist.centos.org` 已不可用,可以手动配置使用其他镜像源。例如,将默认的镜像源替换为阿里云或清华源: **阿里云 CentOS 7 源配置示例:** ```bash mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo yum clean all yum makecache ``` **清华源 CentOS 7 配置示例:** ```bash mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.tuna.tsinghua.edu.cn/help/centos/ yum clean all yum makecache ``` #### 3. 检查 YUM 配置并跳过不可用仓库 如果某些仓库暂时不可用,可以配置 `yum` 跳过这些仓库,避免每次执行命令时都尝试连接: ```bash yum-config-manager --save --setopt=<repoid>.skip_if_unavailable=true ``` 例如,如果仓库 ID 为 `base`,则命令为: ```bash yum-config-manager --save --setopt=base.skip_if_unavailable=true ``` #### 4. 使用 Vault 源(适用于旧版本 CentOS) 对于已停止官方支持的 CentOS 版本(如 CentOS 6),可以使用 `vault.centos.org` 作为替代源: ```bash mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup echo '[base] name=CentOS-$releasever - Base baseurl=https://vault.centos.org/6.10/os/x86_64/ gpgcheck=1 gpgkey=https://vault.centos.org/6.10/os/x86_64/RPM-GPG-KEY-CentOS-6' > /etc/yum.repos.d/CentOS-Base.repo ``` #### 5. 检查 SELinux 和防火墙设置 SELinux 或防火墙可能阻止了 `yum` 访问外部网络。可以临时禁用 SELinux 或关闭防火墙进行测试: ```bash setenforce 0 systemctl stop firewalld ``` 如果问题解决,则需要调整 SELinux 或防火墙规则以允许 `yum` 正常运行。 --- ###
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值