MegaCli 監控raid狀態

本文轉載自:天高任鳥飛(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

三 使用命令及參數 

    命令使用:

  1. #/opt/MegaRAID/MegaCli/MegaCli64 -LDInfo -Lall -aALL 查raid級別

  2. #/opt/MegaRAID/MegaCli/MegaCli64 -AdpAllInfo -aALL 查raid卡信息

  3. #/opt/MegaRAID/MegaCli/MegaCli64 -PDList -aALL 查看硬盤信息

  4. #/opt/MegaRAID/MegaCli/MegaCli64 -AdpBbuCmd -aAll 查看電池信息

  5. #/opt/MegaRAID/MegaCli/MegaCli64 -FwTermLog -Dsply -aALL 查看raid卡日誌

  6. #/opt/MegaRAID/MegaCli/MegaCli64 -adpCount 【顯示適配器個數】

  7. #/opt/MegaRAID/MegaCli/MegaCli64 -AdpGetTime –aALL 【顯示適配器時間】

  8. #/opt/MegaRAID/MegaCli/MegaCli64 -AdpAllInfo -aAll 【顯示所有適配器信息】

  9. #/opt/MegaRAID/MegaCli/MegaCli64 -LDInfo -LALL -aAll 【顯示所有邏輯磁盤組信息】

  10. #/opt/MegaRAID/MegaCli/MegaCli64 -PDList -aAll 【顯示所有的物理信息】

  11. #/opt/MegaRAID/MegaCli/MegaCli64 -AdpBbuCmd -GetBbuStatus -aALL |grep ‘Charger Status’ 【查看充電狀態】

  12. #/opt/MegaRAID/MegaCli/MegaCli64 -AdpBbuCmd -GetBbuStatus -aALL【顯示BBU狀態信息】

  13. #/opt/MegaRAID/MegaCli/MegaCli64 -AdpBbuCmd -GetBbuCapacityInfo -aALL【顯示BBU容量信息】

  14. #/opt/MegaRAID/MegaCli/MegaCli64 -AdpBbuCmd -GetBbuDesignInfo -aALL 【顯示BBU設計參數】

  15. #/opt/MegaRAID/MegaCli/MegaCli64 -AdpBbuCmd -GetBbuProperties -aALL 【顯示當前BBU屬性】

  16. #/opt/MegaRAID/MegaCli/MegaCli64 -cfgdsply -aALL 【顯示Raid卡型號,Raid設置,Disk相關信息】

  17. 3.磁帶狀態的變化,從拔盤,到插盤的過程中。

  18. Device |Normal|Damage|Rebuild|Normal

  19. Virtual Drive |Optimal|Degraded|Degraded|Optimal

  20. Physical Drive |Online|Failed –> Unconfigured|Rebuild|Online

  21. 4.查看磁盤緩存策略

  22. #/opt/MegaRAID/MegaCli/MegaCli64 -LDGetProp -Cache -L0 -a0

  23. or

  24. #/opt/MegaRAID/MegaCli/MegaCli64 -LDGetProp -Cache -L1 -a0

  25. or

  26. #/opt/MegaRAID/MegaCli/MegaCli64 -LDGetProp -Cache -LALL -a0

  27. ro

  28. #/opt/MegaRAID/MegaCli/MegaCli64 -LDGetProp -Cache -LALL -aALL

  29. ro

  30. #/opt/MegaRAID/MegaCli/MegaCli64 -LDGetProp -DskCache -LALL -aALL

  31. 5.設置磁盤緩存策略

  32. 緩存策略解釋:


  33. WT (Write through

  34. WB (Write back)

  35. NORA (No read ahead)

  36. RA (Read ahead)

  37. ADRA (Adaptive read ahead)

  38. Cached

  39. Direct

  40. 例子:

  41. #/opt/MegaRAID/MegaCli/MegaCli64 -LDSetProp WT|WB|NORA|RA|ADRA -L0 -a0

  42. or

  43. #/opt/MegaRAID/MegaCli/MegaCli64 -LDSetProp -Cached|-Direct -L0 -a0

  44. or

  45. enable / disable disk cache

  46. #/opt/MegaRAID/MegaCli/MegaCli64 -LDSetProp -EnDskCache|-DisDskCache -L0 -a0

  47. 6.創建一個 raid5 陣列,由物理盤 2,3,4 構成,該陣列的熱備盤是物理盤 5

  48. #/opt/MegaRAID/MegaCli/MegaCli64 -CfgLdAdd -r5 [1:2,1:3,1:4] WB Direct -Hsp[1:5] -a0

  49. 7.創建陣列,不指定熱備

  50. #/opt/MegaRAID/MegaCli/MegaCli64 -CfgLdAdd -r5 [1:2,1:3,1:4] WB Direct -a0

  51. 8.***陣列

  52. #/opt/MegaRAID/MegaCli/MegaCli64 -CfgLdDel -L1 -a0

  53. 9.在線添加磁盤

  54. #/opt/MegaRAID/MegaCli/MegaCli64 -LDRecon -Start -r5 -Add -PhysDrv[1:4] -L1 -a0

  55. 10.陣列創建完後,會有一個初始化同步塊的過程,可以看看其進度。

  56. #/opt/MegaRAID/MegaCli/MegaCli64 -LDInit -ShowProg -LALL -aALL

  57. 或者以動態可視化文字界面顯示

  58. #/opt/MegaRAID/MegaCli/MegaCli64 -LDInit -ProgDsply -LALL -aALL

  59. 11.查看陣列後臺初始化進度

  60. #/opt/MegaRAID/MegaCli/MegaCli64 -LDBI -ShowProg -LALL -aALL

  61. 或者以動態可視化文字界面顯示

  62. #/opt/MegaRAID/MegaCli/MegaCli64 -LDBI -ProgDsply -LALL -aALL

  63. 12.指定第 5 塊盤作爲全局熱備

  64. #/opt/MegaRAID/MegaCli/MegaCli64 -PDHSP -Set [-EnclAffinity] [-nonRevertible] -PhysDrv[1:5] -a0

  65. 13.指定爲某個陣列的專用熱備

  66. #/opt/MegaRAID/MegaCli/MegaCli64 -PDHSP -Set [-Dedicated [-Array1]] [-EnclAffinity] [-nonRevertible] -PhysDrv[1:5] -a0

  67. 14.***全局熱備

  68. #/opt/MegaRAID/MegaCli/MegaCli64 -PDHSP -Rmv -PhysDrv[1:5] -a0

  69. 15.將某塊物理盤下線/上線

  70. #/opt/MegaRAID/MegaCli/MegaCli64 -PDOffline -PhysDrv [1:4] -a0

  71. #/opt/MegaRAID/MegaCli/MegaCli64 -PDOnline -PhysDrv [1:4] -a0

  72. 16.查看物理磁盤重建進度

  73. #/opt/MegaRAID/MegaCli/MegaCli64 -PDRbld -ShowProg -PhysDrv [1:5] -a0

  74. 或者以動態可視化文字界面顯示

  75. #/opt/MegaRAID/MegaCli/MegaCli64 -PDRbld -ProgDsply -PhysDrv [1:5] -a0


  76. 磁帶狀態的變化,從拔盤,到插盤的過程中:

  77. Device |Normal|Damage|Rebuild|Normal

  78. Virtual Drive |Optimal|Degraded|Degraded|Optimal

  79. Physical Drive |Online|Failed –> Unconfigured|Rebuild|Online


1、 查看RAID級別

25135004_13321356183guB.png

2、 查看RAID卡信息,主要輸出RAID卡的一些配置信息

25135004_13321356590gKA.png


RAID Level : Primary-1, Secondary-0, RAID Level Qualifier-0
Size : 1.086 TB
State : Optimal
Strip Size : 128 KB
Number Of Drives per span:4 //表示每4個物理盤做成一個RAID1盤組
Span Depth : 2 //表示共2個RAID1盤組做成了RAID10


3、 查看所有硬盤的信息

/opt/MegaCli64  -pdlist –aALL

25135004_133213567384A8.png

4、 查看當前raid緩存狀態,raid緩存狀態設置爲wb的話要注意電池放電事宜,設置電池放電模式爲自動學習模式

/opt/MegaRAID/MegaCli/MegaCli64   -ldgetprop  -dskcache -lall  -aall

25135004_13321356868AM6.png

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




發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章