Skip to main content

Sử dụng MegaCLI để quản lý LSI RAID

Megacli cho phép quản lý RAID controller theo chuẩn LSI. Hỗ trợ sử dụng quản trị trên Linux Server, ngoài cách quản trị này, chúng ta có thể sử dụng các lựa chọn thay thế khác như :

  • Dell OpenManage Administrator
  • Dell iDRAC (R620 trở về trước chỉ có tùy chọn thêm Schedule Jobs để tạo RAID trong quá trình reboot)

Tính tương thích:

  • MegaCLI cho phép quản lý các card RAID theo chuẩn của LSI, vậy nên ngoài Dell thì một vài máy hỗ trợ RAID khác như Intel Embedded Server RAID, HP, IBM…

I. Cài đặt

Tùy vào bản phân phối với các bước cài đặt sau:

  • Centos:
    • wget http://software.vietnix.vn/datastore/sources/MegaCli-8.07.14-1.noarch.rpm
    • rpm -ivh MegaCli-8.07.14-1.noarch.rpm
  • Ubuntu/Debian:
    • wget http://software.vietnix.vn/datastore/sources/megacli_8.07.14-2_all.deb
    • dpkg -i megacli_8.07.14-2_all.deb

Sau khi cài đặt, megacli nằm tại đường dẫn: /opt/MegaRAID/MegaCli/MegaCli64 Có thể sử dụng alias:

  • alias megacli='/opt/MegaRAID/MegaCli/MegaCli64' Hoặc thêm vào bash.rc:
  • echo "alias megacli='/opt/MegaRAID/MegaCli/MegaCli64'" >> /root/.bashrc && source /root/.bashrc

Script bổ trợ:

  • Giúp quản lý VirtualDisk/Disk được thuận tiện hơn.
  • Yêu cầu: Python2, MegaCLI

II. Quản trị

1. Lấy thông tin

Tổng quan: megacli -ShowSummary -aALL

root@server:~# megacli -ShowSummary -aALL
System  
       Operating System:  Linux version 5.4.0-89-generic    
       Driver Version: 07.713.01.00-rc1  
       CLI Version: 8.07.14  
  
Hardware  
       Controller  
                ProductName       : PERC H730 Mini(Bus 0, Dev 0)  
                SAS Address       : 5d09466057224300  
                FW Package Version: 25.5.6.0009  
                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          : ATA        
               Product Id         : SAMSUNG MZ7WD480  
               State              : Online  
               Disk Type          : SATA,Solid State Device  
               Capacity           : 446.625 GB  
               Power State        : Active  
  
               Connector          : 00<Internal><Encl Pos 1 >: Slot 1    
               Vendor Id          : ATA        
               Product Id         : SAMSUNG MZ7WD480  
               State              : Online  
               Disk Type          : SATA,Solid State Device  
               Capacity           : 446.625 GB  
               Power State        : Active  
  
Storage  
  
      Virtual Drives  
               Virtual drive      : Target Id 0 ,VD name OS  
               Size               : 446.625 GB  
               State              : Optimal  
               RAID Level         : 1    
  
  
Exit Code: 0x00

Các thông tin có quan trọng mà lệnh trên cung cấp:

  • Tên Controller
  • BBU Status (Pin card RAID)
  • Physic Drive
    • DiskID = Connector > Slot
  • Virtual Drive:
    • RAID Level
    • VirtualDisk_ID (Target Id)
    • Name

Có thể sử dụng script python bổ trợ trong việc thao tác (khuyên dùng)

a. RAID Adapter (Controller):

Cú pháp: megacli -AdpGetPciInfo -aAll

Lệnh trên sẽ hiển thị với thông tin như sau

PCI information for Controller 0
--------------------------------
Bus Number      : 2
Device Number   : 0
Function Number : 0
Exit Code: 0x00

Trường hợp trên server có sử dụng 1 adapter Device Number : 0, tương đương là -a0

b. Enclosure

Enclosure/Backplane là thành phần trung gian giữa Ổ cứng và Raid Controlller (Adapter)

Cú pháp: megacli -EncInfo -aAdapterID VD: lấy thông tin Enclosure của Adapter: 0

root@server:~# megacli -EncInfo -a0
    Number of enclosures on adapter 0 -- 1
    Enclosure 0:
    Device ID                     : 32
    Number of Slots               : 26
    Number of Power Supplies      : 0
    Number of Fans                : 0
    Number of Temperature Sensors : 0
    Number of Alarms              : 0
    Number of SIM Modules         : 0
    Number of Physical Drives     : 25
    Status                        : Normal
    Position                      : 1
    Connector Name                : Unavailable
    Enclosure type                : SES
    FRU Part Number               : N/A
    Enclosure Serial Number       : N/A 
    ESM Serial Number             : N/A 
    Enclosure Zoning Mode         : N/A 
    Partner Device Id             : 65535

    Inquiry data                  :
        Vendor Identification     : DP      
        Product Identification    : BP12G+EXP       
        Product Revision Level    : 1.07
        Vendor Specific           :                     
    Exit Code: 0x00

Bạn nên chú ý thông số Device ID, chỉ ra Enclosure ID là 32 Device ID : 32

c. Physical Disk

Ổ cứng vật lý

  • Cú pháp: megacli -PDList -aN
  • Có thể kết hợp với grep để lọc các tham số
megacli -pdlist -a0 | grep "Inquiry Data:\|Slot\|Linkspeed\|S.M.A.R.T alert\|Firmware state"

d. Virtual Drives

RAID group.

  • Kiểm tra thông tin của Virtual Drive: megacli -LDInfo -Lall -a0

    • Có thể thay -Lall sang -L<Target_ID> VD: -L0, để hiển thị thông tin của virtual disk 0
    • Các thông tin trả về đáng lưu ý như:
      • Cache Policy: WriteThought/WriteBack, ReadAhead/NoRA
      • State: Optimal/Degrade
  • Liệt kê các ổ cứng có trong VirtualDisk: megacli -LdPdInfo -a0

  • Kiểm tra RAID Level của VirtualDisk: megacli -LDInfo -L2 -a0 | grep -i raid

    • Thông tin có thể như sau:
root@server:~# megacli -LDInfo -LAll -a0 | grep -i raid  
RAID Level          : Primary-1, Secondary-0, RAID Level Qualifier-0

Chú thích:

  • Primary-0, Secondary-0, RAID Level Qualifier-0 = RAID-0
  • Primary-1, Secondary-0, RAID Level Qualifier-0 = RAID-1
  • Primary-5, Secondary-0, RAID Level Qualifier-3 = RAID-5
  • Primary-6, Secondary-0, RAID Level Qualifier-3 = RAID-6
  • Primary-1, Secondary-3, RAID Level Qualifier-0 = RAID-10

2. Thao tác Nâng cao

a. Thêm Virtual Drive

Lưu ý:

  • Để tránh trường hợp mất dữ liệu, kiểm tra kĩ PhysicDisk ID được thêm vào
  • Physical Drive - Firmware State phải ở trạng thái Ready ( coi thêm megacli -PDList -aN)

a.1. RAID 0,1,5,6

Cú Pháp:

megacli -CfgLdAdd -rX[enclosure_id:DiskID,enclosure_id:DiskID,...] -aN

Chú thích:

  • X: Raid level - 0,1,5,6
  • enclosure_id: ID của Encosure trên một Adapter, trong thường hợp này là 32
  • DiskID: ID của một ổ cứng.
  • N: ID của Adapter
  • Cập nhật đúng số lượng yêu cầu của từng loại RAID: RAID 5 (Tối thiểu 3 ổ cứng), RAID 6 (Tối thiểu 4 ổ cứng)

VD:

  • Tạo RAID 0 với 2 ổ trên Adapter 0, Enclosure 32, với 2 ổ ở có diskID 3,4: megacli -CfgLdAdd -r0[32:3,32:4] -a0
  • RAID0 trên 1 ổ: megacli -CfgLdAdd -r0[32:3] -a0
  • Raid 5 với 3 ổ: megacli -CfgLdAdd -r5[32:3,32:5,32:6] -a0

a.2. RAID 10, 50, 60:

Raid 10: Cú Pháp: megacli -CfgSpanAdd -r10 -Array0[enclosure_id:DiskID,enclosure_id:DiskID] -Array1[enclosure_id:DiskID,enclosure_id:DiskID] -a0

  • VD: RAID 10 trên 4 ổ và 2 spans, (2 disks/span), có PhysicDrive ID: 0-3, Enclosure ID: 32
    • megacli -CfgSpanAdd -r10 -Array0[32:0,32:1] -Array0[32:3,32:4] -a0

Raid 50: megacli -CfgSpanAdd -r50 -Array0[E0:S0,E1:S1,E2:S2,...] -Array1[E0:S0,E1:S1,E2:S2,...] -ArrayN[E0:S0,E1:S1,E2:S2,...] -a0

RAID 60: megacli -CfgSpanAdd -r60 -Array0[E0:S0,E1:S1,E2:S2,E3,S3...] -Array1[E0:S0,E1:S1,E2:S2,E3,S3...] ArrayN[E0:S0,E1:S1,E2:S2,E3,S3...] -a0

b. Tùy chọn cache

b.1 Write-Back

Ghi dữ liệu xuống RAID mem-cache, sau đó ghi xuống ổ cứng. Dùng cho tác vụ yêu cầu ghi lại thường xuyên.

Yêu cầu: RAID có Pin (dùng trong trường hợp lưu trữ dữ liệu còn lưu trữ trên RAID mem-cache và chưa được ghi xuống PhysicDrive trong trường hợp mất điện) Cú pháp: megacli -LDSetProp WT -L<VirtualDisk_ID> -a0

b.2 Write-Through

Ghi trực tiếp dữ liệu xuống ổ cứng.

Cú pháp: megacli -LDSetProp WT -L<VirtualDisk_ID> -a0

b.3 No cache:

Cú pháp: megacli -LDSetProp -Direct -L<VirtualDisk_ID> -a0

b.4 Read Ahead:

Lưu trữ dữ liệu thường truy cập trên RAID mem-cache. Trường hợp sử dụng thực tế, ít có thay đổi rõ rệt.

Cú pháp: megacli -LDSetProp RA -L<VirtualDisk_ID> -a0

b.5 Tắt Read Ahead:

Cú pháp: megacli -LDSetProp NORA -L<VirtualDisk_ID> -a0

c. Thêm JBOD Volume

Lưu ý: Một vài dòng RAID controller không hỗ trợ JBOD. Just a Bunch Of Disk, hay Non-RAID Cú pháp: megacli -PDMakeJBOD -PhysDrv[Enclosure_ID:Disk_ID] -aAll

d. Xóa Foreign Profile

Trường hợp gắn ổ cứng cũ đã từng cấu hình sử dụng RAID, nếu không muốn sử dụng lại các Profile này, cần phải xóa các profile Foreign trước khi có thể thêm/cập nhật Virtual Disk.

Cú pháp:

  • Liệt kê các Foreign profile mà adapter đã đọc: megacli -CfgForeign -Scan -a0
  • Xóa các Foreign profiles : megacli -CfgForeign -Clear -a0

Trường hợp Physic Disk có state là: Bad, có thể force chỉnh lại sang Good megacli -PDMakeGood  -PhysDrv[EnclosureID:DiskID] -Force -aAll

VD: Enclosure ID 32 và Disk ID: 18 megacli -PDMakeGood -PhysDrv[32:18] -Force -aAll

e. Xóa RAID profile

Cú pháp: megacli -CfgLdDel -L<VirtualDisk_ID> -a0

Lưu ý: Kiểm tra thật kỹ thông tin VirtualDisk_ID trước khi xóa.

f. Format toàn bộ dữ liệu

Cú pháp: MegaCli -LDInit {-Start [-full]}|-Abort|-ShowProg|-ProgDsply -Lx|-L0,1,2|-LALL -aN|-a0,1,2|-aALL

  • VD: megacli -LDInit -Start -L<VirtualDisk_ID> -a0

Mặc định tùy chọn -Start sẽ là Fast Init, nếu muốn xóa hoàn toàn dữ liệu còn lưu trên ổ cứng , bạn có thể thêm tùy chọn -Start -full

Lưu ý: Kiểm tra kĩ VirtualDisk_ID trước khi thực hiện xóa.

3. Bảo trì

a. Xác định vị trí ổ cứng

Trong việc bảo trì, thay thế. Trường hợp cần tìm vị trí chính xác của ổ cứng được gắn trên node, megacli có hỗ trợ cách thức với việc nháy sáng đèn trạng thái của ổ cứng.

Cú pháp: megacli -PdLocate -start|-stop -physdrv[enclosure_ID:DiskID] -aAdapterID

VD: xác định vị trí của ổ cứng ở Enclosure ID: 32 và Disk ID là 2

root@server:~# megacli -PdLocate -start -physdrv[32:2] -a0
 Adapter: 0: Device at EnclId-32 SlotId-2 — PD Locate Start Command was successfully sent to Firmware
 Exit Code: 0x00

b. Export/Import RAID profile

Import RAID profile từ Foreign:

megacli -CfgForeign -Import -a0

Sao Lưu cấu hình RAID trên controller:

megacli -CfgSave -f raidcfg.txt -a0

Khôi phục lại cấu hình từ file đã backup:

megacli -CfgRestore -f raidcfg.txt -a0


References

https://globalroot.wordpress.com/2013/06/18/megacli-raid-levels/ https://blog.frehi.be/2011/09/12/megacli-useful-commands/