This is the 12th day of my participation in Gwen Challenge

Hello everyone, I am the Internet old xin, today we are going to discuss disk array RAID disk array.

I. Concepts of RAID

The concept of RAID is defined in the encyclopedia as follows:

Redundant Arrays (RAID) is a Redundant array of Independent Disks. A disk array consists of many inexpensive disks that are combined into a large-capacity disk group in the form of hardware (RAID card) or software (MDADM). Multiple disks are combined to improve the overall disk system performance.

With this technology, data is sliced into many sections and stored separately on individual hard drives. Disk arrays can also take advantage of the Parity Check concept. If any disk in the array fails, the data can still be read. During data reconstruction, the data can be calculated and put back into a new disk

In a word, RAID is an honorary array of disks, which improves the read and write rate and has the fault tolerance function.

The basic idea of RAID is to combine several hard disks in a certain way to form a new disk array so that the new disk array can meet the requirements of high-performance hard disks.

2. RAID type

  • raid 0

RAID0 is a very simple way to combine multiple disks to form a large storage capacity. When we write data, the data is divided into N pieces to independently read and write data from N disks. In this way, the N pieces of data are concurrently written to disks, resulting in high performance.

  • raid 1

RAID1 is the highest cost per unit of a disk array. When data is written to the disk, the same data is written to the working disk and the mirror disk, so the actual space usage is only 50%. The two disks are used as one disk, which is a relatively expensive solution.

RAID1 actually has the opposite effect to RAID0. RAID1, when you write two copies, you make a redundant copy of your data. In this way, any damaged disk can be based on another disk to recover data, data reliability is very strong, but the performance is not so good.

  • raid 5

In RAID5 mode, it is no longer necessary to write checksum codes on separate disks. It distributes parity code information to each disk. For example, if there are N disks in total, the data to be written is divided into N copies, and the parity code information is concurrently written to the N disks (data and parity code information must be stored on different disks). Once a disk is corrupted, the remaining data and the corresponding parity code information can be used to recover the corrupted data.

This is one of the most commonly used methods. RAID5 is a solution that combines storage performance, data security, and storage cost.

RAID5 requires at least three disks to form a disk array and allows a maximum of one disk to fail at the same time. If two disks are damaged at the same time, the data cannot be recovered.

  • raid 10

RAID10 takes advantage of both RAID1 and RAID0. The disk is divided into two disks based on RAID1 mode. When data is written to the two disks, all data is written to the two disks at the same time. This ensures data protection. In addition, each disk is divided into N concurrent reads and writes based on RAID0 technology, which also ensures data efficiency.

But you can also see that RAID10 mode uses half of the disk space for redundant data, which is wasteful and therefore not used very much.

1. RAID implementation:
  • Hard RAID: Requires a RAID controller card with its own CPU and high processing speed
  • Soft RAID: Implemented by operating systems, including Windows and Linux

We are going to simulate the implementation of soft raid5 today

2. Implementation of soft RAID 5

The experimental steps of this time are as follows: 1) create 4 hard disks 2) create RAID 3) format and mount 4) view RAID information 5) simulate the failure of one hard disk 6) add the repaired disk to the existing array

1) Add a new hard drive and create 5 partitions

Partition the newly added hard drive into five to simulate five hard drives.

[root@xinsz08-15 ~]# ll /dev/sd* # Existing partitionBrw-rw ---- 1 root disk 8, 0 6月 29 05:45 /dev/sda brw-rw---- 1 root disk 8, 1 6月 29 05:45 /dev/sda1 brw-rw---- 1 root disk 8, 2 6月 29 05:45 /dev/sda2 brw-rw---- 1 root disk 8, 3 6月 29 05:45 /dev/sda3 brw-rw---- 1 root disk 8, 16 6月 29 05:45 /dev/sdbCopy the code
[root@xinsz08-15 ~]# fdisk /dev/sdb

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 
Value out of range.
Partition number (1-4): 1
First cylinder (1-3263, default 1): 
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-3263, default 3263): +5G

Command (m for help) :Copy the code

According to the above partitioning method, there are four zones, which are 5G respectively

Note: Logical partitions cannot be used as disk arrays

[root@xinsz08-15 ~]# ll /dev/sdb*Brw-rw ---- 1 root disk 8, 16 June 29 06:02 /dev/sdb brw-rw---- 1 root disk 8, 17 6月 29 06:02 /dev/sdb1 brw-rw---- 1 root disk 8, 18 6月 29 06:02 /dev/sdb2 brw-rw---- 1 root disk 8, 19 June 29 06:02 /dev/sdb3 brw-rw---- 1 root disk 8, 20 June 29 06:02 /dev/sdb4Copy the code
2. Create a RAID

[root@xinsz08-15 ~]# yum install mdadm

Basic parameters of MDADM:

parameter role
C Create a RAID
/dev/m0 The first RAID device
-L5 RAID5
-n Number of RAID members
-x Number of hot spare disks
-a Add hot standby
-G Hot standby is converted to membership

Next we create our first RAID device, a RAID 5, with three disks for the array and one for hot spare.

[root@xinsz08-15 ~]# mdadm -c /dev/md0-l5-n3-x1 /dev/sdb{1,2,3,4}
mdadm: /dev/sdb4 appears to be part of a raid array:
       level=raid0 devices=0 ctime=Thu Jan  1 08:00:00 1970
mdadm: partition table exists on /dev/sdb4 but will be lost or
       meaningless after creating array
mdadm: largest drive (/dev/sdb4) exceeds size (5249024K) by more than 1%
Continue creating array? y
mdadm: Defaulting to version 1.2 metadata
mdadm: array /dev/md0 started.

Copy the code

[root@xinsz08-15 ~]# mdadm -d -s > /etc/mdadm.conf

Example Query existing disk arrays

  [root@xinsz08-15 ~]# mdadm -D -sARRAY/dev/md0 metadata spares = 1 name = = 1.2 xinsz08-15:0 UUID = 85 d2c0f0: d2e390b4:6 f91164c: c7e3f691 [root @ xinsz08-15 ~]# mdadm -d -s /dev/md0ARRAY/dev/md0 metadata spares = 1 name = = 1.2 xinsz08-15:0 UUID = 85 d2c0f0: d2e390b4:6 f91164c: c7e3f691Copy the code
3. Format the mount
[root@xinsz08-15 ~]Format the disk array as an ext4 systemMke2fs 1.41.12 (17-May-2010) File system label = OS :Linux block size =4096 (log=2) Block size =4096 (log=2)
Stride=128 blocks, Stripe width=256 blocks
657072 inodes, 2624512 blocks
131225 blocks (5.00%) reserved for=0 Maximum filesystem blocks=2688548864 81 block groups 32768 blocks per group, 32768 fragments per group 8112 inodes per group Superblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632 Complete Writing superblocks and Filesystem Accounting Information: This filesystem will be automatically checked every 32 mounts or 180 days. You can use the virtualized filesystem to check every 32 days. whichever comes first. Use tune2fs -c or -i to override. [root@xinsz08-15 ~]# 

Copy the code

Create a mount directory and mount it

[root@xinsz08-15 ~]# mkdir /mnt/raid5
[root@xinsz08-15 ~]# mount /dev/md0 /mnt/raid5
[root@xinsz08-15 ~]# df -h/dev/md0 9.8g 23M 9.3g 1% / MNT /raid5 [root@xinsz08-15 ~]# 
Copy the code
4. Check the RAID information again
[root@xinsz08-15 ~]# mdadm -d /dev/md0
/dev/md0:   # disk nameVersion: 1.2# Disk version
  Creation Time : Mon Jun 29 06:03:43 2020   The time to create the disk array
     Raid Level : raid5       Disk array is RIAD5Array Size: 10498048 (10.01 GiB 10.75 GB) Used Dev Size: 5249024 (5.01 GiB 5.38 GB) Raid Devices: 3# RAID array consisting of three disks
  Total Devices : 4     # Four quick disks in total, because there is a spare disk
    Persistence : Superblock is persistent

    Update Time : Mon Jun 29 06:09:43 2020
          State : clean 
 Active Devices : 3    # 3 active disks
Working Devices : 4    # total of four
 Failed Devices : 0    # 0 broken
  Spare Devices : 1    Share one spare disk

         Layout : left-symmetric
     Chunk Size : 512K

           Name : xinsz08-15:0  (local to host xinsz08-15)
           UUID : 85d2c0f0:d2e390b4:6f91164c:c7e3f691
         Events : 18

    Number   Major   Minor   RaidDevice State
       0       8       17        0      active sync   /dev/sdb1
       1       8       18        1      active sync   /dev/sdb2
       4       8       19        2      active sync   /dev/sdb3

       3       8       20        -      spare   /dev/sdb4
[root@xinsz08-15 ~]# 

Copy the code
5. Simulate a broken disk and remove it

Terminal 1: Simulate a broken disk and remove it

-f simulation broken, -r removed

[root@xinsz08-15 ~]# mdadm /dev/md0 -f /dev/sdb2 -r /dev/sdb2

mdadm: set /dev/sdb2 faulty in /dev/md0
mdadm: hot removed /dev/sdb2 from /dev/md0
Copy the code

[root@xinsz08-15 ~]# watch -n 0.5 ‘mdadm -d /dev/md0’

Finally, you will see the spare Devices spare drive become known as working drive. The total number of disks becomes 3.

6. Restore the deleted SDB2 and add it to the storage array again
[root@xinsz08-15 ~]# mdadm /dev/md0 -a /dev/sdb2
mdadm: added /dev/sdb2
Copy the code

View: You can see that sDB2 has become a hot spare disk

[root@xinsz08-15 ~]# mdadm -D /dev/md0/dev/md0: Version: 1.2 Creation Time: Mon Jun 29 06:03:43 2020 Raid Level: RAID5 Array Size: 10498048 (10.01 GiB 10.75 GB) Used Dev Size: 5249024 (5.01 GiB 5.38 GB) Raid Devices: 3 Total Devices: 4 Persistence : Superblock is persistent Update Time : Mon Jun 29 06:29:52 2020 State : clean Active Devices : 3 Working Devices : 4 Failed Devices : 0 Spare Devices : 1 Layout : left-symmetric Chunk Size : 512K Name : xinsz08-15:0 (local to host xinsz08-15)
           UUID : 85d2c0f0:d2e390b4:6f91164c:c7e3f691
         Events : 39

    Number   Major   Minor   RaidDevice State
       0       8       17        0      active sync   /dev/sdb1
       3       8       20        1      active sync   /dev/sdb4
       4       8       19        2      active sync   /dev/sdb3

       5       8       18        -      spare   /dev/sdb2

Copy the code

Conclusion:

Disk array is a very important concept and needs to be done carefully with many reference experiments.