Linux系统下安装MegaCli64工具查看和管理raid卡

原文链接:http://blog.csdn.net/lufeisan/article/details/53398756

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

说明:安装完毕之后MegaCli64所在路径为/opt/MegaRAID/MegaCli/MegaCli64,在此路径下可以运行MegaCli64工具,切换到其它路径下则不能执行,此时为了使用方便,可以考虑将/opt/MegaRAID/MegaCli/MegaCli64追加到系统PATH变量,或者像下面这样做(建议):
ln -s /opt/MegaRAID/MegaCli/MegaCli64 /bin/MegaCli64
ln -s /opt/MegaRAID/MegaCli/MegaCli64 /sbin/MegaCli64


三 使用命令及参数

[plain] view plain copy
  1. 命令使用:  
  2. #/opt/MegaRAID/MegaCli/MegaCli64 -LDInfo -Lall -aALL 查raid级别  
  3. #/opt/MegaRAID/MegaCli/MegaCli64 -AdpAllInfo -aALL 查raid卡信息  
  4. #/opt/MegaRAID/MegaCli/MegaCli64 -PDList -aALL 查看硬盘信息  
  5. #/opt/MegaRAID/MegaCli/MegaCli64 -AdpBbuCmd -aAll 查看电池信息  
  6. #/opt/MegaRAID/MegaCli/MegaCli64 -FwTermLog -Dsply -aALL 查看raid卡日志  
  7. #/opt/MegaRAID/MegaCli/MegaCli64 -adpCount 【显示适配器个数】  
  8. #/opt/MegaRAID/MegaCli/MegaCli64 -AdpGetTime –aALL 【显示适配器时间】  
  9. #/opt/MegaRAID/MegaCli/MegaCli64 -AdpAllInfo -aAll 【显示所有适配器信息】  
  10. #/opt/MegaRAID/MegaCli/MegaCli64 -LDInfo -LALL -aAll 【显示所有逻辑磁盘组信息】  
  11. #/opt/MegaRAID/MegaCli/MegaCli64 -PDList -aAll 【显示所有的物理信息】  
  12. #/opt/MegaRAID/MegaCli/MegaCli64 -AdpBbuCmd -GetBbuStatus -aALL |grep ‘Charger Status’ 【查看充电状态】  
  13. #/opt/MegaRAID/MegaCli/MegaCli64 -AdpBbuCmd -GetBbuStatus -aALL【显示BBU状态信息】  
  14. #/opt/MegaRAID/MegaCli/MegaCli64 -AdpBbuCmd -GetBbuCapacityInfo -aALL【显示BBU容量信息】  
  15. #/opt/MegaRAID/MegaCli/MegaCli64 -AdpBbuCmd -GetBbuDesignInfo -aALL 【显示BBU设计参数】  
  16. #/opt/MegaRAID/MegaCli/MegaCli64 -AdpBbuCmd -GetBbuProperties -aALL 【显示当前BBU属性】  
  17. #/opt/MegaRAID/MegaCli/MegaCli64 -cfgdsply -aALL 【显示Raid卡型号,Raid设置,Disk相关信息】  
  18. 3.磁带状态的变化,从拔盘,到插盘的过程中。  
  19. Device |Normal|Damage|Rebuild|Normal  
  20. Virtual Drive |Optimal|Degraded|Degraded|Optimal  
  21. Physical Drive |Online|Failed –> Unconfigured|Rebuild|Online  
  22. 4.查看磁盘缓存策略  
  23. #/opt/MegaRAID/MegaCli/MegaCli64 -LDGetProp -Cache -L0 -a0  
  24. or  
  25. #/opt/MegaRAID/MegaCli/MegaCli64 -LDGetProp -Cache -L1 -a0  
  26. or  
  27. #/opt/MegaRAID/MegaCli/MegaCli64 -LDGetProp -Cache -LALL -a0  
  28. ro  
  29. #/opt/MegaRAID/MegaCli/MegaCli64 -LDGetProp -Cache -LALL -aALL  
  30. ro  
  31. #/opt/MegaRAID/MegaCli/MegaCli64 -LDGetProp -DskCache -LALL -aALL  
  32. 5.设置磁盘缓存策略  
  33. 缓存策略解释:  
  34.   
  35. WT (Write through  
  36. WB (Write back)  
  37. NORA (No read ahead)  
  38. RA (Read ahead)  
  39. ADRA (Adaptive read ahead)  
  40. Cached  
  41. Direct  
  42. 例子:  
  43. #/opt/MegaRAID/MegaCli/MegaCli64 -LDSetProp WT|WB|NORA|RA|ADRA -L0 -a0  
  44. or  
  45. #/opt/MegaRAID/MegaCli/MegaCli64 -LDSetProp -Cached|-Direct -L0 -a0  
  46. or  
  47. enable / disable disk cache  
  48. #/opt/MegaRAID/MegaCli/MegaCli64 -LDSetProp -EnDskCache|-DisDskCache -L0 -a0  
  49. 6.创建一个 raid5 阵列,由物理盘 2,3,4 构成,该阵列的热备盘是物理盘 5  
  50. #/opt/MegaRAID/MegaCli/MegaCli64 -CfgLdAdd -r5 [1:2,1:3,1:4] WB Direct -Hsp[1:5] -a0  
  51. 7.创建阵列,不指定热备  
  52. #/opt/MegaRAID/MegaCli/MegaCli64 -CfgLdAdd -r5 [1:2,1:3,1:4] WB Direct -a0  
  53. 8.删除阵列  
  54. #/opt/MegaRAID/MegaCli/MegaCli64 -CfgLdDel -L1 -a0  
  55. 9.在线添加磁盘  
  56. #/opt/MegaRAID/MegaCli/MegaCli64 -LDRecon -Start -r5 -Add -PhysDrv[1:4] -L1 -a0  
  57. 10.阵列创建完后,会有一个初始化同步块的过程,可以看看其进度。  
  58. #/opt/MegaRAID/MegaCli/MegaCli64 -LDInit -ShowProg -LALL -aALL  
  59. 或者以动态可视化文字界面显示  
  60. #/opt/MegaRAID/MegaCli/MegaCli64 -LDInit -ProgDsply -LALL -aALL  
  61. 11.查看阵列后台初始化进度  
  62. #/opt/MegaRAID/MegaCli/MegaCli64 -LDBI -ShowProg -LALL -aALL  
  63. 或者以动态可视化文字界面显示  
  64. #/opt/MegaRAID/MegaCli/MegaCli64 -LDBI -ProgDsply -LALL -aALL  
  65. 12.指定第 5 块盘作为全局热备  
  66. #/opt/MegaRAID/MegaCli/MegaCli64 -PDHSP -Set [-EnclAffinity] [-nonRevertible] -PhysDrv[1:5] -a0  
  67. 13.指定为某个阵列的专用热备  
  68. #/opt/MegaRAID/MegaCli/MegaCli64 -PDHSP -Set [-Dedicated [-Array1]] [-EnclAffinity] [-nonRevertible] -PhysDrv[1:5] -a0  
  69. 14.删除全局热备  
  70. #/opt/MegaRAID/MegaCli/MegaCli64 -PDHSP -Rmv -PhysDrv[1:5] -a0  
  71. 15.将某块物理盘下线/上线  
  72. #/opt/MegaRAID/MegaCli/MegaCli64 -PDOffline -PhysDrv [1:4] -a0  
  73. #/opt/MegaRAID/MegaCli/MegaCli64 -PDOnline -PhysDrv [1:4] -a0  
  74. 16.查看物理磁盘重建进度  
  75. #/opt/MegaRAID/MegaCli/MegaCli64 -PDRbld -ShowProg -PhysDrv [1:5] -a0  
  76. 或者以动态可视化文字界面显示  
  77. #/opt/MegaRAID/MegaCli/MegaCli64 -PDRbld -ProgDsply -PhysDrv [1:5] -a0  
  78.   
  79. 磁带状态的变化,从拔盘,到插盘的过程中:  
  80. Device |Normal|Damage|Rebuild|Normal  
  81. Virtual Drive |Optimal|Degraded|Degraded|Optimal  
  82. Physical Drive |Online|Failed –> Unconfigured|Rebuild|Online  
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


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

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