错误现象
下载阿里云的yum源
[root@MiWiFi-R3L-srv ~]# wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
--2019-08-15 15:24:09-- http://mirrors.aliyun.com/repo/Centos-7.repo
Resolving mirrors.aliyun.com (mirrors.aliyun.com)... 111.206.4.103
Connecting to mirrors.aliyun.com (mirrors.aliyun.com)|111.206.4.103|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 2523 (2.5K) [application/octet-stream]
Saving to: ‘/etc/yum.repos.d/CentOS-Base.repo’
100%[==================================================================>] 2,523 --.-K/s in 0s
2019-08-15 15:24:09 (293 MB/s) - ‘/etc/yum.repos.d/CentOS-Base.repo’ saved [2523/2523]
执行yum makecache的时候出现错误。
[root@MiWiFi-R3L-srv ~]# yum makecache
Loaded plugins: 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
* base: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
http://mirrors.aliyun.com/centos/%24releasever/os/x86_64/repodata/repomd.xml: [Errno 14] HTTP Error 404 - Not Found
Trying other mirror.
To address this issue please refer to the below wiki article
问题分析
对比.repo文件和报错信息,可以发现$releasever变量没有被系统识别,在连接网络yum源的时候,变成了%24releasever
[root@MiWiFi-R3L-srv ~]# cat /etc/yum.repos.d/CentOS-Base.repo
[base]
name=CentOS-$releasever - Base - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/os/$basearch/
http://mirrors.aliyuncs.com/centos/$releasever/os/$basearch/
http://mirrors.cloud.aliyuncs.com/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
查询资料得知,yum中的变量$releasever是由/etc/yum.conf中的distroverpkg定义的。centos-release为一个rpm包,所谓“distroverpkg=centos-release”的意思,其实是将 $releasever设置为centos-release 这个RPM包的版本号。
[root@MiWiFi-R3L-srv ~]# vim /etc/yum.conf
[main]
distroverpkg=centos-release
通过rpm可以查询到改软件包并没有被安装
[root@MiWiFi-R3L-srv ~]# rpm -q centos-release
package centos-release is not installed
由此我们可以分析出,系统缺少centos-release这个软件包。
解决思路
由于centos-release依赖关系比较复杂,约40个左右依赖包,我们可以修改yum源文件,把$releasever全部替换为7
此时yum可以正常使用,通过yum安装centos-release
[root@MiWiFi-R3L-srv ~]# yum install centos-release
重新下载yum源,覆盖修改之后的yum。yum makecache系统可把$releasever解析为当前的CentOS的版本,恢复正常状态。
[root@MiWiFi-R3L-srv ~]# wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.rep
[root@MiWiFi-R3L-srv ~]# yum makecache
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
base | 3.6 kB 00:00:00
extras | 3.4 kB 00:00:00
updates | 3.4 kB 00:00:00
base/7/x86_64/other_db FAILED
http://mirrors.cloud.aliyuncs.com/centos/7/os/x86_64/repodata/fbebcd3de05e22bd1cd526e594f235968401471d4a9aef3c1ad356b6d1965365-other.sqlite.bz2: [Errno 14] curl#6 - "Could not resolve host: mirrors.cloud.aliyuncs.com; Unknown error"
Trying other mirror.
(1/8): extras/7/x86_64/other_db | 131 kB 00:00:00
参考链接
https://1530236181.iteye.com/blog/2427350
https://blog.csdn.net/michaelwubo/article/details/80624727