如何查看 CentOS 版本

在对问题进行故障排除或者向支持团队提供信息时,有时需要了解确切的内核版本或者操作系统版本。
这篇文章将确定我们正在运行的 CentOS 或者 RHEL 系统的操作系统和内核版本。

在查找任何 Linux 系统的版本时,有两个主要事项需要检查。
他们是

  1. 检查操作系统更新级别
  2. 检查正在运行的内核版本

1. 检查 CentOS/RHEL 操作系统更新级别

下面显示的 4 个文件提供了 CentOS/Redhat OS 的更新版本。

  • /etc/centos-release
  • /etc/os-release
  • /etc/redhat-release
  • /etc/system-release

CentOS 7.4 系统的上述每个文件的内容如下所示。

# cat /etc/redhat-release
CentOS Linux release 7.4.1708 (Core)
# cat /etc/centos-release
CentOS Linux release 7.4.1708 (Core)
# cat /etc/os-release
NAME="CentOS Linux"
VERSION="7 (Core)"
ID="centos"
ID_LIKE="rhel fedora"
VERSION_ID="7"
PRETTY_NAME="CentOS Linux 7 (Core)"
ANSI_COLOR="0;31"
CPE_NAME="cpe:/o:centos:centos:7"
HOME_URL="https://www.centos.org/"
BUG_REPORT_URL="https://bugs.centos.org/"
CENTOS_MANTISBT_PROJECT="CentOS-7"
CENTOS_MANTISBT_PROJECT_VERSION="7"
REDHAT_SUPPORT_PRODUCT="centos"
REDHAT_SUPPORT_PRODUCT_VERSION="7"
# cat /etc/system-release
CentOS Linux release 7.4.1708 (Core)

以上4个文件由centos-release包提供。

# rpm -ql centos-release | grep release$
/etc/centos-release
/etc/os-release
/etc/redhat-release
/etc/system-release

我们可以通过查看 rpm 数据库报告的版本控制来查找版本信息。
例如:

# rpm -qf /etc/redhat-release
centos-release-7-4.1708.el7.centos.x86_64
www. On IT Road .com

检查 CentOS 7 版本

除了以上所有命令外,我们还可以使用命令“hostnamectl”在 CentOS 7 系统中查找操作系统版本信息。
例如:

# hostnamectl
   Static hostname: onitroad
         Icon name: computer-vm
           Chassis: vm
        Machine ID: f9afeb75a5a382dce8269887a67fbf58
           Boot ID: 668b5c55c6b9438b9356438d8beceec6
    Virtualization: xen
  Operating System: CentOS Linux 7 (Core)
       CPE OS Name: cpe:/o:centos:centos:7
            Kernel: Linux 3.10.0-693.21.1.el7.x86_64
      Architecture: x86-64

检查 LSB 版本

另一种检查 centOS 版本的方法是使用“lsb_release”命令。
lsb_release 命令由包“redhat-lsb”提供。
默认情况下,系统上可能不存在此软件包,我们可能需要先安装它。

# yum install redhat-lsb

lsb_release 命令示例:

# lsb_release -d
Description:    CentOS Linux release 7.4.1708 (Core)
# lsb_release -r
Release:        7.4.1708
# lsb_release -a
LSB Version:    :core-4.1-amd64:core-4.1-noarch:cxx-4.1-amd64:cxx-4.1-noarch:desktop-4.1-amd64:desktop-4.1-noarch:languages-4.1-amd64:languages-4.1-noarch:printing-4.1-amd64:printing-4.1-noarch
Distributor ID: CentOS
Description:    CentOS Linux release 7.4.1708 (Core)
Release:        7.4.1708
Codename:       Core

使用 GRUB 配置文件检查操作系统版本

使用 GRUB 配置文件不是检查操作系统版本的推荐方法,但我仍然想在这里提及此方法以供我们参考。
在 GRUB 配置文件中搜索“menuentry”(对于 CentOS 7)和“title”(对于 CentOS 6)以查找操作系统版本。

CentOS 7 示例

# cat /boot/grub2/grub.cfg | grep -w menuentry
menuentry 'CentOS Linux (3.10.0-693.21.1.el7.x86_64) 7 (Core)' --class centos --class gnu-linux --class gnu --class os --unrestricted $menuentry_id_option 'gnulinux-3.10.0-693.21.1.el7.x86_64-advanced-0f790447-ebef-4ca0-b229-d0aa1985d57f' {
menuentry 'CentOS Linux (3.10.0-693.17.1.el7.x86_64) 7 (Core)' --class centos --class gnu-linux --class gnu --class os --unrestricted $menuentry_id_option 'gnulinux-3.10.0-693.17.1.el7.x86_64-advanced-0f790447-ebef-4ca0-b229-d0aa1985d57f' {

对于 CentOS 7,我们还可以从文件 /boot/grub2/grubenv 中获取当前内核版本。
例如:

# grep saved_entry /boot/grub2/grubenv
saved_entry=CentOS Linux (3.10.0-693.21.1.el7.x86_64) 7 (Core)

CentOS 6 示例

# cat /boot/grub/grub.conf | grep title
title CentOS (2.6.32-696.20.1.el6.x86_64)
title CentOS (2.6.32-696.18.7.el6.x86_64)

2.检查运行内核版本

我们可以使用 uname 命令找出我们正在使用的 CentOS 内核版本和架构。
有关 uname 命令的详细信息,请执行“man uname”。

例子:

# uname -s -r
Linux 3.10.0-693.21.1.el7.x86_64
# uname -a
Linux onitroad 3.10.0-693.21.1.el7.x86_64 #1 SMP Wed Mar 7 19:03:37 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux

检查内核编译时间 (uname -v ) 并与已知值进行比较:

# uname -v
#1 SMP Wed Mar 7 19:03:37 UTC 2018

我们还可以使用 rpm 命令验证内核包。
仅当安装的内核存在任何问题时,该命令才会产生输出。

# rpm -q --verify kernel-3.10.0-693.21.1.el7.x86_64
日期:2020-09-17 00:13:14 来源:oir作者:oir