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

前言

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

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

更新历史

2019年07月21日 - 初稿

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

扩展阅读

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/doc...

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查看硬盘信息

[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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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
# 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

---
- 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检查故障硬盘

---
- 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
# check log
cat ansible.log
[Ansiable Tasks: Disk Failure info] host=10.71.12.89

你可能感兴趣的:(raid)