问题背景

修改yum源配置文件,删除yum源,又重新在另一台主机上复制了无问题的yum配置文件,导致yum源无法使用。

yum报错如下

[root@java152 ~]# yum makecache
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile* base: mirrors.tencentyun.com* extras: mirrors.tencentyun.com* updates: mirrors.tencentyun.com
http://mirrors.tencentyun.com/centos/%24releasever/os/x86_64/repodata/repomd.xml: [Errno 14] HTTP Error 404 - Not Found
#####报错信息是%24releasever 和404,意思就是无法解析腾讯云的$releasever变量。
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/.
base                                                                                                         | 1.0 kB  00:00:00
http://mirrors.tencentyun.com/centos/%24releasever/os/x86_64/repodata/repomd.xml: [Errno -1] Error importing repomd.xml for base: Damaged repomd.xml file
正在尝试其它镜像。
http://mirrors.tencentyun.com/centos/%24releasever/os/x86_64/repodata/repomd.xml: [Errno 12] Timeout on http://mirrors.tencentyun.com/centos/$releasever/os/x86_64/repodata/repomd.xml: (28, 'Connection timed out after 30000 milliseconds')
正在尝试其它镜像。
http://mirrors.tencentyun.com/centos/%24releasever/os/x86_64/repodata/repomd.xml: [Errno 12] Timeout on http://mirrors.tencentyun.com/centos/$releasever/os/x86_64/repodata/repomd.xml: (28, 'Connection timed out after 30001 milliseconds')
正在尝试其它镜像。
http://mirrors.tencentyun.com/centos/%24releasever/os/x86_64/repodata/repomd.xml: [Errno 12] Timeout on http://mirrors.tencentyun.com/centos/$releasever/os/x86_64/repodata/repomd.xml: (28, 'Connection timed out after 30001 milliseconds')
正在尝试其它镜像。
http://mirrors.tencentyun.com/centos/%24releasever/os/x86_64/repodata/repomd.xml: [Errno 12] Timeout on http://mirrors.tencentyun.com/centos/$releasever/os/x86_64/repodata/repomd.xml: (28, 'Connection timed out after 30001 milliseconds')
正在尝试其它镜像。
http://mirrors.tencentyun.com/centos/%24releasever/os/x86_64/repodata/repomd.xml: [Errno 12] Timeout on http://mirrors.tencentyun.com/centos/$releasever/os/x86_64/repodata/repomd.xml: (28, 'Connection timed out after 30001 milliseconds')
正在尝试其它镜像。
http://mirrors.tencentyun.com/centos/%24releasever/os/x86_64/repodata/repomd.xml: [Errno 12] Timeout on http://mirrors.tencentyun.com/centos/$releasever/os/x86_64/repodata/repomd.xml: (28, 'Connection timed out after 30001 milliseconds')
正在尝试其它镜像。One of the configured repositories failed (CentOS-$releasever - Base - mirrors.aliyun.com),and yum doesn't have enough cached data to continue. At this point the onlysafe 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 workingupstream. This is most often useful if you are using a newerdistribution release than is supported by the repository (and thepackages for the previous distribution release still work).3. Run the command with the repository temporarily disabledyum --disablerepo=base ...4. Disable the repository permanently, so yum won't use it by default. Yumwill then just ignore the repository until you permanently enable itagain or use --enablerepo for temporary usage:yum-config-manager --disable baseorsubscription-manager repos --disable=base5. 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 muchslower). If it is a very temporary problem though, this is often a nicecompromise: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.aliyun.com/centos/$releasever/os/x86_64/repodata/repomd.xml: [Errno 14] HTTP Error 404 - Not Found
http://mirrors.tencentyun.com/centos/$releasever/os/x86_64/repodata/repomd.xml: [Errno -1] Error importing repomd.xml for base: Damaged repomd.xml file
http://mirrors.tencentyun.com/$releasever/os/x86_64/repodata/repomd.xml: [Errno 12] Timeout on http://mirrors.tencentyun.com/centos/$releasever/os/x86_64/repodata/repomd.xml: (28, 'Connection timed out after 30000 milliseconds')
http://mirrors.tencentyun.com/centos/$releasever/os/x86_64/repodata/repomd.xml: [Errno 12] Timeout on http://mirrors.tencentyun.com/centos/$releasever/os/x86_64/repodata/repomd.xml: (28, 'Connection timed out after 30001 milliseconds')
http://mirrors.tencentyun.com/centos/$releasever/os/x86_64/repodata/repomd.xml: [Errno 12] Timeout on http://mirrors.tencentyun.com/centos/$releasever/os/x86_64/repodata/repomd.xml: (28, 'Connection timed out after 30001 milliseconds')
http://mirrors.tencentyun.com/centos/$releasever/os/x86_64/repodata/repomd.xml: [Errno 12] Timeout on http://mirrors.tencentyun.com/centos/$releasever/os/x86_64/repodata/repomd.xml: (28, 'Connection timed out after 30001 milliseconds')
http://mirrors.tencentyun.com/centos/$releasever/os/x86_64/repodata/repomd.xml: [Errno 12] Timeout on http://mirrors.tencentyun.com/centos/$releasever/os/x86_64/repodata/repomd.xml: (28, 'Connection timed out after 30001 milliseconds')
http://mirrors.tencentyun.com/centos/$releasever/os/x86_64/repodata/repomd.xml: [Errno 12] Timeout on http://mirrors.tencentyun.com/centos/$releasever/os/x86_64/repodata/repomd.xml: (28, 'Connection timed out after 30001 milliseconds')

1.查看DNS没有问题,且主机可以访问到外网。

2.重装yum服务,还是不能用。

yum-3.4.3-161.el7.centos.noarch.rpm
yum-metadata-parser-1.1.4-10.el7.x86_64.rpm
yum-plugin-fastestmirror-1.1.31-50.el7.noarch.rpm命令:rpm -ivh yum-3.4.3-161.el7.centos.noarch.rpm --nodeps --force           //nodeps 强制安装    force 避免依赖命令:rpm -ivh yum-metadata-parser-1.1.4-10.el7.x86_64.rpm --nodeps --force命令:rpm -ivh yum-plugin-fastestmirror-1.1.31-50.el7.noarch.rpm --nodeps --force

最终解决方法

上边一直提示 404 错误,然后我直接访问
http://mirrors.tencentyun.com/centos/$releasever/os/x86_64/repodata/repomd.xml
发现这个地址打不开

将腾讯yum源仓库的$releasever变量都改为7

命令:vim /etc/yum.repos.d/Centos-Base.repo
vim /etc/yum.repos.d/Centos-Epel.repo

命令::%s/$releasever/7/g #文本编辑器中的替换命令


修改完之后执行

# yum  makecache                         # OK

知识扩展:

问题分析一下
1、对比.repo文件和报错信息,可以发现$releasever变量没有被系统识别,在连接网络yum源的时候,变成了%24releasever。

2、查询资料得知,yum中的变量$releasever是由/etc/yum.conf中的distroverpkg定义的。centos-release为一个rpm包,所谓“distroverpkg=centos-release”的意思,其实是将 $releasever设置为centos-release 这个RPM包的版本号;打开yum的配置文件
vim /etc/yum.conf

通过rpm可以查询到改软件包并没有被安装:

解决思路

由于centos-release依赖关系比较复杂,约40个左右依赖包,我们可以修改yum源文件,把$releasever全部替换为7(上边已操作),修改以下爱两个配置文件。

# vim /etc/yum.repos.d/Centos-Base.repo   # 修改腾讯内部yum源Base仓库
# vim /etc/yum.repos.d/Centos-Epel.repo    # 修改腾讯内部yum源EPEL源仓库

此时yum可以正常使用,通过yum安装centos-release

命令:yum -y install centos-release

下载完centos-release源之后,再将base和epel源的7改回$releasever。yum makecache制作缓存yum即可恢复使用。

yum源无法使用,并报404 解决办法相关推荐

  1. 网页报404解决办法

    今天调试的时候报404错误了,这个时候我在后台requestMapping()映射的方法设置断点,该方法没有进去.如果你和我是一样的情况的话,试试以下办法: 1.仔细检查你的URL,每一个字母都和后台 ...

  2. sublime插件-OmniMarkupPreviewer浏览器打开报404解决办法

    Sublime Text > Preferences > Package Settings > OmniMarkupPreviewer > Settings - Default ...

  3. 解决2021年之后 CentOS 6 Yum 源无效 停止维护404错误

    解决2021年之后 CentOS 6 Yum 源无效 停止维护404错误 背景:2021年4月,最近在虚拟机上搞一些服务器相关的东西,发现yum install无效了,于是就各种百度啊....... ...

  4. java 报错404_Javaweb工程运行报错HTTP Status 404解决办法

    最近在学习jsp和servlet,避免不了的要和tomcat打交道,但tomcat经常会出现各式各样的错误,下面是我总结的一些常见的解决方法,希望对大家有用. 1.未部署web应用 2.url输入错误 ...

  5. Linux中设置Docker的yum源时,报-bash: yum-config-manager: command not found错误

    问题描述:在Linux环境中设置docker的yum源时,报-bash: yum-config-manager: command not found错误,如下图所示: 解决方法:这个是因为系统默认没有 ...

  6. Apache/php7.4/Mariadb安装和报错解决办法

    Apache和Mariadb安装基本都没有什么问题 PHP7.4安装过程中出现很多报错,网络大佬够已经给解决,下边安装步骤已经亲测: 需要安装apache的: 安装:yum -y install ht ...

  7. 关于在Swift5中无法使用String.characters的解决办法

    关于在Swift5中无法使用String.characters的解决办法 在swift5中已经舍弃了.characters的使用,如果用了则会出现报错 'characters' is unavaila ...

  8. mysql libs 5.6.27_mysql-5.6.27源码安装及错误解决办法

    环境:centos6.5.x86_64wget http://mirrors.sohu.com/mysql/MySQL-5.6/mysql-5.6.27.tar.gz yum install -y c ...

  9. 连接远程服务器CredSSP加密Oracle修正报错解决办法

    连接远程服务器CredSSP加密Oracle修正报错解决办法: 打开注册表,快捷输入 "regedit"(类似找命令提示符 输入 cmd 一样)找文件夹 路径:HKLM(缩写)\S ...

最新文章

  1. 数据库路由中间件MyCat - 使用篇(2)
  2. 搜索引擎网址收录地址
  3. CTFshow php特性 web132
  4. Windows中通过bat定时执行命令和mysqldump实现数据库备份
  5. 新Hibernate SessionFactory().getCurrentSession()猫腻
  6. iOS消息推送整体流程
  7. ASP.Net 获取服务器信息
  8. php flash 图片上传,Flash教程:flash+php实现图片上传
  9. 微信小程序将于 2017 年 1 月 9 日正式开放
  10. html中倒计时精确到毫秒,倒计时功能 精确到毫秒
  11. 转载:网关的概念以及形象的比喻
  12. 小程序用php的优势,小程序的特点及优势?
  13. 梯度下降来龙去脉附matlab代码
  14. python匿名函数表达式_在Python中使用lambda表达式进行赋值
  15. Netty4.0学习笔记系列之四:混合使用coder和handler
  16. mysql time over_mysql启动失败错误mysqld.service holdoff time over, scheduling restart.
  17. ROS(RouterOS)实现一线多拨+负载均衡(多图)
  18. 实验报告:定义一个名为MyRectangle的矩形类,完成如下要求
  19. SpringMVC配置文件中的各个组件
  20. 如何配置 ESXi 主机管理网络?

热门文章

  1. 为何要劝小白不学python_新手小白如何学好Python?
  2. Unity接入监控摄像头
  3. Linux的Bash——(五)数据流重导向
  4. 删除GitHub上的远程仓库
  5. Stripe文档(部分翻译)
  6. 关于hadoop集群搭建后,访问Browse Directory目录的权限问题
  7. 五一长假暴露了电动爹的真面目,而新能源汽车市场似乎也到了转折点
  8. 大神用Python 爬取了的心中女神的微信,是如何做到的?
  9. 打开Microsoft Visual Studio 2010报错:调用的目标发生了异常
  10. python绘制双折线图