原文鏈接:http://blog.csdn.net/lufeisan/article/details/53398756
http://blog.chinaunix.net/uid-25135004-id-3139293.html
MegaCli是一款管理維護硬件RAID軟件,可以通過它來了解當前raid卡的所有信息,包括 raid卡的型號,raid的陣列類型,raid 上各磁盤狀態,等等。通常,我們對硬盤當前的狀態不太好確定,一般通過機房人員巡檢來完成,有沒有通過軟件的方式來檢查確定這個問題呢。MegaCli就可以做到,一般通過 MegaCli 的Media Error Count: 0 Other Error Count: 0 這兩個數值來確定陣列中磁盤是否有問題;Medai Error Count 表示磁盤可能錯誤,可能是磁盤有壞道,這個值不爲0值得注意,數值越大,危險係數越高,Other Error Count 表示磁盤可能存在鬆動,可能需要重新再插入。MegaCli 可以對陣列中所有的磁盤進行檢測,我們可以通過腳本的方式來檢測相關參數,從而通知管理人員。
一、 下載MegCli,目前針對公司DB數據庫是IBM的服務器,直接從IBM官方下載,如果
其它服務器的,使用各官方下載或者 LSI網站上進行相關下載。一般來說,是通用的。這個包適用32 /64位操作系統平臺
下載地址:ftp://download2.boulder.ibm.com/ecc/sar/CMA/XSA/ibm_utl_sraidmr_megacli-8.00.48_linux_32-64.zip
#unzip ibm_utl_sraidmr_megacli-8.00.48_linux_32-64.zip
#cd linux
# rpm -ivh Lib_Utils-1.00-09.noarch.rpm MegaCli-8.00.48-1.i386.rpm
說明:安裝完畢之後MegaCli64所在路徑爲/opt/MegaRAID/MegaCli/MegaCli64,在此路徑下可以運行MegaCli64工具,切換到其它路徑下則不能執行,此時爲了使用方便,可以考慮將/opt/MegaRAID/MegaCli/MegaCli64追加到系統PATH變量,或者像下面這樣做(建議):
ln -s /opt/MegaRAID/MegaCli/MegaCli64 /bin/MegaCli64
ln -s /opt/MegaRAID/MegaCli/MegaCli64 /sbin/MegaCli64
三 使用命令及參數
- 命令使用:
- #/opt/MegaRAID/MegaCli/MegaCli64 -LDInfo -Lall -aALL 查raid級別
- #/opt/MegaRAID/MegaCli/MegaCli64 -AdpAllInfo -aALL 查raid卡信息
- #/opt/MegaRAID/MegaCli/MegaCli64 -PDList -aALL 查看硬盤信息
- #/opt/MegaRAID/MegaCli/MegaCli64 -AdpBbuCmd -aAll 查看電池信息
- #/opt/MegaRAID/MegaCli/MegaCli64 -FwTermLog -Dsply -aALL 查看raid卡日誌
- #/opt/MegaRAID/MegaCli/MegaCli64 -adpCount 【顯示適配器個數】
- #/opt/MegaRAID/MegaCli/MegaCli64 -AdpGetTime –aALL 【顯示適配器時間】
- #/opt/MegaRAID/MegaCli/MegaCli64 -AdpAllInfo -aAll 【顯示所有適配器信息】
- #/opt/MegaRAID/MegaCli/MegaCli64 -LDInfo -LALL -aAll 【顯示所有邏輯磁盤組信息】
- #/opt/MegaRAID/MegaCli/MegaCli64 -PDList -aAll 【顯示所有的物理信息】
- #/opt/MegaRAID/MegaCli/MegaCli64 -AdpBbuCmd -GetBbuStatus -aALL |grep ‘Charger Status’ 【查看充電狀態】
- #/opt/MegaRAID/MegaCli/MegaCli64 -AdpBbuCmd -GetBbuStatus -aALL【顯示BBU狀態信息】
- #/opt/MegaRAID/MegaCli/MegaCli64 -AdpBbuCmd -GetBbuCapacityInfo -aALL【顯示BBU容量信息】
- #/opt/MegaRAID/MegaCli/MegaCli64 -AdpBbuCmd -GetBbuDesignInfo -aALL 【顯示BBU設計參數】
- #/opt/MegaRAID/MegaCli/MegaCli64 -AdpBbuCmd -GetBbuProperties -aALL 【顯示當前BBU屬性】
- #/opt/MegaRAID/MegaCli/MegaCli64 -cfgdsply -aALL 【顯示Raid卡型號,Raid設置,Disk相關信息】
- 3.磁帶狀態的變化,從拔盤,到插盤的過程中。
- Device |Normal|Damage|Rebuild|Normal
- Virtual Drive |Optimal|Degraded|Degraded|Optimal
- Physical Drive |Online|Failed –> Unconfigured|Rebuild|Online
- 4.查看磁盤緩存策略
- #/opt/MegaRAID/MegaCli/MegaCli64 -LDGetProp -Cache -L0 -a0
- or
- #/opt/MegaRAID/MegaCli/MegaCli64 -LDGetProp -Cache -L1 -a0
- or
- #/opt/MegaRAID/MegaCli/MegaCli64 -LDGetProp -Cache -LALL -a0
- ro
- #/opt/MegaRAID/MegaCli/MegaCli64 -LDGetProp -Cache -LALL -aALL
- ro
- #/opt/MegaRAID/MegaCli/MegaCli64 -LDGetProp -DskCache -LALL -aALL
- 5.設置磁盤緩存策略
- 緩存策略解釋:
- WT (Write through
- WB (Write back)
- NORA (No read ahead)
- RA (Read ahead)
- ADRA (Adaptive read ahead)
- Cached
- Direct
- 例子:
- #/opt/MegaRAID/MegaCli/MegaCli64 -LDSetProp WT|WB|NORA|RA|ADRA -L0 -a0
- or
- #/opt/MegaRAID/MegaCli/MegaCli64 -LDSetProp -Cached|-Direct -L0 -a0
- or
- enable / disable disk cache
- #/opt/MegaRAID/MegaCli/MegaCli64 -LDSetProp -EnDskCache|-DisDskCache -L0 -a0
- 6.創建一個 raid5 陣列,由物理盤 2,3,4 構成,該陣列的熱備盤是物理盤 5
- #/opt/MegaRAID/MegaCli/MegaCli64 -CfgLdAdd -r5 [1:2,1:3,1:4] WB Direct -Hsp[1:5] -a0
- 7.創建陣列,不指定熱備
- #/opt/MegaRAID/MegaCli/MegaCli64 -CfgLdAdd -r5 [1:2,1:3,1:4] WB Direct -a0
- 8.刪除陣列
- #/opt/MegaRAID/MegaCli/MegaCli64 -CfgLdDel -L1 -a0
- 9.在線添加磁盤
- #/opt/MegaRAID/MegaCli/MegaCli64 -LDRecon -Start -r5 -Add -PhysDrv[1:4] -L1 -a0
- 10.陣列創建完後,會有一個初始化同步塊的過程,可以看看其進度。
- #/opt/MegaRAID/MegaCli/MegaCli64 -LDInit -ShowProg -LALL -aALL
- 或者以動態可視化文字界面顯示
- #/opt/MegaRAID/MegaCli/MegaCli64 -LDInit -ProgDsply -LALL -aALL
- 11.查看陣列後臺初始化進度
- #/opt/MegaRAID/MegaCli/MegaCli64 -LDBI -ShowProg -LALL -aALL
- 或者以動態可視化文字界面顯示
- #/opt/MegaRAID/MegaCli/MegaCli64 -LDBI -ProgDsply -LALL -aALL
- 12.指定第 5 塊盤作爲全局熱備
- #/opt/MegaRAID/MegaCli/MegaCli64 -PDHSP -Set [-EnclAffinity] [-nonRevertible] -PhysDrv[1:5] -a0
- 13.指定爲某個陣列的專用熱備
- #/opt/MegaRAID/MegaCli/MegaCli64 -PDHSP -Set [-Dedicated [-Array1]] [-EnclAffinity] [-nonRevertible] -PhysDrv[1:5] -a0
- 14.刪除全局熱備
- #/opt/MegaRAID/MegaCli/MegaCli64 -PDHSP -Rmv -PhysDrv[1:5] -a0
- 15.將某塊物理盤下線/上線
- #/opt/MegaRAID/MegaCli/MegaCli64 -PDOffline -PhysDrv [1:4] -a0
- #/opt/MegaRAID/MegaCli/MegaCli64 -PDOnline -PhysDrv [1:4] -a0
- 16.查看物理磁盤重建進度
- #/opt/MegaRAID/MegaCli/MegaCli64 -PDRbld -ShowProg -PhysDrv [1:5] -a0
- 或者以動態可視化文字界面顯示
- #/opt/MegaRAID/MegaCli/MegaCli64 -PDRbld -ProgDsply -PhysDrv [1:5] -a0
- 磁帶狀態的變化,從拔盤,到插盤的過程中:
- Device |Normal|Damage|Rebuild|Normal
- Virtual Drive |Optimal|Degraded|Degraded|Optimal
- Physical Drive |Online|Failed –> Unconfigured|Rebuild|Online
/opt/MegaRAID/MegaCli/MegaCli64 -ldgetprop -dskcache -lall -aall
5、 raid 電池設置相關
查看電池狀態信息(Display BBU Status Information)
MegaCli -AdpBbuCmd -GetBbuStatus -aN|-a0,1,2|-aALL
MegaCli -AdpBbuCmd -GetBbuStatus -aALL
查看電池容量(Display BBU Capacity Information)
MegaCli -AdpBbuCmd -GetBbuCapacityInfo -aN|-a0,1,2|-aALL
MegaCli -AdpBbuCmd -GetBbuCapacityInfo –aALL
查看電池設計參數(Display BBU Design Parameters)
MegaCli -AdpBbuCmd -GetBbuDesignInfo -aN|-a0,1,2|-aALL
MegaCli -AdpBbuCmd -GetBbuDesignInfo –aALL
查看電池屬性(Display Current BBU Properties)
MegaCli -AdpBbuCmd -GetBbuProperties -aN|-a0,1,2|-aALL
MegaCli -AdpBbuCmd -GetBbuProperties –aALL
設置電池爲學習模式爲循環模式(Start BBU Learning Cycle)
Description Starts the learning cycle on the BBU.
No parameter is needed for this option.
MegaCli -AdpBbuCmd -BbuLearn -aN|-a0,1,2|-aALL
設置磁盤的緩存模式和訪問方式 (Change Virtual Disk Cache and Access Parameters)
Description Allows you to change the following virtual disk parameters:
-WT (Write through), WB (Write back): Selects write policy.
-NORA (No read ahead), RA (Read ahead), ADRA (Adaptive read ahead): Selects read policy.
-Cached, -Direct: Selects cache policy.
-RW, -RO, Blocked: Selects access policy.
-EnDskCache: Enables disk cache.
-DisDskCache: Disables disk cache.
MegaCli -LDSetProp { WT | WB|NORA |RA | ADRA|-Cached|Direct} |
{-RW|RO|Blocked} |
{-Name[string]} |
{-EnDskCache|DisDskCache} –Lx |
-L0,1,2|-Lall -aN|-a0,1,2|-aALL
MegaCli -LDSetProp WT -L0 -a0
顯示磁盤緩存和訪問方式(Display Virtual Disk Cache and Access Parameters)
MegaCli -LDGetProp -Cache | -Access | -Name | -DskCache -Lx|-L0,1,2|
-Lall -aN|-a0,1,2|-aALL
Displays the cache and access policies of the virtual disk(s):
-WT (Write through), WB (Write back): Selects write policy.
-NORA (No read ahead), RA (Read ahead), ADRA (Adaptive read ahead): Selects read policy.
-Cache, -Cached, Direct: Displays cache policy.
-Access, -RW, -RO, Blocked: Displays access policy.
-DskCache: Displays physical disk cache policy.
Megaraid 必知必會 使用LSI的megaraid可以對raid進行有效監控。別的廠商比如HP,IBM也有自己的raid API
MegaCli -ldinfo -lall -aall
查詢raid級別,磁盤數量,容量,條帶大小。
MegaCli -cfgdsply -aALL |grep Policy
查詢控制器cache策略
MegaCli -LDSetProp WB -L0 -a0
設置write back功能
MegaCli -LDSetProp CachedBadBBU -L0 -a0
設置即使電池壞了還是保持WB功能
MegaCli -AdpBbuCmd -BbuLearn a0
手動充電
MegaCli -FwTermLog -Dsply -aALL
查詢日誌
顯示適配器個數: MegaCli -adpCount
顯示所有適配器信息: MegaCli -AdpAllInfo -aAll
Critical Disks : 0
Failed Disks : 0
顯示所有邏輯磁盤組信息: MegaCli -LDInfo -LALL -aAll
顯示所有的物理信息: MegaCli -PDList -aAll
Media Error Count: 0
Other Error Count: 0
查看充電狀態: MegaCli -AdpBbuCmd -GetBbuStatus -aALL
Learn Cycle Requested : No
Fully Charged : Yes
顯示BBU(後備電池)狀態信息: MegaCli -AdpBbuCmd -GetBbuStatus -aALL
顯示BBU容量信息: MegaCli -AdpBbuCmd -GetBbuCapacityInfo -aALL
顯示BBU設計參數: MegaCli -AdpBbuCmd -GetBbuDesignInfo -aALL
顯示當前BBU屬性: MegaCli -AdpBbuCmd -GetBbuProperties -aALL
顯示Raid卡型號,Raid設置,Disk相關信息: MegaCli -cfgdsply -aALL
查看Cache 策略設置: MegaCli -cfgdsply -aALL |grep -i Policy
Current Cache Policy: WriteBack, ReadAheadNone, Direct, Write Cache OK if Bad BBU
查看充電進度百分比: MegaCli -AdpBbuCmd -GetBbuStatus -aALL
各種設備和磁盤的不同狀態:
Device |Normal|Damage|Rebuild|Normal
Virtual Drive |Optimal|Degraded|Degraded|Optimal
Physical Drive |Online|Failed –> Unconfigured|Rebuild|Online
6、 通過腳本檢測RAID 磁盤狀態
Linux下腳本
#!/bin/bash
#check raid disk status
MEGACLI="/opt/MegaRAID/MegaCli/MegaCli64 "
$MEGACLI -pdlist -aALL | grep "Firmware state" | awk -F : '{print $2}' | awk -F , '{print $1}' >/tmp/fireware.log
$MEGACLI -pdlist -aALL | grep -E "Media Error|Other Error" | awk -F : '{print $2}' >/tmp/disk.log
for i in `cat < /tmp/disk.log`
do
if [ $i -ne 0 ]
then
curl "http://xxxxxxB&state=ALARM&description=raid_disk_error"
fi
done
for i in `cat < /tmp/fireware.log`
do
if [ $i != Online ]
then
curl "http://xxxxxxstate=ALARM&description=raid_disk_offline"
fi
done
Windows 下腳本
Windows下腳本用的工具是gnu for windows平臺的一些軟件,如 bash grep awk cat
通過bash直接調用腳本
如:G:\raid_check\unixtools>bash.exe G:\disk.sh
#check raid disk status
MEGACLI="//G/raid_check/MegaCli.exe"
GREP="//G/raid_check/unixtools/grep.exe"
AWK="//G/raid_check/unixtools/awk.exe"
CAT="//G/raid_check/unixtools/cat.exe"
CURL="//G/raid_check/unixtools/curl.exe"
$MEGACLI -pdlist -aALL | $GREP "Firmware state" |$AWK -F: '{print $2}' |$AWK -F , '{print $1}' >//c/fireware.log
$MEGACLI -pdlist -aALL | $GREP -E "Media Error|Other Error" | $AWK -F : '{print $2}' > //c/disk.log
for i in `$CAT c:/disk.log`
do
if [ $i -ne 0 ]
then
$CURL "http://xxxxxx&description=raid_disk_error"
fi
done
for i in `$CAT c:/fireware.log`
do
if [ $i != Online ]
then
$CURL "http://xxxxx&state=ALARM&description=raid_disk_offline"
fi