MegaCli 是一款管理维护硬件 RAID 软件,可以通过它来了解当前 raid 卡的所有信息,包括 raid



卡的型号,raid 的阵列类型,raid 上各磁盘状态,等 。通常,我们对硬盘当前的状态不太



好确定,一般通过机房人员巡检来完成,有没有通过软件的方式来检查确定这个问题呢。



MegaCli 就可以做到,一般通过 MegaCli 的 Media Er o Count: 0 Other E ro Count: 0 这两个数



值来确定阵列中磁盘是否有问题;Medai Er o Count 表示磁盘可能错误,可能是磁盘有坏道,



这个值不为 0 值得注意,数值越大,危险系数越高,Other E ro Count 表示磁盘可能存在松



动,可能需要重新再插入。MegaCli 可以对阵列中所有的磁盘进行检测,我们可以通过脚本


的方式来检测相关参数,从而通知管理人员。



1.显示 Rebuid 进度

/opt/MegaRAID/MegaCli/MegaCli64 -PDRbld -ShowProg -physdrv[20: ] -aAL

2.查看 E S


/opt/MegaRAID/MegaCli/MegaCli64 -PDList -aAl -NoL g | rep -Ei "(enclosure|slot)"

 3.查看所有硬盘的状态


/opt/MegaRAID/MegaCli/MegaCli64 -PDList -aAl -NoL g

4.查看所有 Virtual Disk 的状态

/opt/MegaRAID/MegaCli/MegaCli64 -LdP Info -aAl –NoL g

RAID Lev l 对应关系:

RAID Lev l : Primary-1, Secondary-0, RAID Lev l Qualif er-0 RAID 1

RAID Lev l : Primary-0, Secondary-0, RAID Lev l Qualif er-0 RAID 0

RAID Lev l : Primary-5, Secondary-0, RAID Lev l Qualif er-3 RAID 5

RAID Lev l : Primary-1, Secondary-3, RAID Lev l Qualif er-0 RAID 10

5.在线做 Raid

/opt/MegaRAID/MegaCli/MegaCli64 -CfgLdA d -r0[ :1 ] WB NORA Direct CachedBadB U

-strpsz64 -a0 -NoL g

/opt/MegaRAID/MegaCli/MegaCli64 -CfgLdA d -r5 [12: ,12:3,12:4,12:5,12:6,12:7] WB Direct -a0

6.点亮指定硬盘(定位)

/opt/MegaRAID/MegaCli/MegaCli64 -PdLocate -star -physdrv[25 :2] -a0

7.清除 Foreign 状态

/opt/MegaRAID/MegaCli/MegaCli64 -CfgForeign -Clear - 0

8.查看 RAID 阵列中掉线的盘

/opt/MegaRAID/MegaCli/MegaCli64 -pdgetmis ng -a0 # # #

9.替换坏掉的模块

/opt/MegaRAID/MegaCli/MegaCli64 -pdreplacemis ng -physdrv[12: 0] -Ar ay5 -row0 -a0

10.手动开启 rebuid


/opt/MegaRAID/MegaCli/MegaCli64 -pdrbld -star -physdrv[12: 0] -a0



11 .查看 Megacli 的 log


/opt/MegaRAID/MegaCli/MegaCli64 -FwTermLog dsply -a0 > adp2.log

12.设置 HotSpare


/opt/MegaRAID/MegaCli/MegaCli64 -pdhsp -set [-Dedicated [-Ar ay2] [-EnclAf in ty]

[-no Rev rtible] -PhysDrv[4:1 ] -a0

/opt/MegaRAID/MegaCli/MegaCli64 -pdhsp -set [-EnclAf in ty] [-no Rev rtible] -PhysDrv[32:1}]

-a0

13.关闭 Rebuild

/opt/MegaRAID/MegaCli/MegaCli64 -AdpAutoRbld -Dsbl -a0

14.设置 rebuild 的速率


/opt/MegaRAID/MegaCli/MegaCli64 -AdpSetProp RebuildRate -30 -a0



= = = = = = = = = = = = = = = = = = = = = = = = = 1. 首先介绍下 Linux 系统本身查看

软件 raid:查看 raid 级别,状态等信息

#cat /proc/mdsta

硬件 raid:查看 raid 的厂商,型号,级别

#dmesg | rep -i ra d

#cat /proc/s i/sc i

2.硬件 raid 最佳的办法是通过已安装的 raid 厂商的管理工具来查看,下面安装 MegaCLI 工具

查看

首先下载 MegaCli,解压缩。#rpm -ivh MegaCli-1.0 24-0.i386.rpm 安装在/opt 下,所以执行

命令都是/opt/MegaRAID/MegaCli/MegaCli64 哦。

命令使用:

#/opt/MegaRAID/MegaCli/MegaCli64 -LDInfo -Lal -aAL 查 raid 级别

#/opt/MegaRAID/MegaCli/MegaCli64-AdpAl Info -aAL 查 raid 卡信息

#/opt/MegaRAID/MegaCli/MegaCli64-PDList -aAL 查看硬盘信息

#/opt/MegaRAID/MegaCli/MegaCli64-AdpBbuCmd -aAl 查看电池信息

#/opt/MegaRAID/MegaCli/MegaCli64-FwTermLog -Dsply -aAL 查看 raid 卡日志

#/opt/MegaRAID/MegaCli/MegaCli64-adpCount 【显示适配器个数】

#/opt/MegaRAID/MegaCli/MegaCli64-AdpGetTime –aAL 【显示适配器时间】

#/opt/MegaRAID/MegaCli/MegaCli64-AdpAl Info -aAl 【显示所有适配器信息】

#/opt/MegaRAID/MegaCli/MegaCli64-LDInfo -LA L -aAl 【显示所有逻辑磁盘组信息】

#/opt/MegaRAID/MegaCli/MegaCli64-PDList -aAl 【显示所有的物理信息】

#/opt/MegaRAID/MegaCli/MegaCli64-AdpBbuCmd -GetBbuSta us -aAL |grep ‘Charge Sta us’

【查看充电状态】

#/opt/MegaRAID/MegaCli/MegaCli64-AdpBbuCmd -GetBbuSta us -aAL 【显示 B U 状态信息】

#/opt/MegaRAID/MegaCli/MegaCli64-AdpBbuCmd -GetBbuCap cityInfo -aAL【显示 B U 容量信

息】

#/opt/MegaRAID/MegaCli/MegaCli64-AdpBbuCmd -GetBbuDesignI fo -aAL 【显示 B U 设计

参数】

#/opt/MegaRAID/MegaCli/MegaCli64-AdpBbuCmd -GetBbuProperties -aAL 【显示当前 B U

属性】

#/opt/MegaRAID/MegaCli/MegaCli64-cfgdsply -aAL 【显示 Raid 卡型号,Raid 设置,Disk 相关信息】

3.磁带状态的变化,从拔盘,到插盘的过程中。

Device |Normal|Dam ge|Rebuild|Normal

Virtual Drive |Optimal|Degrade |Degrade |Optimal

Physical Drive |Onli e|Failed –> Unconfigured|Rebuild|Onli e

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 -LA L -a0

ro

#/opt/MegaRAID/MegaCli/MegaCli64-LDGetProp -Cache -LA L -aAL

ro

#/opt/MegaRAID/MegaCli/MegaCli64-LDGetProp -DskCache -LA L -aAL

5.设置磁盘缓存策略

缓存策略解释:

WT (Write hrough

WB (Write back)

NORA (No read head)

RA (Read head)

ADRA (Adaptive r ad head)

Cached

Direct

例子:

#/opt/MegaRAID/MegaCli/MegaCli64-LDSetProp WT|WB|NORA|RA| DRA -L0 -a0

or

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

or

enable / disable disk ca he

#/opt/MegaRAID/MegaCli/MegaCli64-LDSetProp -EnDskCache|-Dis kCache -L0 -a0

6.创建一个 raid5 阵列,由物理盘 2,3 4 构成,该阵列的热备盘是物理盘 5

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

7.创建阵列,不指定热备

#/opt/MegaRAID/MegaCli/MegaCli64-CfgLdA d -r5 [1:2,1:3,1:4] WB Direct -a0

8.删除阵列

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

9.在线添加磁盘

#/opt/MegaRAID/MegaCli/MegaCli64-LDRecon -Star - 5 Ad -PhysDrv[1:4] -L1 -a0

10.阵列创建完后,会有一个初始化同步块的过程,可以看 其进度。

#/opt/MegaRAID/MegaCli/MegaCli64-LDInit -ShowProg -LA L -aAL或者以动态可视化文字界面显示

#/opt/MegaRAID/MegaCli/MegaCli64-LDInit -ProgDsply -LA L -aAL

1 .查看阵列后台初始化进度

#/opt/MegaRAID/MegaCli/MegaCli64-LDBI -ShowProg -LA L -aAL

或者以动态可视化文字界面显示

#/opt/MegaRAID/MegaCli/MegaCli64-LDBI -ProgDsply -LA L -aAL

12.指定第 5 块盘作为全局热备

#/opt/MegaRAID/MegaCli/MegaCli64-PDHSP -Set [-EnclAf in ty] [-no Rev rtible] -PhysDrv[1:5]

-a0

13.指定为某个阵列的专用热备

#/opt/MegaRAID/MegaCli/MegaCli64-PDHSP -Set [-Dedicated [-Ar ay1] [-EnclAf in ty]

[-no Rev rtible] -PhysDrv[1:5] -a0

14.删除全局热备

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

15.将某块物理盘下线/上线

#/opt/MegaRAID/MegaCli/MegaCli64-PDOf line -PhysDrv [1:4] -a0

#/opt/MegaRAID/MegaCli/MegaCli64-PDOnli e -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


= = = = = = = = = = = = = = = = = = = = = =


/opt/MegaRAID/MegaCli/MegaCli64 -LDInfo -Lal -aAL | grep -E "RAID Lev l|Strip Size|Number

Of Drives|Span Depth|^Size" 查看做 raid 的情况

/opt/MegaRAID/MegaCli/MegaCli64 -CfgLdDel -L1 -a0 # # 删

/opt/MegaRAID/MegaCli/MegaCli64-CfgLdA d -r5

[9:4,9:5,9:6,9:7,9:8,9: ,9:10,9:1 ,9:12,9:13,9:14] WB Cached CachedBadB U -strpsz1024 -a0

/opt/MegaRAID/MegaCli/MegaCli64 -PDHSP -Set [-EnclAf in ty] [-no Rev rtible] -PhysDrv[9:15]

-a0

/opt/MegaRAID/MegaCli/MegaCli64 -LDSetProp -EnDskCache -L1 -a0

# 做 raid5

/opt/MegaRAID/MegaCli/MegaCli64 -PDList -aAl | grep -E "Enclosure Device ID|Slot

Number|Raw Size|Firmware sta e" # 查看盘的数量

uiqnum=` /opt/MegaRAID/MegaCli/MegaCli64 -PDlist -aAL | grep "ID" | uniq |

awk -F: '{print $2}' | awk '{print $1}'` # # 取 Enclosure Device ID

disknum=`/opt/MegaRAID/MegaCli/MegaCli64 -PDList -aAL | grep -E "DISK\ GRO

UP|Slot\ Number|postion:|Firmware\ sta e:" | grep Slot | awk -F[:\ ] '{prin

t $NF}'` # # 取 Slot Number

diskto al=`/opt/MegaRAID/MegaCli/MegaCli64 -PDList -aAL | grep -E "DISK\ G

ROUP|Slot\ Number|postion:|Firmware\ sta e:" | grep Slot | awk -F[:\ ] '{pr

int $NF}' | wc -l` # #算出总数

ar ay=($disknum)