阿里云ECS CentOS和Ubuntu系统如何确认已安装的版本?

在阿里云ECS上确认CentOS和Ubuntu系统已安装的版本,可以通过以下命令查看:

一、CentOS系统

1. 查看系统版本信息

# 方法1:查看/etc/redhat-release文件
cat /etc/redhat-release

# 方法2:使用hostnamectl命令
hostnamectl

# 方法3:查看/etc/os-release文件
cat /etc/os-release

# 方法4:使用rpm命令(仅限RHEL/CentOS)
rpm -q centos-release

2. 查看内核版本

# 查看内核版本
uname -r

# 查看详细系统信息
uname -a

二、Ubuntu系统

1. 查看系统版本信息

# 方法1:查看/etc/os-release文件
cat /etc/os-release

# 方法2:查看/etc/lsb-release文件
cat /etc/lsb-release

# 方法3:使用lsb_release命令
lsb_release -a

# 方法4:查看版本文件
cat /etc/issue

2. 查看内核版本

# 查看内核版本
uname -r

# 查看详细系统信息
uname -a

三、通用方法(适用于所有Linux发行版)

1. 查看发行版信息

# 查看系统发行版
cat /etc/*-release

# 查看系统信息文件
cat /proc/version

2. 使用hostnamectl命令(systemd系统)

hostnamectl

四、阿里云控制台查看

除了SSH登录服务器查看,还可以通过阿里云控制台查看:

  1. 登录阿里云ECS控制台
  2. 进入实例列表
  3. 点击实例ID进入详情页
  4. 在"实例详情"中查看"操作系统"信息

五、常用命令示例输出

CentOS示例:

$ cat /etc/redhat-release
CentOS Linux release 7.9.2009 (Core)

$ hostnamectl
   Static hostname: localhost.localdomain
         Icon name: computer-vm
           Chassis: vm
        Machine ID: xxxxx
           Boot ID: xxxxx
    Virtualization: kvm
  Operating System: CentOS Linux 7 (Core)
       CPE OS Name: cpe:/o:centos:centos:7
            Kernel: Linux 3.10.0-1160.el7.x86_64
      Architecture: x86-64

Ubuntu示例:

$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 20.04.3 LTS
Release:        20.04
Codename:       focal

$ cat /etc/os-release
NAME="Ubuntu"
VERSION="20.04.3 LTS (Focal Fossa)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 20.04.3 LTS"
VERSION_ID="20.04"

六、快速判断系统类型

如果不确定是CentOS还是Ubuntu,可以使用:

# 判断包管理器类型
which yum     # CentOS/RHEL系统
which apt     # Ubuntu/Debian系统

# 或者查看发行版ID
grep "^ID=" /etc/os-release

这些命令可以帮助你快速确认阿里云ECS实例上安装的操作系统版本信息。

云服务器