今天被开发告知一台测试服务器使用yum命令出现报错,无法正常安装、更新软件。
登上服务器运行yum提示:
[root@Erp-Test1 ~]# yum update yum Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile 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: base/$releasever/x86_64 [root@Erp-Test1 ~]#
网上查询到的解决方法大多是说跟DNS解析出现问题关系较大,但此机和其它服务器配置相同,域名解析也正常。
说明不是此问题。
后来,在stackoverrun上看见了关于此问题的解决方式。
其是由于centos-release包丢失,导致系统yum变量$releasever出错。
使用命令检测包是否存在:
[root@Erp-Test1 ~]# rpm -qi centos-release package centos-release is not installed [root@Erp-Test1 ~]#
这台机上显示包未安装,而正常系统上会显示出包信息:
解决此问题,首先先定位系统的版本(上面另一台机其实已经显示了CentOS 7.5):
[root@Erp-Test1 ~]# cat /etc/redhat-release CentOS Linux release 7.5.1804 (Core) [root@Erp-Test1 ~]#
从官方repo源中获取centos-release包(或从安装的ISO文件中进行提取):
[root@Erp-Test1 ~]# wget http://vault.centos.org/centos/7.5.1804/os/x86_64/Packages/centos-release-7-5.1804.el7.centos.x86_64.rpm
使用rpm重新安装centos-release包:
[root@Erp-Test1 ~]# rpm -Uvh centos-release-7-5.1804.el7.centos.x86_64.rpm
我这里安装还报错,提示报错coreutils待相关包依赖效验失败了:
但很明显,这些基础组件系统里面都是存在着的。故进行强制安装:
[root@Erp-Test1 ~]# rpm -Uvh --nodeps --replacepkgs centos-release-7-5.1804.el7.centos.x86_64.rpm
然后便可重新使用yum命令了。