2023年12月15日发(作者:)

二、 下载、安装 MegCli

下载地址:wget

/2014/12/ibm_utl_sraidmr_megacli-8.00.48_linux_

#unzip ibm_utl_sraidmr_megacli-8.00.48_linux_

#cd linux

#rpm -ivh Lib_

#rpm -ivh

#故障硬盘修复(添加新硬盘或阵列)

#-PDMakeGood是改变状态由Unconfigured bad变成Unconfigured good

#-PhysDrv[252:2] 是硬盘信息[]内第一个数字是Enclosure Device ID,第二个数字是Slot Number

#-a0 是Adapter #0

1./opt/MegaRAID/MegaCli/MegaCli64 -PDMakeGood -PhysDrv[252:2] -a0

#硬盘变为Unconfigured good之后加入阵列

2./opt/MegaRAID/MegaCli/MegaCli64 -LDRecon -Start -r5 -Add

-PhysDrv[252:2] -L0 -a0

3.等待重建,大约需要2小时

Reconstruction : Completed 0%, Taken 1 min.

使用/opt/MegaRAID/MegaCli/MegaCli64命令会在当前目录生成日志文件可以加上 -NoLog参数取消日志

三 使用命令及参数

命令使用:

#/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 磁盘状态

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

$MEGACLI -pdlist -aALL | grep -E "Media Error|Other Error" | awk -F :

'{print $2}' >/tmp/

for i in `cat < /tmp/`;do

if [ $i -ne 0 ];then

curl

"/&state=ALARM&description=raid_disk_error"

fi

done

for i in `cat < /tmp/`;do

if [ $i != Online ];then

curl

"/$state=ALARM&description=raid_disk_offline"

fi

done

7、批处理脚本

Windows下脚本用的工具是gnu for windows平台的一些软件,如 bash grep awk cat 通过bash直接调用脚本

G:raid_checkunixtools> G:

#check raid disk status

MEGACLI="//G/raid_check/"

GREP="//G/raid_check/unixtools/"

AWK="//G/raid_check/unixtools/"

CAT="//G/raid_check/unixtools/"

CURL="//G/raid_check/unixtools/"

$MEGACLI -pdlist -aALL | $GREP "Firmware state" |$AWK -F: '{print $2}'

|$AWK -F , '{print $1}' >//c/

$MEGACLI -pdlist -aALL | $GREP -E "Media Error|Other Error" | $AWK -F :

'{print $2}' > //c/

for i in `cat < /tmp/`;do

if [ $i -ne 0 ];then

curl

"/&state=ALARM&description=raid_disk_error"

fi

done

for i in `cat < /tmp/`;do

if [ $i != Online ];then

curl

"/$state=ALARM&description=raid_disk_offline"

fi

done