服务器 IPMI 远程管理配置实战

一、背景与概述

IPMI(Intelligent Platform Management Interface)是服务器硬件管理的核心协议,允许运维人员在操作系统未启动或服务器宕机时,通过网络远程管理硬件。本文基于实际生产环境,介绍 IPMI/BMC 的配置与使用最佳实践。

二、IPMI 架构说明

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
┌─────────────────────────────────────────────────────────┐
│ 服务器硬件层 │
│ ┌─────────┐ ┌─────────┐ ┌─────────┐ ┌─────────┐ │
│ │ CPU │ │ 内存 │ │ 硬盘 │ │ 电源 │ │
│ └────┬────┘ └────┬────┘ └────┬────┘ └────┬────┘ │
│ └────────────┼────────────┼────────────┘ │
│ ▼ │
│ ┌─────────────────────────────────────────────────┐ │
│ │ BMC/IPMI 控制器 │ │
│ │ (独立于操作系统,即使关机也能工作) │ │
│ └─────────────────────┬───────────────────────────┘ │
│ │ │
│ ▼ │
│ ┌─────────────────┐ │
│ │ 专用管理网口 │ │
│ │ (或共享网口) │ │
│ └────────┬────────┘ │
└───────────────────────┼───────────────────────────────┘


┌─────────────────┐
│ 运维管理网络 │
└─────────────────┘

三、IPMI 配置步骤

3.1 查看当前 IPMI 状态

1
2
3
4
5
6
7
8
# 检查 IPMI 服务状态
systemctl status ipmid

# 查看 IPMI 设备信息
ipmitool mc info

# 查看网络配置
ipmitool lan print 1

3.2 配置 IPMI 网络参数

1
2
3
4
5
6
7
8
9
10
11
12
13
14
# 设置 IPMI IP 地址(静态配置推荐)
ipmitool lan set 1 ipsrc static
ipmitool lan set 1 ipaddr 192.168.100.10
ipmitool lan set 1 netmask 255.255.255.0
ipmitool lan set 1 defgw ipaddr 192.168.100.1

# 设置用户权限(用户 ID 2 通常是 admin)
ipmitool user set name 2 admin
ipmitool user set password 2 YourSecurePassword123
ipmitool user enable 2
ipmitool user privilege 2 4 # 4 = Administrator

# 启用 LAN 访问
ipmitool lan set 1 access on

3.3 防火墙配置

1
2
3
4
5
6
# 开放 IPMI 端口
firewall-cmd --permanent --add-port=623/udp
firewall-cmd --reload

# 或使用 iptables
iptables -A INPUT -p udp --dport 623 -j ACCEPT

四、常用 IPMI 命令速查

4.1 电源管理

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 soft

# 强制关机
ipmitool power off

# 重启
ipmitool power reset

# 电源循环
ipmitool power cycle

4.2 传感器监控

1
2
3
4
5
6
7
8
9
10
11
# 查看所有传感器读数
ipmitool sensor list

# 查看温度传感器
ipmitool sensor list | grep -i temp

# 查看风扇转速
ipmitool sensor list | grep -i fan

# 查看电压
ipmitool sensor list | grep -i volt

4.3 系统日志

1
2
3
4
5
6
7
8
9
10
11
# 查看 SEL(系统事件日志)
ipmitool sel list

# 查看 SEL 详细信息
ipmitool sel elist

# 清除 SEL 日志
ipmitool sel clear

# 实时查看日志
ipmitool sel elist | tail -20

4.4 用户管理

1
2
3
4
5
6
7
8
# 列出所有用户
ipmitool user list 1

# 查看用户详细信息
ipmitool user get 2

# 删除用户
ipmitool user disable 3

五、远程连接示例

5.1 本地执行(通过 BMC)

1
2
# 本地 BMC 连接
ipmitool -I openmc sensor list

5.2 远程执行(通过网络)

1
2
3
4
5
6
7
8
# 远程连接格式
ipmitool -I lanplus -H <BMC_IP> -U <username> -P <password> <command>

# 示例:远程查看电源状态
ipmitool -I lanplus -H 192.168.100.10 -U admin -P password power status

# 示例:远程重启服务器
ipmitool -I lanplus -H 192.168.100.10 -U admin -P password power reset

5.3 使用配置文件(避免密码暴露)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# 创建配置文件
cat > ~/.ipmi_config << EOF
DEVICE=192.168.100.10
USERNAME=admin
PASSWORD=YourSecurePassword123
EOF

# 设置权限
chmod 600 ~/.ipmi_config

# 使用配置文件
ipmitool -I lanplus -H $(grep DEVICE ~/.ipmi_config | cut -d= -f2) \
-U $(grep USERNAME ~/.ipmi_config | cut -d= -f2) \
-P $(grep PASSWORD ~/.ipmi_config | cut -d= -f2) \
sensor list

六、安全加固建议

6.1 网络隔离

1
2
3
# IPMI 管理网口应独立于业务网络
# 建议配置专用 VLAN
# 禁止从公网直接访问 IPMI

6.2 用户安全

1
2
3
4
5
6
7
8
9
10
11
12
13
# 1. 修改默认密码(出厂默认通常是 admin/admin)
# 2. 删除或禁用默认用户
# 3. 创建专用运维账号
# 4. 定期更换密码

# 禁用默认用户(用户 ID 1)
ipmitool user disable 1

# 创建新用户
ipmitool user set name 5 ops_user
ipmitool user set password 5 NewSecurePass456
ipmitool user enable 5
ipmitool user privilege 5 3 # 3 = Operator

6.3 固件升级

1
2
3
4
5
# 检查 BMC 固件版本
ipmitool mc info | grep "Firmware Revision"

# 升级 BMC 固件(需从厂商获取)
ipmitool mc update <firmware_file.bin>

七、常见问题排查

7.1 无法连接 IPMI

1
2
3
4
5
6
7
8
9
10
11
# 1. 检查网络连通性
ping <BMC_IP>

# 2. 检查端口是否开放
nc -zu <BMC_IP> 623

# 3. 检查 IPMI 服务
systemctl status ipmid

# 4. 重启 IPMI 服务
systemctl restart ipmid

7.2 传感器读数异常

1
2
3
4
5
# 重置传感器
ipmitool mc reset cold

# 等待 2-3 分钟后重新读取
ipmitool sensor list

7.3 SEL 日志满

1
2
3
4
5
# 备份日志
ipmitool sel elist > sel_backup_$(date +%Y%m%d).log

# 清除日志
ipmitool sel clear

八、自动化监控脚本示例

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#!/bin/bash
# ipmi_health_check.sh

BMC_IP="192.168.100.10"
USER="admin"
PASS="YourPassword"
LOG_FILE="/var/log/ipmi_health.log"

# 检查电源状态
POWER_STATUS=$(ipmitool -I lanplus -H $BMC_IP -U $USER -P $PASS power status 2>/dev/null)
echo "$(date) - Power: $POWER_STATUS" >> $LOG_FILE

# 检查温度告警
TEMP_ALERT=$(ipmitool -I lanplus -H $BMC_IP -U $USER -P $PASS sensor list 2>/dev/null | grep -i "temp" | grep -v "ok")
if [ -n "$TEMP_ALERT" ]; then
echo "$(date) - Temperature Alert: $TEMP_ALERT" >> $LOG_FILE
# 可在此添加告警通知
fi

# 检查 SEL 新事件
SEL_COUNT=$(ipmitool -I lanplus -H $BMC_IP -U $USER -P $PASS sel list 2>/dev/null | wc -l)
echo "$(date) - SEL Events: $SEL_COUNT" >> $LOG_FILE

九、总结

IPMI 是服务器运维的核心工具,掌握其配置和使用对于保障服务器稳定运行至关重要。关键要点:

  1. 网络隔离:IPMI 管理网络应与业务网络分离
  2. 安全加固:修改默认密码,禁用默认用户
  3. 定期巡检:检查传感器状态和 SEL 日志
  4. 文档记录:记录所有 BMC IP 地址和账号信息
  5. 应急预案:确保在网络故障时能通过带外管理恢复

文档版本:v1.0
最后更新:2026-03-05