【CentOS7】yum 报错:Could not retrieve mirrorlist http://mirrorlist.centos.org

前言
用yum install 命令去安装一些linux插件时报错,找了很久才解决,踩了很多坑,希望你们也不要踩,既不是大家搜索的网络问题,ping www.baidu.com可以通、DNS也设置了;
一、报错如下
1、报错内容如下

[root@node1 yum.repos.d]# yum install ifconfig
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
Could not retrieve mirrorlist http://mirrorlist.centos.org?arch=x86_64&release=7&repo=sclo-sclo 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-sclo/x86_64

2、原因
我们的服务器没法访问镜像的网络,所以我们需要配置正确的镜像源;
二、解决流程
1、进入 /etc/yum.repos.d文件目录;

cd /etc/yum.repos.d

2、备份文件
备份这三个文件就行了
(注意!!很多人只有 CentOS-Base.repo 文件,没有后两个,这也没问题,有几个备份几个,不用额外创建!)

在这里插入图片描述

3、编辑CentOS-Base.repo 文件(必选)
!!! 警告,在编辑文件的时候,你肯定是复制黏贴下面的内容的。但是,vim 编辑器会有个黏贴反应时间,所以大概率你在黏贴了内容之后,最开头的内容会缺少 1-5 个字符,你需要手动补全,下面的编辑也是一样 !!!

vi /etc/yum.repos.d/CentOS-Base.repo

全选替换:

[base]
name=CentOS-$releasever - Base
baseurl=https://mirrors.aliyun.com/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=https://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7

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

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

[centosplus]
name=CentOS-$releasever - Plus
baseurl=https://mirrors.aliyun.com/centos/$releasever/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=https://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7

4、编辑 CentOS-SCLo-scl-rh.repo 文件(如果没有这个文件,不用管)
编辑 CentOS-SCLo-scl-rh.repo 文件:

vi /etc/yum.repos.d/CentOS-SCLo-scl-rh.repo

替换内容: ***注意哦!!!***这里不是全部替换,只替换【centos-sclo-rh】下面的内容。

[centos-sclo-rh]
name=CentOS-$releasever - SCLo rh
baseurl=https://mirrors.aliyun.com/centos/$releasever/sclo/$basearch/rh/
gpgcheck=1
enabled=1
gpgkey=https://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7

5、编辑 CentOS-SCLo-scl.repo 文件(如果没有这个文件,不用管)
编辑 CentOS-SCLo-scl.repo 文件:

vi /etc/yum.repos.d/CentOS-SCLo-scl.repo

替换内容为:

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

6、清理缓存、重新加载缓存
①清理缓存

yum clean all
[root@node1 yum.repos.d]# yum clean all
Loaded plugins: fastestmirror, langpacks
Cleaning repos: base centos-sclo-rh centos-sclo-sclo extras updates
Cleaning up list of fastest mirrors

②加载缓存

yum makecache
[root@node1 yum.repos.d]# yum makecache
Loaded plugins: fastestmirror, langpacks
Determining fastest mirrors
base                                                                                                               | 3.6 kB  00:00:00
centos-sclo-rh                                                                                                     | 3.0 kB  00:00:00
centos-sclo-sclo                                                                                                   | 3.0 kB  00:00:00
extras                                                                                                             | 2.9 kB  00:00:00
updates                                                                                                            | 2.9 kB  00:00:00
(1/16): base/7/x86_64/group_gz                                                                                     | 153 kB  00:00:00
(2/16): base/7/x86_64/primary_db                                                                                   | 6.1 MB  00:00:24
(3/16): base/7/x86_64/filelists_db                                                                                 | 7.2 MB  00:00:31
(4/16): base/7/x86_64/other_db                                                                                     | 2.6 MB  00:00:10
(5/16): centos-sclo-rh/7/x86_64/primary_db                                                                         | 3.4 MB  00:00:15
(6/16): centos-sclo-sclo/7/x86_64/primary_db                                                                       | 300 kB  00:00:01
(7/16): centos-sclo-sclo/7/x86_64/other_db                                                                         | 185 kB  00:00:00
(8/16): extras/7/x86_64/filelists_db                                                                               | 305 kB  00:00:01
(9/16): extras/7/x86_64/primary_db                                                                                 | 253 kB  00:00:01
(10/16): centos-sclo-sclo/7/x86_64/filelists_db                                                                    | 935 kB  00:00:03
(11/16): extras/7/x86_64/other_db                                                                                  | 154 kB  00:00:00
(12/16): centos-sclo-rh/7/x86_64/other_db                                                                          | 1.6 MB  00:00:05
(14/16): updates/7/x86_64/filelists_db                 61% [=========                                                                     (13/16): centos-sclo-rh/7/x86_64/filelists_db   |  12 MB   00:49
(14/16): updates/7/x86_64/filelists_db                                                                             |  15 MB  00:01:09
(15/16): updates/7/x86_64/other_db                                                                                 | 1.6 MB  00:00:06
(16/16): updates/7/x86_64/primary_db                                                                               |  27 MB  00:01:50
Metadata Cache Created

到此!yum install 报错问题解决

当你在Linux系统上使用yum工具安装软件包时,遇到"Could not retrieve mirrorlist http://mirrorlist.centos.org"这样的错误,通常意味着yum无法从CentOS官方镜像列表获取可用的软件包源。这可能是由于以下几个原因: 1. **网络连接问题**:检查你的网络是否稳定,或者尝试重启路由器、清空DNS缓存。 2. **镜像站点不可达**:CentOS镜像地址可能暂时无法访问,你可以更换到其他的镜像源,比如国内的阿里云、清华大学等提供的镜像。 3. **防火墙限制**:确认系统防火墙或安全软件是否阻止了对特定网址的访问,如有需要,可以临时关闭或者添加规则允许访问。 4. **yum配置文件问题**:检查`/etc/yum.conf` 或者 `/etc/yum.repos.d/` 中的mirrors设置,看是否有正确的URL。 5. **时间同步问题**:确保系统的日期和时间与互联网的时间保持一致,因为一些服务器可能会基于时间戳验证请求。 解决这个问题的一个通用步骤是编辑yum的配置文件,更新或添加一个有效的镜像源。例如: ```bash sudo vi /etc/yum.repos.d/CentOS-Mirrors.list ``` 然后替换原有的镜像URL为可用的镜像,如: ``` [base] name=CentOS-$releasever - Base mirrorlist=https://mirrors.aliyun.com/repo/CentOS-\$releasever/$basearch/ enabled=1 gpgcheck=1 ``` 保存并关闭文件后,运行命令让yum更新新的配置: ```bash sudo yum makecache fast ``` 接着再次尝试安装软件包: ```bash sudo yum install [package-name] ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值