title: 系统信息采集
created: 2026-06-20
updated: 2026-08-14
type: concept
tags: [linux, monitoring, hardware]
sources:
- raw/scripts/sysinfo.sh
- raw/scripts/规格汇总.txt
- raw/scripts/sdr.sh - raw/scripts/ipmitool.sh
- raw/scripts/redfish.curl.sh
系统信息采集
系统信息采集是服务器运维的基础工作,涵盖 BIOS/主板信息、BMC/FRU 数据、CPU/内存/磁盘/网卡规格、硬件监控传感器数据等。本文汇总了常用采集工具和命令。
dmidecode — 硬件信息解码
dmidecode 读取 DMI(Desktop Management Interface)表,输出 BIOS、系统、主板、内存等详细信息。
常见 type 参数
| Type | 名称 | 说明 |
|---|---|---|
| 0 | BIOS Information | BIOS 版本、日期、厂商、ROM 大小 |
| 1 | System Information | 产品名称、序列号、UUID、SKU |
| 2 | Baseboard Information | 主板型号、序列号、版本 |
| 16 | Physical Memory Array | 物理内存阵列(插槽总数、最大容量) |
| 17 | Memory Device | 单条内存信息(容量、类型、速度、序列号) |
| 4 | Processor | CPU 信息 |
| 7 | Cache | Cache 信息 |
| 9 | System Slots | PCI/PCIe 插槽信息 |
基本用法
# BIOS 信息
sudo dmidecode -t 0
# 或
sudo dmidecode | grep -A16 "BIOS Information"
sudo dmidecode -s bios-version
# 产品信息
sudo dmidecode -t 1
sudo dmidecode | grep -A16 "System Information"
# 主板信息
sudo dmidecode -t 2
# 内存阵列信息
sudo dmidecode -t 16
# 内存条详细信息
sudo dmidecode -t 17 | awk -F': ' '
BEGIN {
printf "%-5s %-15s %-20s %-25s %-10s\n", "Line", "Locator", "Serial", "Size-Type-Speed", "Part Number";
}
/Size:/ { size = $2 }
/Bank Locator:/ { locator = $2 }
/Type:/ { type = $2 }
/Configured Memory Speed:/ { speed = $2 }
/Serial Number:/ { serial = $2 }
/Part Number:/ { part = $2 }
/Firmware Version:/ {
combined = size "-" type "-" speed;
printf "%-5d %-15s %-20s %-25s %-10s\n", line++, locator, serial, combined, part;
}'
# 电源信息
sudo dmidecode | grep -A16 "System Power Supply"
CPU 信息
# CPU 详细信息
lscpu
# 简洁格式输出(型号、物理/逻辑核数、L3 缓存)
lscpu | awk -F':' '
/Model name/ {sub(/^ +/,"",$2); model=$2}
/Socket\(s\)/ {socket=$2}
/Core\(s\) per socket/ {core=$2}
/Thread\(s\) per core/ {thread=$2}
/L3 cache/ {l3=$2}
END {
total_phy=socket*core
total_log=total_phy*thread
printf "%s %d %d %s\n", model, total_phy, total_log, l3
}'
BMC & FRU 信息
BMC(Baseboard Management Controller)提供带外管理能力,通过 IPMI 协议访问:
# BMC 固件信息
sudo ipmitool mc info
# FRU(Field Replaceable Unit)信息 - 包含产品序列号、部件号
sudo ipmitool fru
# 传感器数据仓库(SDR)
sudo ipmitool sdr
sudo ipmitool sdr list
sudo ipmitool sensor
# 筛选关键传感器(温度、功耗、风扇转速)
sudo ipmitool sdr | grep -Ei 'RPM|degrees C|Watts'
SDR 监控脚本
sdr.sh 提供多时间点的传感器数据采集,用于监控硬件稳定性:
# 采集多个时间点的传感器数据并排输出
mapfile -t r1 < <(ipmitool sdr | grep -Ei 'RPM|degrees C|Watts' | awk '{printf "%-25s | %-15s\n", $1, $3}')
sleep 100
mapfile -t r2 < <(ipmitool sdr | grep -Ei 'RPM|degrees C|Watts' | awk '{printf "| %-15s\n", $3}')
sleep 300
# ... 更多时间点
# 并排输出各时间点数据
paste -d '' <(printf '%s\n' "${r1[@]}") <(printf '%s\n' "${r2[@]}")
系统概览工具
neofetch
轻量级系统信息展示工具,显示 Logo、OS、内核、CPU、GPU、内存等:
# 安装
sudo curl http://192.168.1.34/neofetch.sh -o /usr/bin/neofetch && chmod +x /usr/bin/neofetch
neofetch
hostnamectl
hostnamectl
# 输出包含 Static hostname、Icon name、Chassis、Machine ID、Boot ID、
# Operating System、Kernel、Architecture
inxi
更详细的全系统信息工具:
sudo apt install inxi # Debian/Ubuntu
sudo yum install inxi # RHEL/CentOS
inxi -Fxz # 完整信息,隐藏敏感字段
fastfetch
neofetch 的高性能替代品:
dnf install -y fastfetch
fastfetch
磁盘信息
# 查看磁盘型号、序列号、大小
sudo lsblk -o NAME,MAJ:MIN,MODEL,SERIAL,SIZE,WWN,HCTL,TRAN,VENDOR,TYPE | grep disk
sudo lsblk
# 查看 SCSI 设备
lsscsi
# 使用 lshw 查看磁盘详细信息
sudo lshw -class disk
网卡信息
# 网卡 PCI 设备列表
sudo lspci | grep net
# 网卡与总线地址对应关系
lshw -class network -businfo
# IP 地址信息
ip address
ip addr show
# 网卡配置文件的 IP 配置
# vi /etc/sysconfig/network-scripts/ifcfg-eth0
PCIe 设备树
# 完整 PCIe 设备树
sudo lspci -tv
# 按 Vendor ID 过滤(如 NVIDIA GPU)
lspci -d 10de: -vvv
lspci -tv 以树状结构展示 PCIe 拓扑,包括 Root Complex、PCIe Switch、端点设备及各设备之间的层级关系,对理解 NUMA 架构和 GPU 拓扑至关重要。
规格汇总命名规范
根据 规格汇总.txt,服务器硬件的命名规范化格式如下:
主板规格
格式:主板大小-主板类型-单路双路-CPU支持型号-板载网卡数量
示例:ATX-服务器主板-支持双路至强E5-2600v4/v3系列处理器-双千兆
CPU 规格
格式:型号-物理内核数-基频-L3级缓存-功率
示例:Intel-Xeon-Silver-4210R-10C-2.40GHz-13.75MB-100W
AMD-EPYC-7542-32C-1500MHz-16384K-?
示例:CPU-S-4210R-Intel-Xeon-Silver--4210R-10C-2.40-GHz-13.75MB-100W
示例:Intel-Xeon-Silver-E5-2620V4-8C-2.1GHz-20M-85W
内存规格
格式:内存容量-DDR-ECC/RECC-频率-颗粒规格
示例:MEM-64GB-DDR4-ECC-LRDIMM-2666-4R*4
16GB-DDR4-RECC-2933-1R*4
ECC— 带纠错功能RECC/RDIMM— 注册内存(Registered ECC)LRDIMM— 低负载双列直插内存模块1R*4/4R*4— Rank 数和颗粒位宽
硬盘规格
格式:SSD/HDD-容量-接口-速度-其他规格-尺寸
示例:SSD-240GB-SATA-6Gb/s-3D-TLC-2.5in
HDD-4T-SATA-6Gb/s-7200rpm-128MB-3.5IN
SSD/HDD— 硬盘类型SATA/SAS/NVMe— 接口类型6Gb/s— 接口速率3D-TLC— NAND 类型2.5in/3.5IN— 外形尺寸
硬件监控(IPMI SDR)
# 实时硬件健康监控
sudo ipmitool sdr list
# 查看传感器阈值
sudo ipmitool sensor
# 查看电源和温度
sudo ipmitool sdr | grep -Ei 'degrees C | Watts'
一键系统信息采集
综合脚本 sysinfo.sh 可一次性采集所有关键信息:
# 使用 curl 远程执行
sudo curl http://192.168.1.34/sysinfo.sh | sh > sysinfo.$(date +%Y%m%d_%H%M%S).out
该脚本依次采集:neofetch → hostnamectl → dmidecode BIOS/Product/Board → ipmitool mc info/fru → dmidecode 电源 → ipmitool sdr/sensor → lscpu → dmidecode 内存 → lsblk 磁盘 → lspci 网卡 → ip a → lspci -tv
相关页面
- cpu-testing — CPU 测试(lscpu 信息用于确认 CPU 规格)
- memory-testing — 内存测试(dmidecode 内存信息确认内存配置)
- gpu-testing — GPU 测试(lspci 查看 GPU、dmidecode 定位物理槽位)
- network-testing — 网络测试(lspci 和 ethtool 查看网卡信息)
硬件管理
硬件管理(Hardware Management)
Linux 服务器硬件管理包括带外(Out-of-Band)管理、传感器监控、固件维护等。核心工具是 IPMItool(见下文详解),结合 dmidecode 和 lspci 工具,可以全面掌握服务器硬件状态。
IPMI / BMC 管理
IPMI(Intelligent Platform Management Interface)是服务器硬件的独立管理子系统,BMC(Baseboard Management Controller)是其核心控制器。
关键操作
# 查看 BMC 信息
ipmitool mc info
# 查看传感器状态(温度、电压、风扇转速、功耗)
ipmitool sdr
ipmitool sensor list
# 电源管理
ipmitool power status
ipmitool power on/off/reset
# SEL 日志查看
ipmitool sel list
# 查看 FRU 信息(产品、板卡、机箱)
ipmitool fru list
远程管理
通过 IPMI-over-LAN 可实现远程带外管理:
ipmitool -H <BMC_IP> -I lanplus -U <user> -P <password> power reset
ipmitool -H <BMC_IP> -I lanplus -U <user> -P <password> sol activate
启动设备设置
ipmitool chassis bootdev pxe # PXE 启动
ipmitool chassis bootdev disk # 本地盘启动
dmidecode 硬件信息
dmidecode 读取 SMBIOS/DMI 表中的硬件信息:
| type 参数 | 内容 | 命令 |
|---|---|---|
| type 0 | BIOS 版本/日期 | dmidecode -t 0 |
| type 1 | 系统产品信息(厂商、型号、序列号) | dmidecode -t 1 |
| type 2 | 主板信息 | dmidecode -t 2 |
| type 16 | 物理内存阵列 | dmidecode -t 16 |
| type 17 | 内存条详细信息(容量、频率、序列号) | dmidecode -t 17 |
连续监控与日志
sdr.sh 脚本实现 IPMI SDR 多时间点监控,采集风扇转速(RPM)、温度(degrees C)和功耗(Watts)数据,并对比多轮采样结果来判断硬件状态趋势。
相关页面
- IPMItool 详解(见本文档 IPMItool 详解章节)
- 系统信息采集
- Linux 常规操作与优化
IPMItool 详解
IPMItool — 智能平台管理接口
IPMItool 是 Linux 环境下管理 BMC(Baseboard Management Controller)的标准命令行工具,提供对服务器硬件的带外管理能力。即使操作系统无响应,仍可通过 IPMI 执行电源控制、传感器监控和日志查看等操作。
安装
yum install -y ipmitool
apt install -y ipmitool
驱动加载
在使用 IPMItool 前,需要加载相应的内核模块:
modprobe ipmi_watchdog # IPMI 看门狗定时器
modprobe ipmi_poweroff # IPMI 电源管理
modprobe ipmi_msghandler # IPMI 消息处理(基础模块)
modprobe ipmi_devintf # IPMI 设备接口
modprobe ipmi_si # IPMI 系统接口(KCS/SMIC/BT 模式)
验证通信
# 发送原始 IPMI 命令验证通信
ipmitool raw 6 1
BMC 信息查看
查看 BMC 版本与固件信息
# BMC 基本信息
ipmitool mc info
# BMC 重启
sudo ipmitool mc reset warm # 温和重启(推荐)
sudo ipmitool mc reset cold # 强制冷重启(更彻底)
查看 BMC 网络配置
# 查看 IP 地址、MAC、网关等信息
ipmitool lan print
ipmitool lan print [ChannelNo]
# 查看通道信息
ipmitool channel info 1
ipmitool channel info 6
电源管理
# 查看电源状态
ipmitool power status
# 开机
ipmitool power on
# 关机
ipmitool power off
# 重启
ipmitool power reset
# 批量重启(循环执行)
for i in {1..10}; do
ipmitool -H 192.168.1.234 -I lanplus -U admin -P admin power reset
sleep 300
done
传感器监控(SDR/Sensor)
查看全部传感器
# 查看 SDR(Sensor Data Record)全部信息
ipmitool sdr
# 按类型筛选
ipmitool sdr type "power supply"
ipmitool sdr | grep -Ei 'RPM|degrees C|Watts'
查看传感器详细值
ipmitool sensor list
长时间监控脚本(sdr.sh)
# 输出温度/RPM/功耗在 0s、100s、300s、600s、900s 的变化趋势
sudo curl http://192.168.1.34/sdr.sh | sh > sdr.$(date +%Y%m%d_%H%M%S).out
该脚本采集 ipmitool sdr 中 RPM(风扇转速)、degrees C(温度)、Watts(功耗)三类传感器数据,按时间切片拼接成表格,用于观察散热和功耗趋势。
FRU 信息编辑
FRU(Field Replaceable Unit)信息用于记录服务器的厂商、型号、序列号等硬件资产信息。
查看 FRU
ipmitool fru list
读取/写入 FRU 二进制
# 导出
ipmitool fru read 0 fru.bin
# 导入
ipmitool fru write 0 fru.bin
编辑 FRU 字段
# 格式:ipmitool fru edit <fruid> field <section> <index> <string>
# Product(产品)信息
ipmitool fru edit 0 field p 0 "Kunqian" # 制造商
ipmitool fru edit 0 field p 1 "KH2212G-HK" # 产品名
ipmitool fru edit 0 field p 2 "123456" # 部件号
ipmitool fru edit 0 field p 3 "1.0" # 版本
ipmitool fru edit 0 field p 4 "SN-2024-001" # 序列号
ipmitool fru edit 0 field p 5 "Asset-001" # 资产标签
# Chassis(机箱)信息
ipmitool fru edit 0 field c 0 "Kunqian" # 机箱类型
ipmitool fru edit 0 field c 1 "CH-001" # 部件号
ipmitool fru edit 0 field c 2 "CSN-001" # 序列号
# Board(主板)信息
ipmitool fru edit 0 field b 0 "Kunqian" # 制造商
ipmitool fru edit 0 field b 1 "MB-2212G" # 产品名
ipmitool fru edit 0 field b 2 "BSN-001" # 序列号
ipmitool fru edit 0 field b 3 "BPN-001" # 部件号
SEL 日志查看
SEL(System Event Log)记录服务器硬件事件,包括温度警告、电压异常、风扇故障等。
# 查看所有 SEL 日志
ipmitool sel list
# 远程查看 SEL
ipmitool -H 192.168.1.40 -I lanplus -U admin -P admin@123 sel elist
远程管理
基本语法
ipmitool -H <BMC_IP> -I lanplus -U <用户名> -P <密码> <命令>
参数说明:
- -H:BMC 的管理 IP 地址
- -I lanplus:使用 RMCP+ 协议(加密通信)
- -U:BMC 登录用户名
- -P:BMC 登录密码
示例
# 验证远程连接
ipmitool -H 192.168.1.40 -I lanplus -U admin -P admin@123 raw 6 1
# 远程重启
ipmitool -H 192.168.1.40 -I lanplus -U admin -P admin@123 power reset
# 远程查看传感器
ipmitool -H 192.168.1.40 -I lanplus -U admin -P admin@123 sdr
启动设备设置
通过 IPMI 设置下一次启动的设备,用于 PXE 网络安装或本地磁盘启动。
# 设置 PXE 网络启动
ipmitool chassis bootdev pxe
ipmitool chassis bootdev pxe options=efiboot # UEFI 模式
# 设置本地磁盘启动
ipmitool chassis bootdev disk
# 查看当前启动参数
ipmitool chassis bootparam get 5
# 远程设置 PXE 启动并重启
ipmitool -I lanplus -H xxx.xxx.xxx.xxx -U xxxx -P xxxx chassis bootdev pxe
ipmitool -I lanplus -H xxx.xxx.xxx.xxx -U xxxx -P xxxx power reset
注意:设置 PXE 启动后,必须使用
ipmitool power reset重启,不能使用 OS 内部的reboot命令(否则 PXE 启动设置可能无效)。
SOL(Serial-over-LAN)串口重定向
SOL 允许通过网络远程访问服务器的串行控制台,相当于带外 SSH。
# 打开 SOL 会话
ipmitool sol activate
# 关闭 SOL 会话
ipmitool sol deactivate
# 启用/禁用某用户的 SOL 负载
ipmitool sol payload enable 1 2
ipmitool sol payload disable 1 2
# 远程抓取 SOL 日志
ipmitool -I lanplus -H 192.168.1.22 -U admin -P admin sol activate | tee sol.log
用户管理
# 查看用户列表
ipmitool user list [ChannelNo]
# 新增用户
ipmitool user set name <user_id> <username>
ipmitool user set password <user_id> <password>
ipmitool user priv <user_id> <privilege_level> [ChannelNo]
# 启用/禁用用户
ipmitool user enable <user_id>
ipmitool user disable <user_id>
# 修改密码
ipmitool user set password 1 abcdefg
网络配置
# 设置 IP 获取方式
ipmitool lan set 1 ipsrc static # 静态 IP
ipmitool lan set 1 ipsrc dhcp # DHCP
# 设置 IP 地址、子网掩码、默认网关
ipmitool lan set 1 ipaddr 192.168.1.100
ipmitool lan set 1 netmask 255.255.255.0
ipmitool lan set 1 defgw ipaddr 192.168.1.1
风扇控制(raw 命令)
使用原始 IPMI 命令直接控制 BMC 芯片,实现对风扇转速的手动调节(不同服务器厂商的 raw 命令可能不同)。
# BMC 重置
ipmitool raw 0x32 0x66
# 风扇切换为手动模式
ipmitool raw 0x00 0x30 0x01 0x00
# 设置风扇转速(最后一位 0x1e = 30% 转速,十六进制)
ipmitool raw 0x30 0x30 0x02 0xff 0x1e
# 远程风扇控制
ipmitool -I lanplus -H <iDRAC_IP> -U <用户名> -P <密码> raw 0x30 0x30 0x02 0xff 0x1e
注意:风扇控制命令因 BMC 厂商(如 iDRAC、OpenBMC、AMI)而异,请查阅对应厂商文档。
相关概念
- 硬件管理(见上文硬件管理章节)
- system-information — 系统信息采集(dmidecode、lscpu、硬件规格汇总)