Linux下MegaCliRaid管理一、软件包由LSI官网下载Megacli软件包,8.02.16_MegaCLI.zip,解压处MegaCliLin.zip,继续解压出两个Rpm软件包,并拷贝到相应目录下,以/root为例:二、安装软件包在Redhat和CentOS等系统下可以直接执行rpm–ivhxxxx.rpm来安装,但在Debian和Ubuntu下应该执行如下步骤:需要使用如下命令:alien,dpkg,rpm2cpio,cpio;系统中如果没有请使用#sudoapt-getinstallpackagename来安装相应的软件包1)安装库文件:#alienLib_Utils-1.00-09.noarch.rpm#dpkg–ilib-utils_1.00-10_all.deb使用alien命令把Lib_Utils-....noarch.rpm转换为deb包,使用dpkg命令安装。2)解压MegaCLI:#rpm2cpioMegaCli-8.02.16-1.i386.rpm|cpio–idmv安装完成后会出现opt/目录,可以根据不同系统使用如下命令查看配置信息.#./opt/MegaRAID/MegaCli/MegaCli-AdpAllInfo-aALL#./opt/MegaRAID/MegaCli/MegaCli64-AdpAllInfo–aALL以下以64bit系统为例三、MegaCli用法名词解释VirtualDrive(VD):虚拟硬盘,简单说就是RaidVDStateOptimal:Raid目前为正常VDStateDegraded:Raid状态不正常,退化或者降级PhysicalDrive(PD):实体硬盘,实际有的硬盘数量PDStateOnline:硬盘目前的状态为正常PDStateFail、Unconfigured、Rebuld:磁盘状态不正常,掉盘、未配置或正在重建Raid1)查看Raid卡信息#/opt/MegaRAID/MegaCli/MegaCli-AdpAllInfo–a0但这样看到的信息太多太复杂,可以根据如下脚本定义自己关注的信息#!/bin/bash#checkRaidcardvdandpdstateHOSTNAME=`/bin/hostname`CARD=`./MegaCli64-adpallinfo-a0|grepProductName|cut-d':'-f2`VDSTATE1=`./MegaCli64-cfgdsply-aALL|grepState`VDSTATE2=`./MegaCli64-AdpAllInfo-aALL|grepDegraded`VDSTATE3=`./MegaCli64-AdpAllInfo-aALL|grepOffline`PDSTATE1=`./MegaCli64-cfgdsply-aALL|grepOnline|wc-l|sed's///'`PDSTATE2=`./MegaCli64-cfgdsply-aALL|grepRebuild|wc-l|sed's///'`PDSTATE3=`./MegaCli64-AdpAllInfo-aALL|grepCriticalDisks`PDSTATE4=`./MegaCli64-AdpAllInfo-aALL|grepDisks`PDSTATE5=`./MegaCli64-AdpAllInfo-aALL|grepVirtual`echo#############HostInformation##############echoHost:$HOSTNAMEechoRaidCard:$CARDecho''''echo############VirtualDiskState#############echoVDNumber:$PDSTATE5echoVirtualDisk$VDSTATE1echo$VDSTATE2echo$VDSTATE3echoecho############VDDiskState##################echoOnlineDisk:$PDSTATE1echoRebuildDisk:$PDSTATE2echo$PDSTATE3echoecho############PhysicalDisksState#############echo$PDSTATE4本机有8块硬盘4块单盘分别做Raid0执行改脚本可以看到如下信息:root@ubuntu:~/opt/MegaRAID/MegaCli#./info#############HostInformation##############Host:ubuntuRaidCard:MegaRAIDSASMR9240-8i############VirtualDiskState#############VDNumber:VirtualDrives:4VirtualDiskState:OptimalForeignState:NoneState:OptimalForeignState:NoneState:OptimalForeignState:NoneState:OptimalForeignState:NoneDegraded:0Offline:0############VDDiskState##################OnlineDisk:4RebuildDisk:0CriticalDisks:0############PhysicalDisksState#############Disks:8CriticalDisks:0FailedDisks:0四、掉盘处理方法当发生掉盘后,应该更换新的硬盘,更换硬盘后,在SAS卡2008下会默认为JBOD模式(插入后系统会立即识别,此时不要重启机器)或者硬盘本身带有foreign信息,此时应该执行命令把他转换为Unconfiguregood模式并清除foreign信息再做Raid。1)首先查找到该卡子的DivceID,记录#./MegaCli64-PDlist-aALL|grepDivceIDEnclosureDeviceID:64,记录该EnDeviceID,如果由两个卡子可以分别执行参数-a0和-a1来取代-aALL2)查找看有没有foreign信息#./MegaCli64-PDlist-aALL|grepForeignState例如得到如下信息ForeignState:NoneForeignState:ForeignForeignState:NoneForeignState:NoneForeignState:NoneForeignState:NoneForeignState:NoneForeignState:None在执行该命令前应该看下slot号是否按顺序排列#./MegaCli64-PDlist-aALL|grepSlot,如果不按顺序则应找到该硬盘对应的Slot号,经查看如上的信息按0-7顺序排列。该信息显示slot0-7的foreign信息,可以看到slot1的硬盘状态存在foreign。3)修改硬盘状态信息为unconfigruegood把改DivceID64卡子的slot1状态改为unconfigruegood#./MegaCli64-PDMakeGood-PhysDrv[64:1]-force-a0Adapter:0:EnclId-64SlotId-1statechangedtoUnconfigured-Good.ExitCode:0x004)清除foreign信息扫描该卡子上的硬盘看是否存在foreign信息./MegaCli64-CfgForeign-Scan–a0不存在就不用再执行下面的命令了。如果在a0上存在则执行,清除#./MegaCli64-CfgForeign-Clear[a0]Foreignconfiguration0isclearedoncontroller0.ExitCode:0x005)重新做Raid例1、EnDeviceID64的slot1的单盘做Raid0,则#./MegaCli64-CfgLdAdd-r0[64:1]WTDirect-a0Adapter0:CreatedVD1Adapter0:ConfiguredtheAdapter!!ExitCode:0x00例2、在该卡子上slot4和slot5制作Raid1./MegaCli64-CfgLdAdd-r1[64:4,64:5]WTDirect-a0Adapter0:CreatedVD4Adapter0:ConfiguredtheAdapter!!ExitCode:0x00当Raid1掉线后更换新硬盘,使用参数-PDMakeGood-PhysDrv[64:4]把硬盘配置为unconfigruegood后,把出该盘,重新插入,则Raid卡会自动处于Rebuild状态。或者得到掉线的PD信息#./MegaCli64-Pdgetmissing-a0Adapter0-MissingPhysicaldrivesNo.ArrayRowSizeExpected040285568MBExitCode:0x00替代该掉线硬盘#MegaCli64-PdReplaceMissing-physdrv[64:4]–array4,-row0–a0重启后将自动Rebuild五、MegaCli其他常见用法1、查看磁盘缓存策略MegaCli-LDGetProp-Cache-L0-a0Adapter0-VD0:CachePolicy:WriteBack,ReadAheadNone,DirectorMegaCli-LDGetProp-Cache-L1-a0Adapter0-VD1:CachePolicy:WriteBack,ReadAheadNone,DirectorMegaCli-LDGetProp-Cache-LALL-a0Adapter0-VD0:CachePolicy:WriteBack,ReadAheadNone,DirectAdapter0-VD1:CachePolicy:WriteBack,ReadAheadNone,DirectorMegaCli-LDGetProp-Cache-LALL-aALLAdapter0-VD0:CachePolicy:WriteBack,ReadAheadNone,DirectAdapter0-VD1:CachePolicy:WriteBack,ReadAheadNone,DirectorMegaCli-LDGetProp-DskCache-LALL-aALLAdapter0-VD0:DiskWriteCache:Disk’sDefaultAdapter0-VD1:DiskWriteCache:Disk’sDefault2、设置磁盘缓存策略缓存策略解释:WT(WritethroughWB(Writeback)NORA(Noreadahead)RA(Readahead)ADRA(Adaptivereadahead)CachedDirect例子:MegaCli-LDSetPropWT|WB|NORA|RA|ADRA-L0-a0orMegaCli-LDSetProp-Cached|-Direct-L0-a0orenable/disablediskcacheMegaCli-LDSetProp-EnDskCache|-DisDskCache-L0-a0例如:硬盘缓存的打开与关闭#./MegaCli64-LDSetProp-EnDskCache-Lall-aall【打开硬盘缓存】#./MegaCli64-LDSetProp-DisDskCache-Lall-aall【关闭硬盘缓存】3、创建/删除阵列创建一个raid5阵列,由物理盘2,3,4构