【centos7】Could not retrieve mirrorlist http://mirrorlist.centos.org/?release=7&arch=x86_64&repo=os&i

本文讲述了在CentOS7中遇到yum安装时关于mirrorlist和baseurl报错的解决方案,包括修改仓库配置、设置DNS和恢复默认设置等步骤。

centos7中yum报错:

已加载插件:fastestmirror
Could not retrieve mirrorlist http://mirrorlist.centos.org/?release=7&arch=x86_64&repo=os&infra=stock error was
14: curl#6 - "Could not resolve host: mirrorlist.centos.org; 未知的错误"


 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. Disable the repository, 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>

     4. 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

解决办法:

1、修改文件,vi /etc/yum.repos.d/CentOS-Base.repo ,将文件中mirrorlist开头的语句注释,将baseurl开头的语句注释删掉。

2、检查修改配置文件,vi /etc/resolv.conf:

nameserver 8.8.8.8   #定义DNS服务器的IP地址
search localdomain    #定义域名的搜索列表

3、之后执行yum -y update就不会报错了

4、恢复 CentOS-Base.repo到原始状态(baseurl注释掉,mirrorList取消注释)

改完上述还是报错:

[root@localhost ~]# yum -y update
已加载插件:fastestmirror
http://mirror.centos.org/centos/7/os/x86_64/repodata/repomd.xml: [Errno 14] HTTP Error 404 - Not Found
正在尝试其它镜像。


 One of the configured repositories failed (CentOS-7 - Base),
 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. Disable the repository, 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 base

     4. 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=base.skip_if_unavailable=true

failure: repodata/repomd.xml from base: [Errno 256] No more mirrors to try.
http://mirror.centos.org/centos/7/os/x86_64/repodata/repomd.xml: [Errno 14] HTTP Error 404 - Not Found

1、编辑修改网卡配置文件,追加DNS

vi /etc/sysconfig/network-scripts/ifcfg-eno16777984

修改域名:

DNS=8.8.8.8

2、检验测试:

运行命令ping mirrors.aliyun.com,展示如下结果表示域名已可用

3、备份:

mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup

4、 yum源 没有配置,只能更新国内镜像源,但是没有wget,可以用curl更新国内镜像,使用阿里镜像http://mirrors.aliyun.com/repo/Centos-7.repo。

curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo

5、yum clean all  #清理缓存

yum makecache   #设置缓存

在尝试访问 `http://mirrorlist.centos.org?arch=x86_64` 时出现 `Could not retrieve mirrorlist` 错误,通常与网络连接、DNS 解析或镜像源配置相关。以下是可能的原因及解决方案: ### 1. 网络连接问题 确保服务器能够正常访问外部网络。可以通过以下命令测试网络连通性: ```bash ping mirrorlist.centos.org ``` 如果无法解析或连接,可能是 DNS 配置问题。可以尝试修改 `/etc/resolv.conf` 文件,添加公共 DNS: ```bash nameserver 8.8.8.8 nameserver 8.8.4.4 ``` 然后再次尝试访问镜像列表。 ### 2. 镜像源配置问题 由于 CentOS 7 的官方支持已经结束,部分仓库已被移至归档库,导致默认的镜像源地址失效。可以将镜像源更换为 CentOS Vault 或国内镜像源(如阿里云、清华源等)。 #### 修改为 CentOS Vault 源: 编辑 `/etc/yum.repos.d/CentOS-Base.repo` 文件,替换为以下内容: ```ini [base] name=CentOS-$releasever - Base baseurl=http://vault.centos.org/7.9.2009/os/x86_64/ gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7 #released updates [updates] name=CentOS-$releasever - Updates baseurl=http://vault.centos.org/7.9.2009/updates/x86_64/ gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7 #additional packages that may be useful [extras] name=CentOS-$releasever - Extras baseurl=http://vault.centos.org/7.9.2009/extras/x86_64/ gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7 ``` ### 3. 清除 YUM 缓存并重建 执行以下命令清除缓存并重新生成: ```bash yum clean all yum makecache ``` ### 4. 检查系统时间 系统时间不正确可能导致 SSL 证书验证失败,进而影响镜像源访问。可以通过以下命令同步时间: ```bash timedatectl set-ntp true ``` ### 5. 使用代理访问(如适用) 如果服务器处于内网环境,可能需要配置 HTTP 代理。在 `/etc/yum.conf` 中添加: ```ini proxy=http://your.proxy.server:port ``` 完成上述配置后,再次尝试执行 `yum` 命令,查看是否解决了 `Could not retrieve mirrorlist` 的问题。 ---
评论 2
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值