ipmitool 使用(一)

IPMI(Intelligent Platform Management Interface) 就是一个管理硬件的标准,目前主要有 1.5 以及 2.0 版本。基本想到的诸如电压、风扇、温度等都能获取到。其实就是一个小型的 OS,独立于服务器,叫 BMC(Baseboard Management controller),可以通过 IPMI 来控制服务器的 on/off。详细的原理解释可以看这里

一般 DELL,HP 的服务器都有支持该协议,可以通过 dmidecode 来 grep ipmi 看看支不支持。
*nix 上可以通过 ipmoitools 来管理,Ubuntu 10.04 可以通过下面这个命令来安装:
$ sudo apt-get install ipmitool

2.6 的内核需要加载如下的模块:
$ sudo modprobe ipmi_devintf
$ sudo modprobe ipmi_si
$ sudo modprobe ipmi_msghandler

ipmitool 提供了交互式以及非交互式的方式来管理,下面这个初始化就是通过交互式的方式进行的。一台刚上架的服务器可以通过下面的方式进行管理 IP 的配置。首先是设置远程卡的用户名密码:
$ ipmitool shell
ipmitool> user set name 2 jaseywang
ipmitool> user enable 2
ipmitool> user set password 2 fuckyou
ipmitool> channel setaccess 1 2 ipmi=on link=on privilege=4


接着是远程卡的网段:
ipmitool> lan set 2 ipsrc static
ipmitool> lan set 2 ipaddr 192.168.111.111
ipmitool> lan set 2 netmask 255.255.255.0
ipmitool> lan set 2 defgw 192.168.111.111
ipmitool> lan set 2 access on
ipmitool> lan set 2 user

上面的以非交互式的方式进行的话,可以如下:
$ sudo ipmitool  -I lanplus -H 10.18.10.230 -U jaseywang -P fuckyou  power status

export 一下 IPMI_PASSWORD 这个变量就可以『免密码』登录了,当然也可以像上面那样通过 -P 指定:
$ export IPMI_PASSWORD=your passwd
$ sudo ipmitool  -I lanplus -H 10.18.10.230 -U jaseywang chassis status

详细的使用可以直接输入原始命令查看:
# ipmitool
No command provided!
Commands:
        raw           Send a RAW IPMI request and print response
        i2c           Send an I2C Master Write-Read command and print response
        spd           Print SPD info from remote I2C device
        lan           Configure LAN Channels
        chassis       Get chassis status and set power state
        power         Shortcut to chassis power commands
        event         Send pre-defined events to MC
        mc            Management Controller status and global enables
        sdr           Print Sensor Data Repository entries and readings
        sensor        Print detailed sensor information
        fru           Print built-in FRU and scan SDR for FRU locators
        gendev        Read/Write Device associated with Generic Device locators sdr
        sel           Print System Event Log (SEL)
        pef           Configure Platform Event Filtering (PEF)
        sol           Configure and connect IPMIv2.0 Serial-over-LAN
        tsol          Configure and connect with Tyan IPMIv1.5 Serial-over-LAN
        isol          Configure IPMIv1.5 Serial-over-LAN
        user          Configure Management Controller users
        channel       Configure Management Controller channels
        session       Print session information
        sunoem        OEM Commands for Sun servers
        kontronoem    OEM Commands for Kontron devices
        picmg         Run a PICMG/ATCA extended cmd
        fwum          Update IPMC using Kontron OEM Firmware Update Manager
        firewall      Configure Firmware Firewall
        delloem       OEM Commands for DELL systems
        shell         Launch interactive IPMI shell
        exec          Run list of commands from file
        set           Set runtime variable for shell and exec
        hpm           Update HPM components using PICMG HPM.1 file
        ekanalyzer    run FRU-Ekeying analyzer using FRU files

help 提示做的也很不错,比如输入上面的 mc:
# ipmitool mc help
MC Commands:
  reset <warm|cold>
  guid
  info
  watchdog <get|reset|off>
  selftest
  getenables
  setenables <option=on|off> …
    recv_msg_intr         Receive Message Queue Interrupt
    event_msg_intr        Event Message Buffer Full Interrupt
    event_msg             Event Message Buffer
    system_event_log      System Event Logging
    oem0                  OEM 0
    oem1                  OEM 1
    oem2                  OEM 2

系统会提示你接下来可以使用的参数。下面列举的是一些常用的,具体不解释了:
mc info
power on
power off
lan print 1
channel info 1
chassis status
sdr elist full
sdr type temperature
sel list
fru print

差不多上面的就能获取到基本的硬件信息了,仅仅这样意义不大,把这些信息比如像温度、电压等收集起来做成监控才比较实用。

ref:
http://buttersideup.com/docs/howto/IPMI_on_Debian.html
http://ivoks.blogspot.jp/2008/09/full-control-over-server.html
http://docs.oracle.com/cd/E19464-01/820-6850-11/IPMItool.html
http://support.dell.com/support/edocs/software/smbmcmu/bmcmu_4_0/cs/ug/bmcugc0d.htm#wp1067804