RAID and How to Set It Up on Alibaba Cloud

RAID Storage Techniques

  • Striping: It is a method of splitting the flow of data into blocks and spreading the data blocks across multiple storage devices. This will increase the read/write performance of data.
  • Mirroring: It replicates the data into two or more disks. This method is very good for applications that require high performance and high availability.
  • Parity: This method is mainly used for fault tolerance by calculating the data in two drives and storing the results on a third.

Hardware and Software Implementations of RAID

RAID Levels

RAID0

RAID1

RAID5

RAID6

RAID10

Setting up RAID0 Array

Prerequisites

  • A newly created Alibaba Cloud ECS instance installed with Ubuntu 16.04.
  • A minimum of two hard drives that are attached to your instance.
  • A root password that is set up to your instance.

Getting Started

Disk /dev/sda: 10 GiB, 10737418240 bytes, 20971520 sectors
/dev/sda1 * 2048 499711 497664 243M 83 Linux
/dev/sda2 501758 20969471 20467714 9.8G 5 Extended
/dev/sda5 501760 20969471 20467712 9.8G 8e Linux LVM
Disk /dev/sdb: 2 GiB, 2147483648 bytes, 4194304 sectors
Disk /dev/sdc: 2 GiB, 2147483648 bytes, 4194304 sectors

Install Mdadm

Create RAID0 Array

mdadm --create --verbose /dev/md0 --level=0 --raid-devices=2 /dev/sdb /dev/sdc
mdadm: chunk size defaults to 512K
mdadm: Defaulting to version 1.2 metadata
mdadm: array /dev/md0 started.
cat /proc/mdstat
Personalities : [raid0] 
md0 : active raid0 sdc[1] sdb[0]
4190208 blocks super 1.2 512k chunks

unused devices: <none>
mdadm -E /dev/sd[b-c]
/dev/sdb:
Magic : a92b4efc
Version : 1.2
Feature Map : 0x0
Array UUID : a4d636f7:eb05e54a:28cdb118:46076be1
Name : Node2:0 (local to host Node2)
Creation Time : Sun Nov 18 12:11:01 2018
Raid Level : raid0
Raid Devices : 2
Avail Dev Size : 4190208 (2046.34 MiB 2145.39 MB)
Data Offset : 4096 sectors
Super Offset : 8 sectors
Unused Space : before=4008 sectors, after=0 sectors
State : clean
Device UUID : 8b79b1f4:d313744a:5559fc18:cff176ba
Update Time : Sun Nov 18 12:11:01 2018
Bad Block Log : 512 entries available at offset 72 sectors
Checksum : 15bc99ce - correct
Events : 0
Chunk Size : 512K Device Role : Active device 0
Array State : AA ('A' == active, '.' == missing, 'R' == replacing)
/dev/sdc:
Magic : a92b4efc
Version : 1.2
Feature Map : 0x0
Array UUID : a4d636f7:eb05e54a:28cdb118:46076be1
Name : Node2:0 (local to host Node2)
Creation Time : Sun Nov 18 12:11:01 2018
Raid Level : raid0
Raid Devices : 2
Avail Dev Size : 4190208 (2046.34 MiB 2145.39 MB)
Data Offset : 4096 sectors
Super Offset : 8 sectors
Unused Space : before=4008 sectors, after=0 sectors
State : clean
Device UUID : 528b5008:af0043f3:dbb81ab4:01c7cb32
Update Time : Sun Nov 18 12:11:01 2018
Bad Block Log : 512 entries available at offset 72 sectors
Checksum : e59dcd29 - correct
Events : 0
Chunk Size : 512K Device Role : Active device 1
Array State : AA ('A' == active, '.' == missing, 'R' == replacing)
mdadm --detail /dev/md0
/dev/md0:
Version : 1.2
Creation Time : Sun Nov 18 12:11:01 2018
Raid Level : raid0
Array Size : 4190208 (4.00 GiB 4.29 GB)
Raid Devices : 2
Total Devices : 2
Persistence : Superblock is persistent
Update Time : Sun Nov 18 12:11:01 2018
State : clean
Active Devices : 2
Working Devices : 2
Failed Devices : 0
Spare Devices : 0
Chunk Size : 512K Name : Node2:0 (local to host Node2)
UUID : a4d636f7:eb05e54a:28cdb118:46076be1
Events : 0
Number Major Minor RaidDevice State
0 8 16 0 active sync /dev/sdb
1 8 32 1 active sync /dev/sdc

Create a Filesystem on RAID Array

mkfs.ext4 /dev/md0
mkdir /opt/raid0
mount /dev/md0 /opt/raid0
df -h
Filesystem                  Size  Used Avail Use% Mounted on
udev 478M 0 478M 0% /dev
tmpfs 100M 3.3M 96M 4% /run
/dev/mapper/Node1--vg-root 9.0G 5.8G 2.8G 69% /
tmpfs 497M 4.0K 497M 1% /dev/shm
tmpfs 5.0M 0 5.0M 0% /run/lock
tmpfs 497M 0 497M 0% /sys/fs/cgroup
/dev/sda1 236M 85M 139M 38% /boot
cgmfs 100K 0 100K 0% /run/cgmanager/fs
tmpfs 100M 0 100M 0% /run/user/0
/dev/md0 3.9G 8.0M 3.7G 1% /opt/raid0
mdadm --detail --scan | tee -a /etc/mdadm/mdadm.conf
ARRAY /dev/md0 metadata=1.2 name=Node2:0 UUID=a4d636f7:eb05e54a:28cdb118:46076be1
nano /etc/fstab
/dev/md0  /opt/raid0     ext4    defaults,nofail,discard   0  0

Delete RAID0 Array

umount /dev/md0
mdadm --stop /dev/md0
mdadm: stopped /dev/md0
mdadm --zero-superblock /dev/sdb /dev/sdc
cat /proc/mdstat
Personalities : [raid0] 
unused devices: <none>

Setting Up RAID6 Array

Prerequisites

  • A fresh Alibaba Cloud Ubuntu 16.04 instance.
  • Minimum four extra hard drives are attached to your instance.
  • A root password is set up to your instance.

Getting Started

Disk /dev/sda: 10 GiB, 10737418240 bytes, 20971520 sectors
/dev/sda1 * 2048 499711 497664 243M 83 Linux
/dev/sda2 501758 20969471 20467714 9.8G 5 Extended
/dev/sda5 501760 20969471 20467712 9.8G 8e Linux LVM
Disk /dev/sdb: 2 GiB, 2147483648 bytes, 4194304 sectors
Disk /dev/sdc: 2 GiB, 2147483648 bytes, 4194304 sectors
Disk /dev/sdd: 2 GiB, 2147483648 bytes, 4194304 sectors
Disk /dev/sde: 2 GiB, 2147483648 bytes, 4194304 sectors

Install Mdadm

Create RAID6 Array

mdadm --create --verbose /dev/md0 --level=6 --raid-devices=4 /dev/sdb /dev/sdc /dev/sdd /dev/sde
mdadm: layout defaults to left-symmetric
mdadm: layout defaults to left-symmetric
mdadm: chunk size defaults to 512K
mdadm: size set to 2095104K
mdadm: Defaulting to version 1.2 metadata
mdadm: array /dev/md0 started.
cat /proc/mdstat
Personalities : [linear] [multipath] [raid0] [raid1] [raid6] [raid5] [raid4] [raid10] 
md0 : active raid6 sde[3] sdd[2] sdc[1] sdb[0]
4190208 blocks super 1.2 level 6, 512k chunk, algorithm 2 [4/4] [UUUU]

unused devices: <none>
mdadm --detail /dev/md0
/dev/md0:
Version : 1.2
Creation Time : Sun Nov 18 13:03:32 2018
Raid Level : raid6
Array Size : 4190208 (4.00 GiB 4.29 GB)
Used Dev Size : 2095104 (2046.34 MiB 2145.39 MB)
Raid Devices : 4
Total Devices : 4
Persistence : Superblock is persistent
Update Time : Sun Nov 18 13:04:35 2018
State : clean
Active Devices : 4
Working Devices : 4
Failed Devices : 0
Spare Devices : 0
Layout : left-symmetric
Chunk Size : 512K
Name : Node2:0 (local to host Node2)
UUID : e7d5fc59:661516bc:3b1001a4:8cd03659
Events : 17
Number Major Minor RaidDevice State
0 8 16 0 active sync /dev/sdb
1 8 32 1 active sync /dev/sdc
2 8 48 2 active sync /dev/sdd
3 8 64 3 active sync /dev/sde

Create a Filesystem on RAID Array

mkfs.ext4 /dev/md0
mkdir /opt/raid6
mount /dev/md0 /opt/raid6
df -h
Filesystem                  Size  Used Avail Use% Mounted on
udev 478M 0 478M 0% /dev
tmpfs 100M 3.3M 96M 4% /run
/dev/mapper/Node1--vg-root 9.0G 5.8G 2.8G 69% /
tmpfs 497M 4.0K 497M 1% /dev/shm
tmpfs 5.0M 0 5.0M 0% /run/lock
tmpfs 497M 0 497M 0% /sys/fs/cgroup
/dev/sda1 236M 85M 139M 38% /boot
cgmfs 100K 0 100K 0% /run/cgmanager/fs
tmpfs 100M 0 100M 0% /run/user/0
/dev/md0 3.9G 8.0M 3.7G 1% /opt/raid6
mdadm --detail --scan | tee -a /etc/mdadm/mdadm.conf
ARRAY /dev/md0 metadata=1.2 name=Node2:0 UUID=e7d5fc59:661516bc:3b1001a4:8cd03659
update-initramfs -u
nano /etc/fstab
/dev/md0  /opt/raid6     ext4    defaults,nofail,discard   0  0

Add a Spare Drives to RAID Array

mdadm --add /dev/md0 /dev/sdf
mdadm --detail /dev/md0
/dev/md0:
Version : 1.2
Creation Time : Sun Nov 18 13:03:32 2018
Raid Level : raid6
Array Size : 4190208 (4.00 GiB 4.29 GB)
Used Dev Size : 2095104 (2046.34 MiB 2145.39 MB)
Raid Devices : 4
Total Devices : 5
Persistence : Superblock is persistent
Update Time : Sun Nov 18 13:20:49 2018
State : clean
Active Devices : 4
Working Devices : 5
Failed Devices : 0
Spare Devices : 1
Layout : left-symmetric
Chunk Size : 512K
Name : Node2:0 (local to host Node2)
UUID : e7d5fc59:661516bc:3b1001a4:8cd03659
Events : 18
Number Major Minor RaidDevice State
0 8 16 0 active sync /dev/sdb
1 8 32 1 active sync /dev/sdc
2 8 48 2 active sync /dev/sdd
3 8 64 3 active sync /dev/sde
4 8 80 - spare /dev/sdf

Test RAID6 Fault Tolerance

mdadm --manage --fail /dev/md0 /dev/sdc
mdadm: set /dev/sdc faulty in /dev/md0
mdadm --detail /dev/md0
/dev/md0:
Version : 1.2
Creation Time : Sun Nov 18 13:03:32 2018
Raid Level : raid6
Array Size : 4190208 (4.00 GiB 4.29 GB)
Used Dev Size : 2095104 (2046.34 MiB 2145.39 MB)
Raid Devices : 4
Total Devices : 5
Persistence : Superblock is persistent
Update Time : Sun Nov 18 13:25:59 2018
State : clean, degraded, recovering
Active Devices : 3
Working Devices : 4
Failed Devices : 1
Spare Devices : 1
Layout : left-symmetric
Chunk Size : 512K
Rebuild Status : 57% complete Name : Node2:0 (local to host Node2)
UUID : e7d5fc59:661516bc:3b1001a4:8cd03659
Events : 29
Number Major Minor RaidDevice State
0 8 16 0 active sync /dev/sdb
4 8 80 1 spare rebuilding /dev/sdf
2 8 48 2 active sync /dev/sdd
3 8 64 3 active sync /dev/sde
1 8 32 - faulty /dev/sdc

Original Source

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Alibaba Cloud

Alibaba Cloud

Follow me to keep abreast with the latest technology news, industry insights, and developer trends. Alibaba Cloud website:https://www.alibabacloud.com