Introduction of Soft RAID Concepts and Configuration Method

Keywords: Linux Database vim

Enterprise-level database applications are mostly deployed on RAID disk array servers, which can improve disk access performance and achieve fault tolerance/disaster tolerance.
RAID (Redundant Disk Array), simply understood, is to take some inexpensive hard disks to make an array. Its purpose is to expand storage capacity, improve read and write performance, and realize data redundancy (backup disaster recovery).

Mainstream can be roughly divided into several levels: RAID 0, RAID 1, RAID 5, RAID 6, RAID 10, RAID 01, RAID 50, etc.

  • RAID 0 is abbreviated as disk stripping. It can provide the best read and write performance. If you make two disks into RAID 0, you can write to both A and B disks at the same time when writing data. What I need to say here is, "Write at the same time" does not mean that the same content of the file is "completely written at the same time" on disk A and disk B. For example, a 100M file needs to be written to a disk, assuming that the write speed of a single disk is 10M/S, it takes 10 seconds to complete the write. But in RAID 0 array environment with A and B disks, 10M content can be written to A disk in a single time (in the smallest unit of seconds/S), and the following 10M content can be written to B disk at the same time. In this way, the writing speed becomes 20M/S, which takes only 5 seconds to complete, and only one disk in each disk. Storage of 50M file content will not result in hard disk storage pressure. Of course, the example of appeal may be inappropriate, but also only refers to the theoretical environment, the actual environment will have many other factors, efficiency can not be achieved.
    To be sure, this will definitely improve the read and write performance, but it also brings a problem that if some of the data is lost, all your data will not be retrieved, because RAID0 does not provide redundant recovery strategy. So RAID 0 can be used in read-only database tables or replicated databases. If you are insensitive to data loss, RAID 0 can also be used. In short, this level is high performance and no redundancy.

  • RAID 1 disk mirroring improves read performance and decreases write performance because it uses a disk as a redundant backup method. If you have two 50G disks, it will add up to 100G, but under RAID 1, you can only use 50G. This method will affect disk space use and reduce I/O. Write performance. Popular: When you write a 100M file to RAID 1, you write the content to disk A and the same content to disk B. In this way, the contents of the two disks are identical (which is the legendary redundancy, not something profound). Originally only need to write to one hard disk, but now to write to two hard disks, the efficiency will certainly become lower. As for the "read" operation, in RAID 1 environment, because the two disks have the same content, the read operation is carried out on both disks at the same time, so the read performance is improved. Regarding data redundancy, only when the first hard disk data is damaged or hung up, the second hard disk is started. Of course, if both hard drives hang up, it will really crash. Ha-ha. It is worth mentioning that in some books or articles, RAID 1 copies the data to the second disk as a mirror backup only after the first hard disk has been written. As I understand it, RAID 1 copies and writes at the same time.
  • The difference between RAID 5 and RAID 1 is that there are more parity checks. All parity checks are available on all disks, which are better than RAID 1 in performance. But once disk I/O fails, it will cause a sharp performance degradation. At the same time, this method is also a compromise between RAID 0 and RAID 1. It is a more general practice. In a simple language, RAID5 arrays are composed of at least three hard disks (or more). When data is written to the hard disk, it is written directly to the hard disk in the form of one hard disk. If RAID5 is used, the data will be written into three parts according to the algorithm, and then written to the three hard disks. At the same time, the verification information will be written on these three hard disks. When reading the written data, the data content will be read from the three hard disks, and then checked by the verification information. When one of the hard disks is damaged, the data content of the third hard disk can be calculated from the data stored on the other two hard disks. That is to say, RAID5 only allows one hard disk to fail, which needs to be replaced as soon as possible. When the faulty hard disk is replaced, the data written during the faulty period will be re-checked. If another failure is not solved, it will be catastrophic.
  • RAID 10 is a combination of RAID 0 and RAID 1. It provides high performance, high availability and better performance than RAID 5. It is especially suitable for applications written in large quantities, but the cost is relatively high, no matter how many pieces it is. You lose half of your disk storage. It takes at least four hard disks to complete. A and B do data segmentation and store half of the data separately. C and D do mirror backups of A and B respectively. In this way, it's really perfect, and it's also the best state of my ideal. No parity check for RAID 5 is required. Obviously, the cost would be higher. Another pity is the "short board effect" of performance.

Through the introduction of RAID 10 above, we can understand the performance mode of RAID 50, right? Not here.

The following is a comprehensive performance and application scenario of various RAID levels:

Soft RAID Configuration Command-mdadm

Command format:

[root@localhost ~]# mdadm -C /dev/md5 -a yes -l 5 -n 3 -x 1 /dev/sd[b,c,d,e]
//perhaps
[root@localhost ~]# mdadm -C /dev/md0 -ayes -l5 -n3 -x1 /dev/sd[b-e]1

About the above options and parameters:

  • - C -- create: Create patterns
  • - a -- auto {yes | no}: Agree to create a device. If you do not add this parameter, you must first use the mknod command to create a RAID device. However, it is recommended to use the - a yes parameter to create a RAID device at one time.
  • - L -- level#: Array mode, supported by linear, raid0, raid1, raid4, raid5, raid6, raid10, multipath, faulty, container;
  • - n #: Create this RAID using # block devices (- n 3 means create this RAID with three hard disks)
  • - x #: There are only # blocks in the hot standby in the current array (- x 1 means that there is only one hot standby)

Create an example of RAID (take RAID 5 for example)

The requirements are as follows:

  1. RAID 5 is composed of four partitions, one of which serves as the reserve disk. When the RAID in work is damaged, the reserve disk is on top.
  2. Each partition is 20GB in size.
  3. Set one partition as a preparatory partition.
  4. Mount to / test directory for use

Start configuring:

1. Create RAID 5:

[root@localhost ~]# fdisk -l | grep  disk      #Here are the disks used for RAID 5
                    ..........................#Omit part of content
//Disk/dev/sdb: 21.5 GB, 21474836480 bytes, 41943040 sectors
//Disk label type: gpt
//Disk/dev/sdc: 21.5 GB, 21474836480 bytes, 41943040 sectors
//Disk label type: gpt
//Disk/dev/sdd: 21.5 GB, 21474836480 bytes, 41943040 sectors
//Disk label type: gpt
//Disk/dev/sde: 21.5 GB, 21474836480 bytes, 41943040 sectors
//Disk label type: gpt
                    ..........................#Omit part of content
[root@localhost ~]# mdadm -C /dev/md0 -a yes -l 5 -n 3 -x 1 /dev/sd[b,c,d,e]
                     ........................#Ignore some hints
Continue creating array? y                   #Enter "y" for confirmation
mdadm: Defaulting to version 1.2 metadata
mdadm: array /dev/md0 started.       #/ dev/md0 was successfully created.
[root@localhost ~]# cat /proc/mdstat       #Query the RAID information you just created
Personalities : [raid6] [raid5] [raid4] 
md0 : active raid5 sdd[4] sde[3](S) sdc[1] sdb[0]   #Entity disks that make up RAID and their order
 41908224 blocks super 1.2 level 5, 512k chunk, algorithm 2 [3/3] [UUU]  
 #Relevant information, chunk size and RAID level indicate that the latter three U stands for normal, if not U, for errors.

unused devices: <none>

[root@localhost ~]# mdadm -D /dev/md0      #The results of this command are more humane.
/dev/md0:                          #Device File Name of RAID
           Version : 1.2
     Creation Time : Thu Sep  5 09:37:42 2019    #Time to create RAID
        Raid Level : raid5      #RAID level, here is RAID 5
        Array Size : 41908224 (39.97 GiB 42.91 GB)    #Available dosage of whole RAID
     Used Dev Size : 20954112 (19.98 GiB 21.46 GB)     #Available capacity of each disk
      Raid Devices : 3      #Number of disks that make up RAID
     Total Devices : 4       #Total number of disks including spare
       Persistence : Superblock is persistent

       Update Time : Thu Sep  5 09:39:28 2019
             State : clean          #Current usage status of this RAID
    Active Devices : 3        #Number of devices started
   Working Devices : 4       #Number of devices currently used for this RAID
    Failed Devices : 0            #Number of damaged equipment
     Spare Devices : 1      #Number of reserve disks

            Layout : left-symmetric
        Chunk Size : 512K             #Block capacity of chunk

Consistency Policy : resync

              Name : localhost.localdomain:0  (local to host localhost.localdomain)
              UUID : d395d245:8f9294b4:3223cd47:b0bee5d8
            Events : 18
#Here are the usage of each disk, including three active syncs and one spare
    Number   Major   Minor   RaidDevice State
       0       8       16        0      active sync   /dev/sdb
       1       8       32        1      active sync   /dev/sdc
       4       8       48        2      active sync   /dev/sdd

       3       8       64        -      spare   /dev/sde
#RaidDevice is the order of disks within this RAID

2. Format and mount:

[root@localhost ~]# mkfs.xfs /dev/md0          #Format the RAID 5 just created
[root@localhost ~]# mkdir /test       #Create mount points
[root@localhost ~]# mount /dev/md0 /test       #mount
[root@localhost ~]# df -hT /test      #Verify mounting and use it as a normal file system
//File System Type Capacity Used Available% Mount Points
/dev/md0       xfs    40G   33M   40G    1% /test
#Write the mount information into / etc/fstab to start up automatically. The device name can be / dev/md0 or UUID of the device.
[root@localhost ~]# blkid /dev/md0     #Query the UUID of RAID 5
/dev/md0: UUID="93830b3a-69e4-4cbf-b255-f43f2ae4864b" TYPE="xfs" 
[root@localhost ~]# vim /etc/fstab   #Open / etc/fstab and write the following
UUID=93830b3a-69e4-4cbf-b255-f43f2ae4864b /test xfs     defaults        0 0

3. Testing RAID 5:

Regarding testing, it must involve writing parameters to manage RAID, as follows:

  • - F -- fail: Set the following device to an error state;
  • - a -- add: The following devices will be added to the md;
  • - R -- remove: Remove the following device from the md;
[root@localhost ~]# echo "hi,girl,good morning." > /test/a.txt   #Write data
[root@localhost ~]# cat /test/a.txt     #See
hi,girl,good morning.
[root@localhost ~]# mdadm /dev/md0 -f /dev/sdb    #Damage / dev/sdb
mdadm: set /dev/sdb faulty in /dev/md0
[root@localhost ~]# mdadm -D /dev/md0     #View the status of RAID 5
/dev/md0:
           Version : 1.2
     Creation Time : Thu Sep  5 09:37:42 2019
        Raid Level : raid5
        Array Size : 41908224 (39.97 GiB 42.91 GB)
     Used Dev Size : 20954112 (19.98 GiB 21.46 GB)
      Raid Devices : 3
     Total Devices : 4
       Persistence : Superblock is persistent

       Update Time : Thu Sep  5 10:47:00 2019
             State : clean 
    Active Devices : 3
   Working Devices : 3
    Failed Devices : 1        #One failed disk was found
     Spare Devices : 0

            Layout : left-symmetric
        Chunk Size : 512K

Consistency Policy : resync

              Name : localhost.localdomain:0  (local to host localhost.localdomain)
              UUID : d395d245:8f9294b4:3223cd47:b0bee5d8
            Events : 39

    Number   Major   Minor   RaidDevice State
       3       8       64        0      active sync   /dev/sde
       1       8       32        1      active sync   /dev/sdc
       4       8       48        2      active sync   /dev/sdd

       0       8       16        -      faulty   /dev/sdb       #This is the damaged disk just now.
#It can be found that the damaged disk has been replaced by the standby disk.
[root@localhost ~]# df -hT /test      #Available capacity or 40G
//File System Type Capacity Used Available% Mount Points
/dev/md0       xfs    40G   33M   40G    1% /test
root@localhost ~]# mdadm /dev/md0 -r /dev/sdb     #Remove damaged disk from RAID group
mdadm: hot removed /dev/sdb from /dev/md0
[root@localhost ~]# mdadm /dev/md0 -a /dev/sdf      #Add a disk to the RAID group
mdadm: added /dev/sdf
[root@localhost ~]# mdadm -D /dev/md0    #View the membership status of RAID groups
/dev/md0:
                       .............#Omit part of content
    Number   Major   Minor   RaidDevice State
       3       8       64        0      active sync   /dev/sde
       1       8       32        1      active sync   /dev/sdc
       4       8       48        2      active sync   /dev/sdd

       5       8       80        -      spare   /dev/sdf   
             #The newly added disk has become the reserve disk for the RAID group

4. Setting RAID Group to Ordinary Disk

[root@localhost ~]# umount /test
[root@localhost ~]# vim /etc/fstab
                       .............#Omit part of content
UUID=93830b3a-69e4-4cbf-b255-f43f2ae4864b /test xfs     defaults        0 0             
#Automount and delete RAID 5 settings
[root@localhost ~]# dd if=/dev/zero of=/dev/md0 bs=1M count=50
#Damage the superblock of RAID
[root@localhost ~]# mdadm --stop /dev/md0     #Stop using RAID
mdadm: stopped /dev/md0
#The following is to overwrite the superblock information of the member disks in RAID
[root@localhost ~]# dd if=/dev/zero of=/dev/sdc bs=1M count=10
[root@localhost ~]# dd if=/dev/zero of=/dev/sdd bs=1M count=10
[root@localhost ~]# dd if=/dev/zero of=/dev/sde bs=1M count=10
[root@localhost ~]# dd if=/dev/zero of=/dev/sdf bs=1M count=10
[root@localhost ~]# cat /proc/mdstat         #Confirm that the RAID does not exist below
Personalities : [raid6] [raid5] [raid4] 
unused devices: <none>

After the above operation, the disk is restored to normal disk, but the original data is not available, and the subsequent use has not been studied in depth. Some re-checking commands can be used to scan or restart the system, which can be mounted for use, otherwise it may not be mounted.

Re-test command:

[root@localhost ~]# partprobe /dev/sdc

———————— This is the end of the article. Thank you for reading.————————

Posted by 40esp on Wed, 04 Sep 2019 22:35:13 -0700