1. 程式人生 > >MegaCli 監控raid狀態

MegaCli 監控raid狀態

megacli

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

三 使用命令及參數

命令使用:
#/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

1、 查看RAID級別

技術分享

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

技術分享

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

技術分享

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

/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

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

#!/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

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

#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


MegaCli 監控raid狀態