1. IPMI 简介

IPMI(Intelligent Platform Management Interface,智能平台管理接口)是一种工业标准,用于带外(out-of-band)管理服务器硬件。它独立于操作系统(OS)和 BIOS,允许管理员远程监控硬件状态、控制电源、查看传感器数据、访问串行控制台等。通常通过 Baseboard Management Controller(BMC,基板管理控制器)实现。

常用的 IPMI 工具是 ipmitool,它支持通过本地或网络与 BMC 通信。

2. 安装 ipmitool

CentOS / RHEL

yum install ipmitool

Ubuntu / Debian

apt-get install ipmitool

源码编译

SourceForge 下载源码并编译。

3. 基本用法

3.1 连接方式

  • 本地(KCS 接口):在服务器上直接执行(需要加载内核模块,如 ipmi_devintf)。

    ipmitool <command>
  • 远程(LAN 接口):通过网络连接到 BMC。

    ipmitool -H <BMC_IP> -U <用户名> -P <密码> <command>

常用选项:

  • -H:BMC 的 IP 地址
  • -U:BMC 用户名
  • -P:密码(也可用 -f 从文件读取,或通过环境变量 IPMITOOL_PASSWORD
  • -I:接口类型(lanlanplus,推荐 lanplus 支持加密)
  • -p:BMC 端口(默认 623)

示例:

ipmitool -H 192.168.1.100 -U admin -P password -I lanplus chassis power status

4. 常用命令分类

4.1 电源管理

命令说明
chassis power on开机
chassis power off强制关机(相当于长按电源键)
chassis power soft软关机(发出 ACPI 关机信号,需 OS 支持)
chassis power reset重启
chassis power cycle先关闭再开启电源
chassis power status查看当前电源状态

示例:

ipmitool -H 192.168.1.100 -U admin -P password chassis power status

4.2 传感器信息

命令说明
sensor list列出所有传感器及其读数
sensor get "<传感器名>"获取单个传感器的详细信息
sdr list显示传感器数据记录(SDR)
sdr type <类型>按类型过滤(如 Temperature, Voltage, Fan)

示例:

ipmitool sensor list
ipmitool sdr type Temperature

4.3 用户管理

命令说明
user list列出所有用户
user set name <用户ID> <用户名>设置用户名
user set password <用户ID> <密码>设置密码(提示输入)
user enable <用户ID>启用用户
user disable <用户ID>禁用用户
user priv <用户ID> <权限级别> <通道号>设置用户权限(2=User, 3=Operator, 4=Admin)

权限级别:

  • 1:Callback
  • 2:User
  • 3:Operator
  • 4:Administrator
  • 5:OEM

示例:

# 添加用户
ipmitool user set name 2 john
ipmitool user set password 2
ipmitool user priv 2 4 1
ipmitool user enable 2

4.4 网络配置

命令说明
lan print <通道号>显示当前网络参数(通道号通常为1)
lan set <通道号> ipsrc <static/dhcp>设置 IP 来源
lan set <通道号> ipaddr <IP>设置静态 IP
lan set <通道号> netmask <掩码>设置子网掩码
lan set <通道号> defgw ipaddr <网关>设置默认网关

示例:

ipmitool lan print 1
ipmitool lan set 1 ipsrc static
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

4.5 通道设置

命令说明
channel info [通道号]显示通道信息
channel getaccess <通道号> <用户ID>查看用户通道访问权限
channel setaccess <通道号> <用户ID> [选项]设置用户通道访问权限

选项:callin=on/off, ipmi=on/off, link=on/off, privilege=<级别> 等。

示例:

ipmitool channel info 1
ipmitool channel getaccess 1 2

4.6 SOL(Serial Over LAN)串行控制台

SOL 允许通过 IPMI 远程访问服务器的串行控制台。

命令说明
sol activate激活 SOL 会话(需先配置)
sol deactivate停用当前 SOL 会话
sol info [通道号]查看 SOL 配置
sol set <参数> <值>配置 SOL 参数(如波特率)

先要确保 SOL 已启用:

ipmitool sol set enabled true 1
ipmitool sol set privilege-level admin 1
ipmitool sol set force-encryption false 1  # 如果不需要加密

然后激活:

ipmitool -H 192.168.1.100 -U admin -P password sol activate

退出 SOL 会话:~.(先按 ~ 再按 .)或按 Ctrl + ] 进入转义模式。

4.7 系统事件日志(SEL)

命令说明
sel list列出所有事件
sel elist列出事件(更详细的格式)
sel info显示 SEL 信息(如总条目数)
sel clear清除所有事件
sel delete <记录ID>删除指定事件
sel save <文件名>保存 SEL 到文件

示例:

ipmitool sel list
ipmitool sel clear

4.8 FRU(Field Replaceable Unit)

FRU 包含硬件组件信息(如序列号、制造商等)。

命令说明
fru list列出所有 FRU 设备
fru print [<设备ID>]显示 FRU 详细信息

示例:

ipmitool fru print

4.9 其他实用命令

命令说明
bmc info显示 BMC 自身信息(固件版本等)
mc info同 bmc info
mc reset cold/warm重启 BMC
chassis identify <秒数>开启机箱定位灯(通常几秒)
raw <网卡> <命令>发送原始 IPMI 命令

5. 示例场景

5.1 远程查看服务器温度

ipmitool -H 192.168.1.100 -U admin -P password sdr type Temperature

5.2 远程重启服务器

ipmitool -H 192.168.1.100 -U admin -P password chassis power reset

5.3 创建新管理员用户

ipmitool user set name 3 alice
ipmitool user set password 3
ipmitool user priv 3 4 1
ipmitool user enable 3

5.4 配置 BMC 静态 IP

ipmitool lan set 1 ipsrc static
ipmitool lan set 1 ipaddr 192.168.1.200
ipmitool lan set 1 netmask 255.255.255.0
ipmitool lan set 1 defgw ipaddr 192.168.1.1

5.5 进入 SOL 控制台

ipmitool -H 192.168.1.100 -U admin -P password sol activate

6. 注意事项

  • 安全性:远程使用时建议启用加密(-I lanplus),并避免在命令行直接暴露密码(可使用 -f 或环境变量)。
  • 权限:不同厂商的 BMC 可能对某些命令支持不完全,部分命令需要管理员权限。
  • 通道号:多数服务器使用通道 1 用于管理网络,但某些厂商可能不同(如 Dell 可能使用通道 2)。
  • SOL 退出:记住退出序列 ~.(点号紧跟波浪号)。
  • 防火墙:BMC 默认使用 UDP 623 端口,确保网络可达。

7. 参考资料

  • ipmitool 官方文档
  • man ipmitool 命令手册
  • 各服务器厂商的 BMC 用户指南(Dell iDRAC、HP iLO、Supermicro IPMI 等)

备注:本文基于 ipmitool 1.8.18 版本,不同版本或厂商 BMC 可能有细微差异。

最后修改:2026 年 03 月 16 日
如果觉得我的文章对你有用,请随意赞赏