ipmitool:伺服器自動化控制風扇轉速

首先安裝ipmitool:

apt install ipmitool

啟用ipmi 系統模塊:

modprobe ipmi_si
modprobe ipmi_devintf
echo ipmi_si >> /etc/modprobe
echo ipmi_devintf >> /etc/modprobe

確認 ipmi 運作狀態:

ipmitool lan print

建立執行檔:

nano fan.sh
#!/bin/bash
#
# chmod +x /root/fan.sh
#
DATE=$(date +%Y-%m-%d-%H%M%S)
echo "$DATE"
#Setting Fan speed to 15%
#STATICSPEEDBASE16="0x0f"
#Setting Fan speed to 26%
STATICSPEEDBASE16="0x1a"
#HighSpeed 50%
HighSpeed="0x32"
TEMPTHRESHOLD="31"
#
T=$(ipmitool sdr type temperature | cut -d"|" -f5 | cut -d" " -f2)
echo "-- current temperature --"
echo "$T"
#
if [[ $T > $TEMPTHRESHOLD ]]
  then
    echo "--> Enable dynamic fan control"
    ipmitool raw 0x30 0x30 0x01 0x01
elif [[ $T = 30 ]]
  then 
    echo "--> Set Fan to High Speed control"
    ipmitool raw 0x30 0x30 0x01 0x00
    echo "--> set static fan speed"
    ipmitool raw 0x30 0x30 0x02 0xff $HighSpeed
  else
    echo "--> disable dynamic fan control"
    ipmitool raw 0x30 0x30 0x01 0x00
    echo "--> set static fan speed"
    ipmitool raw 0x30 0x30 0x02 0xff $STATICSPEEDBASE16
fi

執行之後就會出現以下結果:

2019-11-24-025602
-- current temperature --
28
41
--> disable dynamic fan control

--> set static fan speed

建立 crontab 任務:

crontab -e
#10min check
*/10 * * * * sudo bash /root/fan.sh
#5min check
*/5 * * * * sudo bash /root/fan.sh

享受安靜風扇噪音~

阅读剩余
THE END