问题
# 回顾
[root@rhel7 ~]# cat /etc/yum.repos.d/redhat.repo
[rhel-7-server-openstack-7.0-tools-source-rpms]
metadata_expire = 86400
enabled_metadata = 0
sslclientcert = /etc/pki/entitlement/1617084447624569515.pem
baseurl = https://cdn.redhat.com/content/dist/rhel/server/7/$releasever/$basearch/openstack-tools/7.0/source/SRPMS
ui_repoid_vars = releasever basearch
sslverify = 1
name = Red Hat OpenStack Tools 7.0 for Red Hat Enterprise Linux 7 Server (Source RPMs)
sslclientkey = /etc/pki/entitlement/1617084447624569515-key.pem
gpgkey = file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release
enabled = 0
sslcacert = /etc/rhsm/ca/redhat-uep.pem
gpgcheck = 1
# 问题
上面的repo文件中的 $releasever 和 $basearch 各是什么意思?这2个变量在哪定义?
问题展开
/etc/yum.conf 或 /etc/dnf/dnf.conf 来修改 distroverpkg 参数
# 在CentOS7.9上
[root@test1 ~]# cat /etc/yum.conf
[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=23&ref=http://bugs.centos.org/bug_report_page.php?category=yum
distroverpkg=centos-release
# 在RHEL7.9上
[root@rhel7 ~]# cat /etc/yum.conf
[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=23&ref=http://bugs.centos.org/bug_report_page.php?category=yum
distroverpkg=centos-release
会看到都有一个distroverpkg参数,且值相同,
distroverpkg 的值并不是明文,而是"redhat-release"。这里的redhat-release并不是/etc/redhat-release 文件
实际上指的是 redhat-release 这个RPM包。所谓"distroverpkg=redhat-release"的意思,其实是将 $releasever 设置为 redhat-release 这个RPM包的版本号
# 在CentOS7.9上
[root@test1 ~]# rpm -qa | grep centos-release # 执行rpm -qa | grep redhat-release时无结果
centos-release-7-9.2009.0.el7.centos.x86_64
# 在RHEL7.9上
[root@rhel7 ~]# rpm -qa | grep redhat-release # 执行rpm -qa | grep centos-release时无结果
redhat-release-eula-7.8-0.el7.noarch
redhat-release-server-7.9-12.el7_9.x86_64
distroverpkg:该参数指定了一个软件包的名称,yum 或 dnf 会从该包的版本信息中提取发行版的版本号。
通常这个包是与系统发行版紧密关联的核心包,例如 redhat-release、centos-release、almalinux-release 等
不同的发行版可能使用不同的包来确定版本信息,distroverpkg的典型值
对于 RHEL 系列:redhat-release
对于 CentOS:centos-release
对于 AlmaLinux:almalinux-release
对于 Rocky Linux:rocky-release
这些包的版本号通常与发行版版本号一致,因此它们被用于确定 $releasever 的值
$releasever 和 $basearch
$releasever:这个变量通常由 distroverpkg 指定的软件包版本号来决定,表示系统的主要版本号,例如 7, 8, 9 等
$basearch:这个变量表示系统的基础架构类型,例如 x86_64、aarch64 等。它通常直接从系统架构信息中获取
# 查询系统发布包的版本
# 对于 RHEL 或 CentOS
rpm -q --qf "%{VERSION}\n" redhat-release
# 对于 AlmaLinux
rpm -q --qf "%{VERSION}\n" almalinux-release
# 对于 Rocky Linux
rpm -q --qf "%{VERSION}\n" rocky-release