yum中$releasever、 $basearch等变量含义

2020-09-01 0 476 百度已收录

Red Hat Linux 或 CentOS 发行版本

第一种方法,也是最容易想到的方法是查看 /etc/issue 和 /etc/RedHat-release这两个文件,这两个文件都差不多,都含有发行号, 但这是在文件中,很容易修改,我那个同事觉得这个不太靠谱。

第二种方法是使用命令,在RHEL 5 或 CentOS 5 中有个命令: lsb-release,通过这个命令可以查到,不过在RHEL 6就没这么幸运了,在我的最小系统中找不到这个命令,而我那个同事偏偏是在CentOS6上获取发行版本号, 看来此路又不通了。

不过有一个线索, 那就是在CentOS自带的Yum源文件中使用了 $releasever , $basearch等这些变量, 奇怪的是这些变量的值是从哪获取的呢?

Google 一下之后,说明Yum变量的说明可以在这里(5.3.3. Using YumVariables)找到,说明如下:

5.3.3. Using Yum Variables

You can use and reference the following built-in variables inyum commands and in all Yum configuration files (that is,/etc/yum.conf and all .repo files in the /etc/yum.repos.d/directory):

$releasever
You can use this variable toreference the release version of Red Hat Enterprise Linux. Yumobtains the value of $releasever from the distroverpkg=value linein the /etc/yum.conf configuration file. If there is no such linein /etc/yum.conf, then yum infers the correct value by deriving theversion number from the redhat-release package.
$arch

You can use this variable to refer to the system’s CPUarchitecture as returned when calling Python’s os.uname() function.Valid values for $arch include: i586, i686 and x86_64.
$basearch

You can use $basearch to reference the base architecture ofthe system. For example, i686 and i586 machines both have a basearchitecture of i386, and AMD64 and Intel64 machines have a basearchitecture of x86_64.
$YUM0-9

These ten variables are each replaced with the value of anyshell environment variables with the same name. If one of thesevariables is referenced (in /etc/yum.conf for example) and a shellenvironment variable with the same name does not exist, then theconfiguration file variable is not replaced.

To define a custom variable or to override the value of anexisting one, create a file with the same name as the variable(without the “$” sign) in the /etc/yum/vars/ directory, and add thedesired value on its first line.

For example, repository descriptions often include theoperating system name. To define a new variable called $osname,create a new file with “Red Hat Enterprise Linux” on the first lineand save it as /etc/yum/vars/osname:

~]# echo “Red Hat Enterprise Linux” >/etc/yum/vars/osname

Instead of “Red Hat Enterprise Linux 6”, you can now use thefollowing in the .repo files:

name=$osname $releasever

文中说到$releasever的定义可以查看 /etc/yum.conf 文件的事distroverpkg=value行,打开 /etc/yum.conf 看一下,默认文件(我的是CentOS 6)内容如下:
[main]
cachedir=/var/cache/yum/$basearch/$releasever
keepcache=0
debuglevel=2
logfile=/var/log/yum.log
exactarch=1
obsoletes=1
gpgcheck=1
plugins=1
installonly_limit=5
bugtracker_url=http://bugs.centos.org/set_project.php?project_id=16&ref=http://bugs.centos.org/bug_report_page.php?category=yum
distroverpkg=centos-release
distroverpkg=centos-release 代表什么? 去哪找 centos-release。找到这里我再一次表示困惑。

不过另一篇文章进行了我的视野: yum的$releasever真是太反动了, 关键内空如下:

在 /etc/yum.repos.d/ 目录下的软件库定义文件中,常常会在 baseurl 的路径中提到$releasever 这个变量,表示当前发行版的大版本号,但大家知道这个变量是在哪设置的吗?我 grep 了整个 etc目录都没找到,还是看了 yum.conf 才知道的,是在 yum.conf 文件里 distroverpkg选项定义的。但这个选项就很有问题:

distroverpkg 和 releasever 名字不同,且看不出什么联系
distroverpkg的值,并不是明文,而是“redhat-release”。不知道大家看到这个会有什么想法,反正我是首先想到了/etc/redhat-release 文件,但我错了。实际上指的是 redhat-release这个RPM包。所谓“distroverpkg=redhat-release”的意思,其实是将 $releasever 设置为redhat-release 这个RPM包的版本号

原来如此。这发行版本号可是藏的够深的。
小结:
yum中的$releasever变量是取redhat-release-serverrpm包的属性值( %{version})。
[root@ldap01 ~]# rpm -q –qf %{version}redhat-release-server;echo
6Server
查看关于yum的配置

ls /etc/yum* -ld:

查看/etc/yum.repos.d下的文件

查看CentOS-Base.repo内容:

部分内容:

[base]
baseurl=http://mirror.centos.org/centos/$releasever/os/$basearch/
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os
gpgcheck=1
gpgkey=file:///etc/pki/rpm-pgg/RPM-GPG-KEY-CentOS-6
[update]
baseurl=http://mirror.centos.org/centos/$releasever/updates/$basearch/
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates

我们看出来里面包含大量的变量:

$releasever和$basearch

$releasever的值,这个表示当前系统的发行版本,可以通过如下命令查看:

rpm -qi centos-release

结果如下:

其中的Version:6就是我们系统的版本号

$basearch是我们的系统硬件架构(CPU指令集),就是我们常说的i386i486i586i686…

使用如下命令即可:

arch

输出如下:

我这个处理器是i686,现在所有的intel 32位体系(包括AMD等兼容CPU)都叫i386体系,包括P4。i686仍然属于i386体系,不过对CPU(相对于386)的特性作了指令优化。 GNU/Linux分为i386、alpha、PowerPC、Sun等各个不同版本,所有从Intel386-P4都用i386版本,但i386版本中 有几个内核(i386,i486,i586,i686),安装时安装程序检测到你得CPU级别后,自动为你安装相应内核。

在Linux中使用命令arch可以初步查看出当前系统所识别出来的机器CPU类型,如”i386″, “i486″,”i586”, “alpha”, “sparc”, “arm”, “m68k”,”mips”,”ppc”,”ia64″,”x86_64″等;ia64和x86_64就说明这台机器是64位的;

所以我这儿要使用i386作为$basearch的值

baseurl=http://mirror.centos.org/centos/$releasever/os/$basearch/

完整路径便是

baseurl=http://mirror.centos.org/centos/6/os/i386/

本文永久更新链接地址:https://www.linuxidc.com/Linux/2018-05/152526.htm

yum中$releasever、 $basearch等变量含义

收藏 (0) 打赏

感谢您的支持,我会继续努力的!

打开微信/支付宝扫一扫,即可进行扫码打赏哦,分享从这里开始,精彩与您同在
点赞 (0)

栗子博客 软件 yum中$releasever、 $basearch等变量含义 https://www.lizi.tw/soft/9295.html

常见问题
  • 1、杰齐1.7仅适用于PHP5.2 2、需Zend支持 3、尽量使用宝塔面板 4、尽量使用Windows 系统,关关对Linux支持不太友好。
查看详情

相关文章

评论
暂无评论
官方客服团队

为您解决烦忧 - 24小时在线 专业服务

yum中$releasever、 $basearch等变量含义-海报

分享本文封面