解决CentOS7用yum安装软件显示错误:cannot find a valid baseurl for repo: base/7/x86_64

使用yun安装软件时有时会报repo文件的错误,, 主要问题出自于CentOS-Base.repo文件

 解决CentOS7用yum安装软件显示错误:cannot find a valid baseurl for repo: base/7/x86_64

解决方案:将这个文件后缀名修改使这个文件无效

[root@localhost ~]# cd /etc/yum.repos.d/

[root@localhost yum.repos.d]# mv CentOS-Base.repo CentOS-Base.repo.bak

[root@localhost yum.repos.d]# ls
CentOS-Base.repo.bak  CentOS-Debuginfo.repo    CentOS-Media.repo       CentOS-Vault.repo
CentOS-CR.repo            CentOS-fasttrack.repo      CentOS-Sources.repo

接下来可以继续进行yum的安装

===================================================================================

Centos7系统安装yum遇到的问题failure: repodata/repomd.xml from base: [Errno 256] No more mirrors to try. http:
原创果冻先生的专栏 最后发布于2018-06-10 17:50:03 阅读数 45807 收藏
展开
当遇到这个问题的时候,发现网上也有很多人也在问同样的问题。但是发现大家问的问题,很少有人能解释得很清楚,而且很多人的解决方法复杂且不能解决问题。我查了近二十篇博客和文章,对照做了,但是基本解决不了问题。

http://mirrors.ustc.edu.cn/help/centos.html

http://mirrors.163.com/.help/centos.html

https://blog.csdn.net/dreamchasering/article/details/77160477

https://blog.csdn.net/shaoqiufeng/article/details/78785806

https://blog.csdn.net/orangleliu/article/details/40588799

https://www.cnblogs.com/yizhichun/p/6339742.html

https://blog.csdn.net/james_jr10/article/details/78357600(这个好像很厉害,但是写得不清晰,误我前程啊)

https://segmentfault.com/q/1010000000716991/a-1020000000717340

你来看看,这些问题有多少人问?但是能解决实际问题的却很少!!!

下面由我给出一种最简单最有效的方法。耐心看下去哦!

问题所在:

[root@cit-server6-s1-372 yum.repos.d]# yum makecache
Loaded plugins: fastestmirror
base | 5.6 kB 00:00:00
http://mirrors.163.com/centos/7/os/x86_64/repodata/repomd.xml: [Errno -1] Error importing repomd.xml for base: Damaged repomd.xml file
Trying other mirror.


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. 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://mirrors.163.com/centos/7/os/x86_64/repodata/repomd.xml: [Errno -1] Error importing repomd.xml for base: Damaged repomd.xml file
[root@cit-server6-s1-372 yum.repos.d]#
错误所在的问题: 

主要问题在于yum源问题。

下面开始解决问题:

4.下载yum依赖包

[root@localhost ~]# wget http://vault.centos.org/7.2.1511/os/x86_64/Packages/yum-plugin-fastestmirror-1.1.31-34.el7.noarch.rpm
--2020-02-09 16:01:35-- http://vault.centos.org/7.2.1511/os/x86_64/Packages/yum-plugin-fastestmirror-1.1.31-34.el7.noarch.rpm
正在解析主机 vault.centos.org (vault.centos.org)... 208.100.23.71
正在连接 vault.centos.org (vault.centos.org)|208.100.23.71|:80... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:30600 (30K) [application/x-rpm]
正在保存至: “yum-plugin-fastestmirror-1.1.31-34.el7.noarch.rpm”

100%[==================================================================================================================>] 30,600 6.47KB/s 用时 4.6s

2020-02-09 16:01:40 (6.47 KB/s) - 已保存 “yum-plugin-fastestmirror-1.1.31-34.el7.noarch.rpm” [30600/30600])

[root@localhost ~]# wget http://vault.centos.org/7.2.1511/os/x86_64/Packages/yum-metadata-parser-1.1.4-10.el7.x86_64.rpm
--2020-02-09 16:01:43-- http://vault.centos.org/7.2.1511/os/x86_64/Packages/yum-metadata-parser-1.1.4-10.el7.x86_64.rpm
正在解析主机 vault.centos.org (vault.centos.org)... 208.100.23.71
正在连接 vault.centos.org (vault.centos.org)|208.100.23.71|:80... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:28348 (28K) [application/x-rpm]
正在保存至: “yum-metadata-parser-1.1.4-10.el7.x86_64.rpm”

100%[==================================================================================================================>] 28,348 2.16KB/s 用时 6.4s

2020-02-09 16:01:50 (4.34 KB/s) - 已保存 “yum-metadata-parser-1.1.4-10.el7.x86_64.rpm” [28348/28348])

[root@localhost ~]# ls
anaconda-ks.cfg initial-setup-ks.cfg yum-plugin-fastestmirror-1.1.31-34.el7.noarch.rpm 模板 图片 下载 桌面
core.8499 yum-metadata-parser-1.1.4-10.el7.x86_64.rpm 公共 视频 文档 音乐
[root@localhost ~]# mv yum-* /etc/yum.
yum.conf yum.repos.d/
[root@localhost ~]# mv yum-* /etc/yum.repos.d/
[root@localhost ~]# ls
anaconda-ks.cfg core.8499 initial-setup-ks.cfg 公共 模板 视频 图片 文档 下载 音乐 桌面
[root@localhost ~]# cd /etc/yum.repos.d/
[root@localhost yum.repos.d]# ls
a Centos-7.repo docker-ce.repo local.repo yum-metadata-parser-1.1.4-10.el7.x86_64.rpm yum-plugin-fastestmirror-1.1.31-34.el7.noarch.rpm
[root@localhost yum.repos.d]# rpm -ivh yum-metadata-parser-1.1.4-10.el7.x86_64.rpm
准备中... ################################# [100%]
软件包 yum-metadata-parser-1.1.4-10.el7.x86_64 已经安装
[root@localhost yum.repos.d]# rpm -ivh yum-plugin-fastestmirror-1.1.31-34.el7.noarch.rpm
准备中... ################################# [100%]
软件包 yum-plugin-fastestmirror-1.1.31-50.el7.noarch (比 yum-plugin-fastestmirror-1.1.31-34.el7.noarch 还要新) 已经安装
file /usr/lib/yum-plugins/fastestmirror.py from install of yum-plugin-fastestmirror-1.1.31-34.el7.noarch conflicts with file from package yum-plugin-fastestmirror-1.1.31-50.el7.noarch
file /usr/lib/yum-plugins/fastestmirror.pyc from install of yum-plugin-fastestmirror-1.1.31-34.el7.noarch conflicts with file from package yum-plugin-fastestmirror-1.1.31-50.el7.noarch
file /usr/lib/yum-plugins/fastestmirror.pyo from install of yum-plugin-fastestmirror-1.1.31-34.el7.noarch conflicts with file from package yum-plugin-fastestmirror-1.1.31-50.el7.noarch
[root@localhost yum.repos.d]# ls
a Centos-7.repo docker-ce.repo local.repo yum-metadata-parser-1.1.4-10.el7.x86_64.rpm yum-plugin-fastestmirror-1.1.31-34.el7.noarch.rpm
[root@localhost yum.repos.d]# cd a/
[root@localhost a]# ls
CentOS-Base.repo CentOS-CR.repo CentOS-Debuginfo.repo CentOS-fasttrack.repo CentOS-Media.repo CentOS-Sources.repo CentOS-Vault.repo
[root@localhost a]# cp CentOS-Base.repo CentOS-Base.repo.bak
[root@localhost a]# mv CentOS-Base.repo ../
[root@localhost a]# cd ../
[root@localhost yum.repos.d]# ls
a CentOS-Base.repo local.repo yum-plugin-fastestmirror-1.1.31-34.el7.noarch.rpm
Centos-7.repo docker-ce.repo yum-metadata-parser-1.1.4-10.el7.x86_64.rpm
[root@localhost yum.repos.d]# mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup

 [root@localhost yum.repos.d]# yum clean all

[root@localhost yum.repos.d]# yum makecache