ipmitool常用命令及用法详解

Linux-ManagementTools-IPMItoolCommon

IPMI官方文档

https://github.com/ipmitool/ipmitool

一、基本连接方式

1
2
3
4
5
6
7
8
# 本地管理(需要root权限)
ipmitool [command]

# 远程管理(带密码)
ipmitool -I lanplus -H [BMC_IP] -U [username] -P [password] [command]

# 远程管理(交互式输入密码)
ipmitool -I lanplus -H [BMC_IP] -U [username] -p [password] [command]

二、常用命令分类

1. 传感器信息相关

1
2
3
4
5
6
7
8
# 查看所有传感器信息
ipmitool sensor list

# 查看特定传感器信息(如CPU温度)
ipmitool sensor get "CPU Temp"

# 查看传感器阈值
ipmitool sensor thresh "CPU Temp" upper 80 85 90

2. 电源管理

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# 查看电源状态
ipmitool power status

# 开机
ipmitool power on

# 关机
ipmitool power off

# 硬重启(相当于按电源按钮)
ipmitool power reset

# 软关机(正常关机)
ipmitool power soft

# 电源循环(先关机再开机)
ipmitool power cycle

3. FRU(Field Replaceable Unit)信息

1
2
3
4
5
6
7
8
# 查看FRU信息
ipmitool fru print

# 查看特定FRU信息(如0表示主板)
ipmitool fru print 0

# 将FRU信息导出到文件
ipmitool fru read 0 fru_board.bin

4. SEL(System Event Log)管理

1
2
3
4
5
6
7
8
9
10
11
12
13
14
# 查看SEL日志
ipmitool sel list

# 查看详细的SEL信息
ipmitool sel elist

# 清除SEL日志
ipmitool sel clear

# 获取SEL时间信息
ipmitool sel time get

# 设置SEL时间(与本地时间同步)
ipmitool sel time set "now"

5. BMC配置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# 查看BMC网络配置
ipmitool lan print

# 设置BMC IP地址
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

# 查看BMC用户列表
ipmitool user list 1

# 添加BMC用户
ipmitool user set name 2 newuser
ipmitool user set password 2 "newpassword"
ipmitool user enable 2

# 更改用户权限
ipmitool channel setaccess 1 2 callin=on ipmi=on link=on privilege=4

6. 远程控制台

1
2
3
4
5
# 启动SOL(Serial Over LAN)会话
ipmitool -I lanplus -H [BMC_IP] -U [username] -P [password] sol activate

# 退出SOL会话
# 在SOL会话中按"~."组合键

7. 传感器数据记录(SDR)

1
2
3
4
5
6
7
8
9
10
# 查看SDR信息
ipmitool sdr list

# 查看详细的SDR信息
ipmitool sdr elist

# 查看特定类型的传感器
ipmitool sdr type temperature
ipmitool sdr type fan
ipmitool sdr type voltage

8. 机箱状态

1
2
3
4
5
6
7
8
9
10
# 查看机箱状态
ipmitool chassis status

# 查看机箱策略
ipmitool chassis policy list

# 设置机箱电源恢复策略
ipmitool chassis policy always-on # 上电后自动开机
ipmitool chassis policy previous # 保持上次状态
ipmitool chassis policy stay-off # 保持关机状态

9. 固件管理

1
2
3
4
5
6
7
8
# 查看BMC固件版本
ipmitool mc info

# 强制BMC冷重启
ipmitool mc reset cold

# 强制BMC热重启
ipmitool mc reset warm

10. 网络配置

1
2
3
4
5
6
7
#查看 BMC 网络配置
ipmitool lan print 1

#修改 BMC IP 地址
ipmitool lan set 1 ipaddr <新IP地址>
ipmitool lan set 1 netmask <子网掩码>
ipmitool lan set 1 defgw ipaddr <网关>

三、高级用法

批量执行命令

1
2
# 使用批处理模式执行多个命令
ipmitool -H [BMC_IP] -U [username] -P [password] -b [baud_rate] -t [device_type] < commands.txt

使用加密通道

1
2
# 使用加密的lanplus接口
ipmitool -I lanplus -H [BMC_IP] -U [username] -P [password] -C 17 [command]

调试模式

1
2
3
# 启用调试输出
ipmitool -d [debug_level] [command]
# debug_level: 1-3,数字越大输出越详细

四、注意事项

  1. 执行某些命令(如电源控制)需要管理员权限
  2. 频繁查询传感器可能会导致BMC负载增加
  3. 修改网络配置时要小心,错误的配置可能导致无法远程访问BMC
  4. 在生产环境中操作前建议先测试
  5. 不同厂商的IPMI实现可能有细微差别,某些命令可能不支持