原文地址 : Yum的变量

    新机器使用yum出现了报错,发现本来应该替换的$releasever变量变成了%24releasever

    http://mirrors.aliyun.com/centos/%24releasever/addons/x86_64/repodata/repomd.xml: [Errno 14] HTTP Error 404: Not Found Trying other mirror. Error: Cannot retrieve repository metadata (repomd.xml) for repository: addons. Please verify its path and try again

    下面我们来看看这个是怎么回事,最好的参考文档当然是man,通过man yum.conf 查看这个$releasever

    1. $releasever This will be replaced with the value of the version of the package listed in distroverpkg. This defaults to the ver- sion of redhat-release package.
    2. $arch This will be replaced with your architecture as listed by os.uname()[4] in Python.
    3. $basearch This will be replaced with your base architecture in yum. For example, if your $arch is i686 your $basearch will be
    4. i386.
    5. $YUM0-$YUM9 These will be replaced with the value of the shell environment variable of the same name. If the shell environment
    6. variable does not exist then the configuration file variable will not be replaced.

    可以看到 yum中有这几个变量: $releaserver$arch$basearch 和用户自定义的 $YUM0-$YUM9
    有一个简单的python命令可以看到yum的 releaserver、arch、basearch的值

    1. /usr/bin/python -c 'import yum, pprint; yb = yum.YumBase(); pprint.pprint(yb.conf.yumvar, width=1)'

    对于Yum正常的机器,releaserver变量都有定义

    1. {'arch': 'ia32e', 'basearch': 'x86_64', 'releasever': '5'}

    而对于今天Yum有问题的机器,releasever没有定义

    1. {'arch': 'ia32e', 'basearch': 'x86_64', 'releasever': '$releasever'}

    变量$releasever 的值来自 distroverpkg ,下面我们找一下 distroverpkg是怎么来的,还是在man yum.conf手册中。

    1. distroverpkg The package used by yum to determine the "version" of the distribution. This can be any installed package. Default is redhat-release’. You can see what provides this manually by using: "yum whatprovides redhat-release".

    distroverpkg 定义了一个包名,通过这个包命,执行yum whatprovides $distroverpkg yum就知道了系统的发行版本。
    这里默认的值是redhat-release。

    对于正常的CentOS系统。执行yum whatprovides redhat-release 可以看到结果

    1. 已加载插件:fastestmirror
    2. Loading mirror speeds from cached hostfile
    3. * remi-safe: mirrors.tuna.tsinghua.edu.cn
    4. centos-release-7-7.1908.0.el7.centos.x86_64 : CentOS Linux release file
    5. base
    6. 匹配来源:
    7. 提供 redhat-release = 7.7-10
    8. centos-release-7-7.1908.0.el7.centos.x86_64 : CentOS Linux release file
    9. @base
    10. 匹配来源:
    11. 提供 redhat-release = 7.7-10

    而对于今天遇到的yum有问题的机器,执行这个命令则没有结果。