前言

MegaCli 是 LSI 公司官方提供的 SCSI 卡管理工具,由于 LSI 被收购变成了现在的 Broadcom,所以想下载 MegaCli,需要去 Broadcom 官网查找。现在官方有 Storcli,整合了 LSI 和 3ware 所有产品,本文主要以 MegaCli64 为例,无论选择 MegaCli 还是 Storcli 只要在线上环境运行稳定可以获取正确数据就都是合适的方法。

使用MegaCli64快速查看RAID和定位故障硬盘实践

更新历史

2019年07月21日 - 初稿

阅读原文 - https://wsgzao.github.io/post/megacli64/

扩展阅读

MegaCLI vs tw_cli vs Storcli
Extracting the RAID-Controller Logs via MegaCLI


MegaCli简介

MegaRaid 阵列卡管理工具。他可以查看当前 RAID 卡的所有信息,包括 RAID 卡型号、类型、磁盘状态、电池状态等等。学会了如何使用 MegaCli,我们可以在硬盘没有彻底嗝屁(Failed)之前,监测到是否已经出现预告警报错,不需要现场逐台巡检磁盘状态灯。

  1. 使用Zabbix监控硬盘或者使用IPMI接入OOB(Out-of-Band)监控硬件状态
  2. 使用更加成熟的商业化工具管理如云霁科技CloudBoot,拒绝被单一厂商绑架

MegaCli64官网地址: http://docs.avagotech.com/docs/12351587

Linux下默认路径: /opt/MegaRAID/MegaCli/MegaCli64

MegaCli安装

  1. Download the MegaCli utility from the Broadcom support site

  2. Unzip the downloaded files and install them to any directory of your installed operating system (e.g.: Linux – /tmp/megacli)

  3. From a terminal window in Linux, install the using the the following command:

    Note: root priviledges required to install MegaCLI:

    rpm -i MegaCli-8.07.14-1.noarch.rpm

  4. Then change directory into /opt/MegaRAID/MegaCLI/ and run any of the commands from the table below:

Command Action
./MegaCli64 -FwTermLog -Dsply -aALL > /tmp/ttylog.txt Creates the RAID controller log (ttylog)
./MegaCli64 -PDList -aALL > /tmp/disks.txt Creates a list with information about the RAID controllers, virtual disks and hard disks installed
./MegaCli64 -LDInfo -LALL -aALL > /tmp/LDinfo.txt Creates a list with information about existing RAID volumes and configurations
./MegaCli64 -AdpAllInfo -aALL > /tmp/Adapterinfo.txt Creates a list with information about RAID controller settings
./MegaCli64 -AdpBbuCmd -aALL > /tmp/Battery.txt Creates a detailed list of the battery status of the RAID controller (state of charge, learning cycle, etc.)
./MegaCli64 -AdpEventLog -IncludeDeleted -f deleted.txt -aALL Creates the RAID controller log (ttylog) with all information since very first controller initialization( Note: This file will always be saved in the MegaCLI root folder)

使用MegaCli64查看硬盘信息

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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
[root@localhost wangao]# MegaCli -ShowSummary -aALL

System
Operating System: Linux version 3.10.0-957.21.3.el7.x86_64
Driver Version: 07.705.02.00-rh1
CLI Version: 8.07.06

Hardware
Controller
ProductName : PERC H730P Mini(Bus 0, Dev 0)
SAS Address : 51866da0a1306300
FW Package Version: 25.5.0.0018
Status : Optimal
BBU
BBU Type : BBU
Status : Healthy
Enclosure
Product Id : BP13G+EXP
Type : SES
Status : OK

PD
Connector : 00<Internal><Encl Pos 1 >: Slot 0
Vendor Id : HGST
Product Id : HUS726060AL5214
State : Online
Disk Type : SAS,Hard Disk Device
Capacity : 5.457 TB
Power State : Active

Connector : 00<Internal><Encl Pos 1 >: Slot 1
Vendor Id : HGST
Product Id : HUS726060AL5214
State : Online
Disk Type : SAS,Hard Disk Device
Capacity : 5.457 TB
Power State : Active

Connector : 00<Internal><Encl Pos 1 >: Slot 2
Vendor Id : HGST
Product Id : HUS726060AL5214
State : Online
Disk Type : SAS,Hard Disk Device
Capacity : 5.457 TB
Power State : Active

Connector : 00<Internal><Encl Pos 1 >: Slot 3
Vendor Id : HGST
Product Id : HUS726060AL5214
State : Online
Disk Type : SAS,Hard Disk Device
Capacity : 5.457 TB
Power State : Active

Connector : 00<Internal><Encl Pos 1 >: Slot 4
Vendor Id : HGST
Product Id : HUS726060AL5214
State : Online
Disk Type : SAS,Hard Disk Device
Capacity : 5.457 TB
Power State : Active

Connector : 00<Internal><Encl Pos 1 >: Slot 5
Vendor Id : HGST
Product Id : HUS726060AL5214
State : Online
Disk Type : SAS,Hard Disk Device
Capacity : 5.457 TB
Power State : Active

Connector : 00<Internal><Encl Pos 1 >: Slot 6
Vendor Id : HGST
Product Id : HUS726060AL5214
State : Online
Disk Type : SAS,Hard Disk Device
Capacity : 5.457 TB
Power State : Active

Connector : 00<Internal><Encl Pos 1 >: Slot 7
Vendor Id : HGST
Product Id : HUS726060AL5214
State : Online
Disk Type : SAS,Hard Disk Device
Capacity : 5.457 TB
Power State : Active

Connector : 00<Internal><Encl Pos 1 >: Slot 8
Vendor Id : HGST
Product Id : HUS726060AL5214
State : Online
Disk Type : SAS,Hard Disk Device
Capacity : 5.457 TB
Power State : Active

Connector : 00<Internal><Encl Pos 1 >: Slot 9
Vendor Id : HGST
Product Id : HUS726060AL5214
State : Online
Disk Type : SAS,Hard Disk Device
Capacity : 5.457 TB
Power State : Active

Connector : 00<Internal><Encl Pos 1 >: Slot 10
Vendor Id : HGST
Product Id : HUS726060AL5214
State : Online
Disk Type : SAS,Hard Disk Device
Capacity : 5.457 TB
Power State : Active

Connector : 00<Internal><Encl Pos 1 >: Slot 11
Vendor Id : HGST
Product Id : HUS726060AL5214
State : Online
Disk Type : SAS,Hard Disk Device
Capacity : 5.457 TB
Power State : Active

Connector : 00<Internal><Encl Pos 1 >: Slot 12
Vendor Id : ATA
Product Id : ST9250610NS
State : Online
Disk Type : SATA,Hard Disk Device
Capacity : 232.375 GB
Power State : Active

Connector : 00<Internal><Encl Pos 1 >: Slot 13
Vendor Id : ATA
Product Id : ST9250610NS
State : Online
Disk Type : SATA,Hard Disk Device
Capacity : 232.375 GB
Power State : Active

Connector : 00<Internal><Encl Pos 1 >: Slot 14
Vendor Id : HGST
Product Id : HUS726060AL5214
State : Online
Disk Type : SAS,Hard Disk Device
Capacity : 5.457 TB
Power State : Active

Connector : 00<Internal><Encl Pos 1 >: Slot 15
Vendor Id : HGST
Product Id : HUS726060AL5214
State : Online
Disk Type : SAS,Hard Disk Device
Capacity : 5.457 TB
Power State : Active

Connector : 00<Internal><Encl Pos 1 >: Slot 16
Vendor Id : HGST
Product Id : HUS726060AL5214
State : Online
Disk Type : SAS,Hard Disk Device
Capacity : 5.457 TB
Power State : Active

Connector : 00<Internal><Encl Pos 1 >: Slot 17
Vendor Id : HGST
Product Id : HUS726060AL5214
State : Online
Disk Type : SAS,Hard Disk Device
Capacity : 5.457 TB
Power State : Active

Storage

Virtual Drives
Virtual drive : Target Id 0 ,VD name
Size : 232.375 GB
State : Optimal
RAID Level : 1

Virtual drive : Target Id 1 ,VD name
Size : 81.862 TB
State : Optimal
RAID Level : 5


Exit Code: 0x00
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# check virutal disk / raid info
if [[ -f /opt/MegaRAID/MegaCli/MegaCli64 ]]; then
raidlevel=`sudo /opt/MegaRAID/MegaCli/MegaCli64 -LDInfo -Lall -aALL -NoLog | grep 'RAID Level' | awk -F ":" '{print $2}' | awk -F "," {'print $1}' | awk -F "-" '{print $2}'`
disk_number=`sudo /opt/MegaRAID/MegaCli/MegaCli64 -PDList -aALL -NoLog | egrep 'Device Id' | awk 'BEGIN {RS=""; FS="\n"} {print NF}'`
disk_type=`sudo /opt/MegaRAID/MegaCli/MegaCli64 -PDList -aALL -NoLog | egrep 'Media Type' | head -1 | awk -F ":" '{print $2}'`
else
raidlevel="none"
disk_number="none"
disk_type="none"
fi

# test
[root@localhost wangao]# echo $raidlevel
1 5
[root@localhost wangao]# echo $disk_number
18
[root@localhost wangao]# echo $disk_type
Hard Disk Device

Ansible安装MegaCLi64

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
---
- hosts: all
become: yes
gather_facts: no

tasks:
- name: upload MegaCli64
copy:
src: files/MegaCli-8.07.14-1.noarch.rpm
dest: /tmp/MegaCli-8.07.14-1.noarch.rpm

- name: install MegaCli64 rpm from a local file
yum:
name: /tmp/MegaCli-8.07.14-1.noarch.rpm
state: present

- name: create symlink for MegaCli64
file:
src: /opt/MegaRAID/MegaCli/MegaCli64
dest: /usr/sbin/MegaCli
state: link

Ansible使用MegaCli64检查故障硬盘

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
---
- hosts: all
become: yes
gather_facts: no

tasks:
- name: Check Disk Status
command: ./MegaCli64 -ShowSummary -aALL
args:
chdir: /opt/MegaRAID/MegaCli/
register: result

- name: Log check info
lineinfile:
dest: "{{inventory_dir}}/ansible.log"
line: '[Ansiable Tasks: Disk Failure info] host={{inventory_hostname}}'
insertafter: EOF
create: yes
when: '"Failed" in result.stdout'
delegate_to: localhost
become: no

1
2
3
4
# check log
cat ansible.log
[Ansiable Tasks: Disk Failure info] host=10.71.12.89

文章目录
  1. 1. 前言
  2. 2. 更新历史
  3. 3. MegaCli简介
  4. 4. MegaCli安装
  5. 5. 使用MegaCli64查看硬盘信息
  6. 6. Ansible安装MegaCLi64
  7. 7. Ansible使用MegaCli64检查故障硬盘