Skip to content

Tìm hiểu LVM RAID#

Khái niệm LVM RAID#

LVM RAID là các để tạo các Logical Volumes sử dụng nhiều thiết bị vật lý để có thể cải thiện hiệu năng và tăng tính chịu lỗi. Trong LVM, các thiết bị vật lý là Physical Volume (PV) trong một Volume Group duy nhất (VG).

Dữ liệu của các LV được đặt trên các PV như thế nào được quyết định bởi RAID level. Có nhiều RAID level quy định các cách lưu trữ dữ liệu khác nhau để phục vụ các mục đích khác nhau như: chịu lỗi, tăng hiệu năng đọc ghi.

LVM RAID sử dụng cả Device Mapper (DM) và Multiple Device (MD). DM đươc sử dụng để tạo và quản lý các "visible" LVM device, MD được sử dụng để quản lý việc đặt dữ liệu lên các thiết bị vật lý.

LVM sẽ tạo ra các LV phụ và bị ẩn nằm giữa các LV có thể nhìn thấy và các PV. Trong LVM raid, một cặp LV phụ để lưu trữ dữ liệu và metadata sẽ được tạo cho mỗi một raid image.

Tạo một LVM RAID#

Để tạo một LVM RAID sử dụng lênh lvmcreate và chỉ định loại (type), các loại LVM sẽ tương ứng với các Raid level. Các raid level có thể sử dụng là: raid0, raid1, raid4, raid5, raid6, raid10

 lvcreate --type RaidLevel [OPTIONS] --name Name --size Size VG [PVs]

Để hiện thị loại LV của một LV đang tồn tại:

lvs -o name,segtype LV

Các kiểu raid#

raid0

Giống loại Striping, raid0 chia dữ liệu LV ra nhiều thiết bị theo kích thước của nó. Nó sẽ làm tăng hiệu năng nhưng không có khả năng chịu lỗi, dữ liệu sẽ mất một thiết bị bị lỗi.

lvcreate --type raid0 [--stripes Number --stripesize Size] -n Name --size VG [PVs]

--stripes quy định số lượng PV sẽ được sử dụng để chia dữ liệu cho LV

--stripesize quy định kích thước theo kilobyte của dữ liệu sẽ được ghi lên một PV trước khi ghi đến thiết bị tiếp theo.

PVs là các PV muốn sử dụng cho LV RAID này. Nếu không chỉ định PV thì LVM sẽ tự động chọn

raid1

raid1 cũng được gọi là mirroring, raid1 sử dụng nhiều thiết bị để nhân dữ liệu LV lên tất cả các PV. raid1 có khả năng chịu lỗi cao vì tất cả các PV đều chứa dữ liệu của LV. Số thiết bị tối thiểu yêu cầu cho loại raid này là 2.

lvcreate --type raid1 [--mirrors Number] VG [PVs]

--mirrors chỉ định số lượng bản sao sẽ được tạo cho dữ liệu LV.

Ví dụ: --mirror 2 có nghĩa là nó sẽ sử dụng 3 PV để lưu dữ liệu lên cả 3 PV này.

PVs tùy chọn để chỉ định pv sẽ được sử dụng cho LV này.

raid4

raid4 là một loại striping sử dụng thêm một thiết bị để riêng để lưu trữ toàn bộ dữ liệu. Dữ liệu LV sẽ vẫn còn nếu chỉ một trong các thiết bị bị lỗi. Số thiết bị tối thiểu là 3.

lvcreate --type raid4 [--stripes Number --stripesize Size] VG [PVs]

--stripes Chỉ định số lượng ổ sử dụng để chia dữ liệu, không tính thiết bị riêng(chứa toàn bộ dữ liệu). nhỏ nhất là 2.

--stripesize chỉ định kích thước của dữ liệu ghi trên một thiết bị trước khi chuyển sang ghi sang các thiết bị khác.

PVs chỉ định các PV sẽ được sử dụng cho LV. Nếu không chỉ định LVM sẽ tự động chọn ra sổ PV bằng Number +1 PV cho LV này.

raid5

raid5 là một loại striping sử dụng thêm một thiết bị để lưu các block. Dữ liệu và các block được lưu trên mỗi thiết bị.

lvcreate --type raid5 [--stripes Number --stripesize Size] VG [PVs]
--stripes specifies the number of devices to use for LV data. This does not include the extra device lvm adds for storing parity blocks. A raid5 LV with Number stripes requires Number+1 devices. Number must be 2 or more.

--stripesize specifies the size of each stripe in kilobytes. This is the amount of data that is written to one device before moving to the next.

PVs để chỉ định các PV sẽ được sử dụng. Nếu không chỉ định thì LVm sẽ tự động sử dụng Number+1 PV cho LV này

raid6

Giống như raid 5 nhưng sử dụng thêm 2 thiết bị thay vì 1 thiết bị như raid 5.

lvcreate --type raid6 [--stripes Number --stripesize Size] VG [PVs]
--stripes chỉ định số lương thiết bị dùng để lưu trữ dữ liệu phân tán chưa kể hai thiết bị thêm.

--stripesize

PVs specifies the devices to use. Nễu không chỉ định lvm sẽ chọn ra Number + 2 pv.

Like raid5, there are variations of raid6 with different algorithms for placing the parity blocks. The default variant is raid6_zr (raid6 zero restart, aka left symmetric, which is a rotating parity 0 with data restart.) See RAID6 variants below.

raid10

raid10 is a combination of raid1 and raid0, striping data across mirrored devices. LV data remains available if one or more devices remains in each mirror set. The minimum number of devices required is 4.

raid10 là sự kết hợp của raid 1 và raid 0, chia dữ liệu ra các thiết bị đã được nhân bản.

lvcreate --type raid10
            [--mirrors NumberMirrors]
            [--stripes NumberStripes --stripesize Size]
            VG [PVs]

    --mirrors specifies the number of mirror images within each stripe.
            e.g.  --mirrors 1 means there are two images of the data, the
            original and one mirror image.

    --stripes specifies the total number of devices to use in all raid1
            images (not the number of raid1 devices to spread the LV
            across, even though that is the effective result).  The number
            of devices in each raid1 mirror will be
            NumberStripes/(NumberMirrors+1), e.g. mirrors 1 and stripes 4
            will stripe data across two raid1 mirrors, where each mirror
            is devices.

    --stripesize specifies the size of each stripe in kilobytes.  This is
            the amount of data that is written to one device before moving
            to the next.

    PVs specifies the devices to use.  If not specified, lvm will choose
    the necessary devices.  Devices are used to create mirrors in the
    order listed, e.g. for mirrors 1, stripes 2, listing PV1 PV2 PV3 PV4
    results in mirrors PV1/PV2 and PV3/PV4.

    RAID10 is not mirroring on top of stripes, which would be RAID01,
    which is less tolerant of device failures.

Tài liệu tham khảo:

http://man7.org/linux/man-pages/man7/lvmraid.7.html