服务器增强管理利器---Ipmitool

Top

智能平台管理接口 —— ipmitool 命令

	用户可以利用IPMI 监视服务器等设备的物理特征,如各部件的温度、电压、风扇工作状态、电源供应以及机箱入侵等。创建了单独在系统内运行的无代理管理子系统 — 独立于 CPU、BIOS 和操作系统的类型或条件.
	请记住,不论其他设备或组件(只要 NIC 正常运行,服务器接电)的条件如何,IPMI 自治功能都能使其正常工作。IPMI 可以监测和控制其他系统组件以最大限度地降低对系统的整体影响,同时能够发送消息派遣技术人员。IPMI 的预告故障能力也有助于 IT 周期的管理。通过检查系统事件日志 (SEL),可以更轻松的预先判定故障组件。
	IPMI协议被广泛用于服务器监控中,包括采集CPU温度、风扇转速、主板温度,以及远程开关机等等。而且IPMI独立于硬件和操作系统,无论是CPU、BIOS,还是OS出现故障,都不会影响IPMI的工作。因为IPMI的硬件设备BMC(Baseboard Management Controller)是一个独立的板卡,独立供电。
	使用IPMI监控服务器主要有两种模式:本地和远程。
	在命令传输的安全性方面,用户也无需担心,IPMI增强的认证(基于安全哈希算法1和基于密钥哈希消息认证)和加密(高级加密标准和Arcfour)功能有助于实现安全的远程操作。对VLAN的支持更是为设置管理专用网络提供了方便,并且可以以通道为基础进行配置
	服务器IPMI使用的端口一般是623.
	如果没有-I选项,ipmitool默认使用open,即Linux OpenIPMI; lanplus是lan的增强版 ; lan及lanplus主要用于远程监控
	快捷键      shift + ~ +.  是退出ipmi
远程模式下,IPMI使用RMCP,RMCP基于UDP协议实现
远程监控也就是基于UDP的网络通信
服务器IPMI使用的端口一般是623
# 接口判断
	lan及lanplus主要用于远程监控,如果没有-I选项,ipmitool默认使用open,即Linux OpenIPMI,lanplus是lan的增强版; 其中 lan 对应ipmi 1.5版本, lanplus对应ipmi 2.0版本

安装及开启服务

# 该工具一般都存在于系统安装镜像中,故可直接配置本地软件源安装 
yum install ipmitool

# 开启 ipmi 服务 
systemd start/enable ipmi.service 

下载及编译安装

Ipmitool 软件包下载

Github --- ipmitool 地址

tar -xvf ipmitool-1.8.18.tar.bz2
cd ipmitool-1.8.18
./bootstrap         # 无该文件可不执行
./configure         # 预配置, configure 文件是通过 bootstrap 脚本执行生成的,其本质则是运行 autoconf 命令生成的
sudo make           # 编译
sudo make install   # 安装 
# 安装后配置
modprobe ipmi_si
modprobe ipmi_devintf
modprobe ipmi_msghandler

# 编译 ipmitool 结束时显示的:
ipmitool 1.8.18

Interfaces
  lan     : yes
  lanplus : no
  open    : yes
  free    : no
  imb     : yes
  bmc     : no
  usb     : no
  lipmi   : no
  serial  : yes
  dummy   : no

Extra tools
  ipmievd   : yes
  ipmishell : no
  
  
  -------------------------------------------------------------
  
  
ipmitool 1.8.17

Interfaces
  lan     : yes
  lanplus : no
  open    : yes
  free    : no
  imb     : yes
  bmc     : no
  usb     : yes
  lipmi   : no
  serial  : yes
  dummy   : no

Extra tools
  ipmievd   : yes
  ipmishell : no

安装时遇到的问题和解决方案

# 错误一
configure: error: ** Unable to find readline required by ipmishell.
# 解决方案 
yum install readline-devel

# 错误二
如果autoconf命令执行时报以上错误,那么执行以下命令来更新生成的配置文件
# 解决方案
autoreconf --install

# 错误三 
** The lanplus interface requires an SSL library with EVP_aes_128_cbc defined.
# 解决方案 
yum install openssl-devel

# 错误四
在configure过程中可能会出现大量的GCC extension的告警,可以忽略,不会影响最后ipmitool的命令使用。
../include/ipmitool/ipmi_entity.h:45:2: **warning**: type of bit-field 'logical' is **a GCC extension** [-Wpedantic]
1


# 注意一
如果要使用 anplus,在编译时要加上启用 anplus 项: 
./configure --enable-intf-lanplus

选项及含义

选项 含义
-I【大写的 i 】 指定接口
-H 主机
-U 用户名
-P 密码

子命令及功能

raw       # 发送一个原始的IPMI请求,并且打印回复信息
lan       # 配置网络(lan)信道(channel)
chassis   # 查看底盘的状态和配置电源
event     # 向BMC发送一个已定义的事件(event),可用于测试配置的SNMP是否成功
mc        # 查看MC(Management Contollor)状态和各种允许的项
sdr       # 打印传感器仓库中的任何监控项和从传感器读取到的值。
sensor    # 打印周详的传感器信息。
Fru       # 打印内建的Field Replaceable Unit (FRU)信息
sel       #  打印 System Event Log (SEL)      
pef       # 配置 Platform Event Filtering (PEF),事件过滤平台用于在监控系统发现有event时候,用PEF中的策略进行事件过滤,然后看是否需要报警。
sol/isol  # 用于配置通过串口的Lan进行监控
user      # 配置BMC中用户的信息 。
channel   # 配置Management Controller信道。

加载相关驱动

modprobe ipmi_watchdog;modprobe ipmi_poweroff;modprobe ipmi_devintf;modprobe ipmi_si;modprobe ipmi_msghandler

命令示例

用户管理

# 查看用户列表
ipmitool user list 1 
# 增加管理用户(重置IPMI账号密码):
ipmitool user set name 2 root;ipmitool user set password 2 123456;ipmitool user list 1
ipmitool user set password <用户ID> "123456"   # 更改密码
# 激活与关闭用户; enable后Privilege Level为USER,disable后Privilege Level为NO ACCESS
ipmitool user <enabled/disable> <用户ID>

权限管理

# 查看授权
ipmitool channel getaccess 1 <用户ID>
# 设置用户权限  ---> on为开启、off为关闭,是该用户对于通道的权限
ipmitool channel setaccess 1 用户ID callin=on ipmi=on link=on privilege=<等级>
# privilege 的可选等级如下:
1 callback
2 user
3 operator
4 administrator
5 OEM

查看网络配置

# 查看 BMC 专用口信息
ipmitool lan print 1
# 查看 BMC 复用管理口信息 
ipmitool lan print 8
# 查询 BMC 专用口的 MAC 地址
ipmitool -I lanplus -H 172.16.6.222 -U root -P password lan print 1 | sed '/MAC Address/p' -n
# 带内更改 ip 
ipmitool lan set 1 ipsrc static
ipmitool lan set 1 ipaddr 192.168.1.2
ipmitool lan set 1 netmask 255.255.255.0
ipmitool lan set 1 defgw ipaddr 192.168.1.1

获取传感器数据

ipmitool sdr list     # 传感器简洁数据 , 左边第一列是Sensor ID,第二列是Sensor Readings
ipmitool -v sdr list  # 传感器详细数据

打印系统 SEL Log

ipmitool sel list 

查看BMC信息

ipmitool mc info

电源管理

ipmitool power off    # 硬关机,直接切断电源
ipmitool power soft   # 软关机,即如同轻按一下开机扭
ipmitool power on     # 硬开机
ipmitool power reset  # 硬重启
ipmitool power status # 获取当前电源状态
ipmitool power cycle  # 注意power cycle 和power reset的区别在于前者从掉电到上电有1秒钟的间隔,而后者是很快上电

测试远程服务器是否可以ping通,是, 则可以 远程管理该主机

ipmitool -I lanplus -H 172.16.6.222 -U root -P password sol activate > xxxxx.log 

强制重启(关闭或开启)被监控服务器

ipmitool -I lanplus -H x.x.x.x -U root -P password chassis power reset (off on)

SDS日志下载

ipmitool raw 0x36 0x08 0x20 0x14 0x00 0x01 0x00 0x01 0x04 0xac 0x10 0x6c 0xa7 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 # 需打开 tftp 工具

重定向 SOL 到 BMC (修改 shell 路径 )

# 修改波特率,  有的机器也可在 Bios 下改 
ipmitool -H (BMC的管理IP地址) -I lanplus -U (BMC登录用户名) -P (BMC 登录用户名的密码) sol set volatile-bit-rate 38.4
# 0x00:主机; 0x01:BMC;  0x02:RAID ; 0X03:智能网卡
ipmitool -I lanplus -H 172.16.20.45 -U admin -P Password@_ raw 0x36 0x09 0xa2 0x63 0x00 0x38 0x01
ipmitool -I lanplus -H 172.16.20.45 -U admin -P Password@_ sol activate
# 默认的 shell 路径是bmc shell,重新修改默认shell为/bin/sh之后可以使用sysadmin账号,但是这个是不对外开放的
# sysadmin 的用户只能在 HDM 的 debug 版本下,使用 ssh 才能登录
cat /mnt/sdmmc0p4/bios/BiosBeforeBoot.json  

重定向 SOL 到 BIOS (修改 shell 路径 )

# 修改波特率,  有的机器也可在 Bios 下改 
ipmitool -H (BMC的管理IP地址) -I lanplus -U (BMC登录用户名) -P (BMC 登录用户名的密码) sol set volatile-bit-rate 115.2
# 说明:<9.6/19.2/38.4/57.6/115.2>其中115.2代表115200,即*1000是表示的波特率。
# 开启 SOL 
ipmitool -H 172.17.28.34 -I lanplus -U admin -P Password@_ sol set enabled true 1
# 切换 Bios 或者拨动 第二个拨码 
ipmitool -H 127.0.0.1 -I lanplus -U admin -P admin raw  0x36 0x09 0xa2 0x63 0x00 0x27 0x01
ipmitool -I lanplus -H 172.16.20.45 -U admin -P Password@_ sol activate

新增用户, 且设置为administrator 权限,

ipmitool -I lanplus -H 172.16.20.45 -U admin -P Password@_ user set name 10 liang
ipmitool -I lanplus -H 172.16.20.45 -U admin -P Password@_ user set password 10 Password@_
ipmitool -I lanplus -H 172.16.20.45 -U admin -P Password@_ user priv 10 4

获取服务器功耗

ipmitool sensor | grep -i watts  

# CPU 加压 
stress --cpu <CPU个数>
# 全系统下限制 CPU 压力
cpulimit -l <CPU压力百分比数>  -p <进程Pid>
# 限制某个程序的 CPU 压力 
cpulimit -e <可执行程序文件名或路径名> -l <CPU压力百分比数> 

# 参数说明
Usage: cpulimit [OPTIONS...] TARGET
   OPTIONS
      -l, --limit=N          允许的CPU百分比(从0到100),乘上线程数(必填)
      -v, --verbose          显示控制统计结果
      -z, --lazy             如果没有目标进程,或者目标进程终止,则退出
      -i, --include-children 限制附属(子)进程
      -h, --help             display this help and exit
   TARGET must be exactly one of these:
      -p, --pid=N            进程的pid (implies -z)
      -e, --exe=FILE         可执行程序文件名或路径名
      COMMAND [ARGS]         run this command and limit it (implies -z)

切换主线版本

# 设置 custom id
ipmitool -I lanplus -U admin -P Password@_ -H 172.16.12.201 raw 0x36 0x02 0x20 0x14 0x00 0x80 0xd1 0x01 0x02 <0x01/00/02/03/04/06> 
---00主线,01 百度,02 乐视(G3 上表示腾讯),03 京东,04 京东金融,06移动 
ipmitool -I lanplus -H 172.16.72.140 -U admin -P Password@_ raw 0x36 0x02 0x20 0x14 0x00 0x80 0xd1 0x01 0x02 0x11
# 查询 custom id
ipmitool -I lanplus -U admin -P Password@_ -H 172.16.12.201 raw 0x36 0x02 0x20 0x14 0x00 0x80 0xd1 0x01 0x01

BMC 恢复出厂设置

ipmitool -I lanplus -U admin -P Password@_ -H 172.16.12.201 raw 0x32 0x66

海光 3 号机器 设置 HDM 网口 Mac 地址

# 测试流程:
1.查看装备模式
ipmitool raw 0x36 0x02 0x20 0x14 0x00 0x80 0xcb 0x01 0x00
2.打开装备模式
ipmitool raw 0x36 0x02 0x20 0x14 0x00 0x80 0xcb 0x01 0x01 0x01
3.关闭装备模式
ipmitool raw 0x36 0x02 0x20 0x14 0x00 0x80 0xcb 0x01 0x01 0x00  
# 海光机器 3 号机器 进入 BMC 串口需拨动主板上的第二个拨码
# 海光机器 3 号机器 永久更新设置 BMC 口的 Mac 地址,  
ipmitool -I lanplus -H 172.16.101.101 -U admin -P Password@_ raw 0x36 0x09 0xa2 0x63 0x00 0x38 0x01
# 设置专用口的 Mac 地址,倒数第 8 个字段:0x02; 后 6 个为具体的 Mac 地址,Mac 地址第一段最低位不能为 1 
ipmitool -I lanplus -H 172.16.101.101 -U admin -P Password@_ raw 0x36 0x02 0x20 0x14 0x00 0x80 0x57 0x02 0x00 0xc4 0x34 0x6b 0x3f 0x01 0x01
# 设置共享口的 Mac 地址,倒数第 8 个字段:0x01; 后 6 个为具体的 Mac 地址 
ipmitool -I lanplus -H 172.16.101.101 -U admin -P Password@_ raw 0x36 0x02 0x20 0x14 0x00 0x80 0x57 0x01 0x00 0xc4 0x34 0x6b 0x3f 0x01 0x01

刷机器 FRU 信息

# 查看机器 FRU 信息
ipmitool -I lanplus -H 10.99.74.34 -U admin -P Password@_  fru list 
# 刷新
ipmitool.exe -H 10.99.74.35 -I lanplus -U admin -P Password@_ fru edit 0 field p 0 "New H3C Technologies Co., Ltd."
ipmitool.exe -H 10.99.60.48 -I lanplus -U admin -P Password@_ fru edit 0 field p 1 "H3C UniServer R4950 G5"

IP 地址设置

ipmitool lan set 0x01 ipsrc static
ipmitool lan set 0x01 ipaddr 172.16.2.111
ipmitool lan set 0x01 netmask 255.255.128.0
# Frutool 工具的使用方法
please run this script by the following format:
CID read : frutool -H 172.16.1.1 -U admin -P password -F cid -m R
CID write: frutool -H 172.16.1.1 -U admin -P password -F cid -m w -C 2
FRU read : frutool -H 172.16.1.1 -U admin -P password -F fru -m r -p 1
FRU write: frutool -H 172.16.1.1 -U admin -P password -F fru -m w -p 1
IPMITOOL : frutool -H 172.16.1.1 -U admin -P password lan print
IPMITOOL : frutool -H 172.16.1.1 -U admin -P password raw 0x06 0x01

通道管理

# 显示通道信息
ipmitool channel info
# 修改通道的优先级别
ipmitool channel  authcap channel-number privilege
# 读取用户在通道上的权限
ipmitool channel getaccess <通道ID>  <用户ID>
# 设置用户在通道上的权限
ipmitool channel setaccess <通道ID>  <用户ID> callin=on ipmi=on link=on privilege=<等级>
# 通道开关
ipmitool lan set <通道ID> access <on / off>

其他

阿里云机器 自定制子命令

# 查看 bios 简要信息
ipmitool alibios me
# 查看 Bios 版本信息
ipmitool alioem version
# 获取节点主要部件PN/SN信息
ipmitool alioem getsmbiosinformation
# 查看 PSU 信息
ipmitool alioem getdeviceinformation
# AC 重启 
ipmitool -I lanplus -H 172.16.162.78 -U taobao -P '9ijn0okm' raw 0x3e 0x9c 0x00 0x4c 0xa5 0x41 0x43 0x43 0x79 0x63 0x6c 0x65
# BMC 重启
ipmitool mc reset cold

# 查询 ipmi 版本
dmidecode |sed -n '/IPMI/,+5p'  或者 'ipmitool mc info | grep -i ipmi'

# 在系统下获取 HDM ip  
ipmitool.exe -H 172.16.22.55 -I lanplus -U admin -P Password@_ lan print 1

# I2C的运用:
串口下输入i2c-test能看到回显提示
常用的参数:
-b           bus
-s           slave(需要右移一位)
-w           write
-d           偏移量
-m 1         模式 1
-rc          读取长度
i2c-test -b xx -s xx -m 1 -rc 256 -d 0x00
从0开始读256字节
例如:  读取 i2c拓扑图中bus 6   0xE0寄存器 下的 ch2 ,连接的设备  0xE2寄存器下的ch3 的  0xA0寄存器的  从0x10开始 的32个字节数据
       输入:    
       i2c-test –b 5 –s 0x70 –w –d 0x02; 
       i2c-test –b 5 –s 0x71 –w –d 0x04; 
       i2c-test –b 5 –s 0x50 –m 1 –rc 32 –d 0x10
       扫描当前选路下,能看到的寄存器   i2c-test –b 5 --scan         
注意:0xE0是一级选路地址,0xE2是二级选路地址, 0xA0是二级选路下的某个地址
使用i2c之前关进程步骤:
cpuregtool WDT -w 4 0x0c 0x12           //关狗
串口下输入top   查看进程pid
如: 
954     1 sysadmin S     795m221.2   0  0.0 /usr/local/bin/IPMIMain --daemoniz
2396     1 sysadmin S     103m 28.6   0  0.0 ./compmanager
输入kill -stop 954 2396 关掉进程

完成i2c操作之后打开进程、开启看门狗
kill -cont 954 2396
cpuregtool WDT -w 4 0x0c 0x13 
# 例如
cd /var/BiosPush/ 
cat BiosBeforeBoot.json 
i2c-test -b 8 -s 0x70 -w -d 0x04;i2c-test -b 8 --scan 

HDM---RESTFul 手册记录

参考命令

ipmitool 常用命令

ipmitool 命令记录

ipmi 安装 及 常用记录

ipmitool获取服务器信息

报错: lanplus_crypt_impl.c:167:24: error: storage size of ‘ctx’ isn’t known 只解决方案

获取 TOKEN

https://172.16.20.45/api/session?username=admin&password=Password@_&log_type=0
# 使用 HDM 登录的 用户名和密码
posted @ 2023-11-24 15:41  梭梭666  阅读(1694)  评论(0编辑  收藏  举报
返回顶部