centOS7下载软件出现问题及解决办法

项目场景:

已经在vmware中建立新的虚拟机,并已完成centOS7系统的安装,通过yum指令下载安装软件。


问题描述

在通过yum指令进行软件包的下载及安装时报错
例如:输入以下指令下载安装openssl-devel:

[root@localhost ~]# yum install openssl-devel

系统出现以下报错内容:

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

注意查看最后报错提示如下:

Cannot find a valid baseurl for repo: base/7/x86_64

解决方法:

1、首先确认自己的系统是否可以连接外网(通过ping外网确认)

ping www.baidu.com

在这里插入图片描述
如果显示如上,则表明可正常连接外网,可进入下一步;如果出现报错,则需要进行虚拟机的联网设置,关于虚拟机联网方法,读者可查阅参考其他博客(笔者参考博客链接

2、在确认可连接外网情况下,使用yum指令安装,依旧出现以上报错,考虑为CentOS-Base.repo有问题,需要进行更改。

  • 备份原CentOS-Base.repo文件:
mv /etc/yum.repos.d/CentOS-Base.repo  /etc/yum.repos.d/CentOS-Base.repo.bak
  • 查看本地源状态情况:
yum repolist all

返回以下结果:
在这里插入图片描述
可以看到全部为禁用状态

  • 通过阿里或网易镜像库链接下载对应版本repo文件
网易镜像库
https://mirrors.163.com/.help/centos.html
 
阿里云镜像库
http://mirrors.aliyun.com/repo/
  • 将下载的文件传入centOS的repos文件目录中:
    可通过finalshell直接上传到对应文件夹(finalshell下载及安装、连接虚拟机可自行查阅,也可参考以下链接:笔者参考链接
    在这里插入图片描述

  • 再次查询本地源情况:

yum repolist all

查询结果如下(已有启用状态的本地源):

在这里插入图片描述

  • 生成缓存:
yum clean all
yum makecache
  • 再次尝试下载安装包:
yum install -y gcc tcl

返回结果如下:

已加载插件:fastestmirror
Repository base is listed more than once in the configuration
Repository updates is listed more than once in the configuration
Repository extras is listed more than once in the configuration
Repository centosplus is listed more than once in the configuration
Loading mirror speeds from cached hostfile
http://mirrors.163.com/centos/7/os/x86_64/repodata/repomd.xml: [Errno 14] HTTP Error 404 - Not Found
正在尝试其它镜像。
To address this issue please refer to the below wiki article 

https://wiki.centos.org/yum-errors

If above article doesn't help to resolve this issue please use https://bugs.centos.org/.



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

     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 base
        or
            subscription-manager repos --disable=base

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

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

注意最后报错内容:

http://mirrors.163.com/centos/7/os/x86_64/repodata/repomd.xml: [Errno 14] HTTP Error 404 - Not Found

该报错表示该链接找不到页面,并且查询该链接确实出现404提示结果。
该链接对应的镜像源为网易镜像源(http://mirrors.163.com),并且根据链接递层查询,确实在http://mirrors.163.com/centos/7/之后找不到os目录,因此该镜像源无法使用(其他本地源错误也可根据这种方法判断是否镜像源问题)。
笔者由于下载在前述步骤上传了两个镜像源(网易和阿里云),因此我将出现错误的网易镜像源从文件中删除,只保留新增的阿里云镜像源。

  • 使用yum命令下载目标软件包:
yum install -y gcc tcl

cd mysql
yum install openssl-devel

执行后可正常下载软件包,问题得到解决。

  • 20
    点赞
  • 13
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值