Friday, 8 May 2015

Configuring Software RAID in RHEL7

RAID (Redundant Array of Independent Disks) is a system that uses multiple hard drives to distribute or replicate data across several disks.

RAID can do 2 basic things:
First, it can improve performance by "striping" data across multiple drives, thus allowing several drives to work simultaneously.
Second, it can "mirror" data across multiple drives, decreasing the risk associated with a single failed disk. 

RAID has several levels.
RAID 0 : Striped Set with no fault tolerance. Data is striped across all the disks in the RAID array.

RAID 1: Disk Mirroring. Data is mirrored to provide fault tolerance.

RAID 1+0 and RAID 0+1 : Combines the performance benefits of RAID 0 with the redundancy benefits of RAID 1. They use stripping and mirroring.

RAID 3: Striped set with parallel disk access and a dedicated parity disk.

RAID 4: Striped set with independent disk access and a dedicated parity disk.

RAID 5: Striped set with independent disk access and a distributed parity.

RAID 6: Striped set with independent disk access and a dual distributed parity to enable survival if two disk failure occur.
 
 In this tutorial, we will create Level 5 RAID device using 3 disks. RAID 5 strips data for performance and uses parity for fault tolerance. The drives (strips) are independently accessible. Parity is distributed across all disks to overcome the write bottleneck of a dedicated parity disk.


Consider the partitions /dev/sda1, /dev/sda2, /dev/sda3. We will assemble these 3 partitions into 1 logical RAID Level 5 partition.

1) Build a RAID 5 array '/dev/md0' with the above 3 partitions.
[root@oserver1 ~]# mdadm --create /dev/md0 --level=5 --raid-devices=3 /dev/sda1 /dev/sda2 /dev/sda3
mdadm: Defaulting to version 1.2 metadata
mdadm: array /dev/md0 started.


2) View Status
[root@oserver1 ~]# cat /proc/mdstat
Personalities : [raid6] [raid5] [raid4]
md0 : active raid5 sda3[3] sda2[1] sda1[0]
      203776 blocks super 1.2 level 5, 512k chunk, algorithm 2 [3/3] [UUU]
unused devices: <none>

3) Create 'xfs' filesystem on the RAID device '/dev/md0'
[root@oserver1 ~]# mkfs -t xfs /dev/md0
log stripe unit (524288 bytes) is too large (maximum is 256KiB)
log stripe unit adjusted to 32KiB
meta-data=/dev/md0               isize=256    agcount=8, agsize=6272 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=0
data     =                       bsize=4096   blocks=50176, imaxpct=25
         =                       sunit=128    swidth=256 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=0
log      =internal log           bsize=4096   blocks=624, version=2
         =                       sectsz=512   sunit=8 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0

[root@oserver1 ~]# blkid /dev/md0
/dev/md0: UUID="89aa5617-4f4e-4345-8dbe-22a7af46dbe6" TYPE="xfs"

4) Mount the RAID device and create files in it.
[root@oserver1 ~]# mount /dev/md0 /mnt
[root@oserver1 ~]# touch /mnt/foo{1,2,3}
[root@oserver1 ~]# ls /mnt
foo1  foo2  foo3

5) Preserving the configuration.
[root@oserver1 ~]# mdadm --detail /dev/md0 > /etc/mdadm.conf

At boot time, the 'mdmonitor' service reads the contents of the '/etc/mdadm.conf' file to see which RAID devices to start.

6) To mount automatically at boot time, add entry to '/etc/fstab'
    /dev/md0        /mnt        xfs        defaults      0  2

Simulating a failed disk

1) Simulate a failed disk using mdadm
[root@oserver1 ~]# mdadm /dev/md0 --fail /dev/sda1
mdadm: set /dev/sda1 faulty in /dev/md0

2) View Status
[root@oserver1 ~]# cat /proc/mdstat
Personalities : [raid6] [raid5] [raid4]
md0 : active raid5 sda3[3] sda2[1] sda1[0](F)
      203776 blocks super 1.2 level 5, 512k chunk, algorithm 2 [3/2] [_UU]
unused devices: <none>

3) Verify that the RAID device is working even when one disk has failed
[root@oserver1 ~]# umount /mnt
[root@oserver1 ~]# mount /dev/md0 /mnt
[root@oserver1 ~]# ls /mnt
foo1  foo2  foo3

4) Remove the failed partition.
[root@oserver1 ~]# mdadm /dev/md0 -r /dev/sda1
mdadm: hot removed /dev/sda1 from /dev/md0

5) View Status
[root@oserver1 ~]# cat /proc/mdstat
Personalities : [raid6] [raid5] [raid4]
md0 : active raid5 sda3[3] sda2[1]
      203776 blocks super 1.2 level 5, 512k chunk, algorithm 2 [3/2] [_UU]
unused devices: <none>

6) Add the partition back to the RAID array.
[root@oserver1 ~]# mdadm /dev/md0 -a /dev/sda1
mdadm: added /dev/sda1

7) View Status
[root@oserver1 ~]# cat /proc/mdstat
Personalities : [raid6] [raid5] [raid4]
md0 : active raid5 sda1[4] sda3[3] sda2[1]
      203776 blocks super 1.2 level 5, 512k chunk, algorithm 2 [3/3] [UUU]
unused devices: <none>

No comments:

Post a Comment