Soft RAID configuration methods and concepts introduced

Most enterprise-class database applications deployed on the server RAID disk array, which can improve disk access performance and enables fault-tolerant / disaster recovery.
RAID (redundant disk array), simple to understand, is to get some cheap hard to make arrays. Its purpose is to expand the memory capacity to enhance read and write performance, data redundancy (backup disaster recovery).

Mainstream can be divided into several levels: RAID 0, RAID 1, RAID 5, RAID6, RAID 10, RAID 01, RAID 50 and so on.

  • RAID 0 Acronym disk striping, which can provide the best read and write performance, if you put two disks into RAID0, then at the time of writing data, the write operation can be simultaneously disks A and B is performed on the disk . It should be noted that: "... can simultaneously write," does not mean the same contents of the file "completely written at the same time" A disk and B disk. Analogy: a 100M file needs to be written to disk, assuming a single disk write speed is 10M / S, it takes 10 seconds to complete written work. However, if the environment in a RAID 0 array A, B, the two disks, (in seconds / S is a minimum unit) within a single time, the content may be written A disk 10M, 10M and simultaneously write the contents of the immediately B into the disk, so that figure, the writing speed becomes 20M / S, only 5 seconds to get, and only the contents of each disk file is stored 50M, hard disk storage without causing stress. Of course, the example of Appeal may not be appropriate and just under the theory refers to the environment, the actual environment, there are many other factors, efficiency will definitely not be reached.
    To be sure, this would certainly be able to improve read and write performance, but this also raises the question is, if one part of the data is lost, all your data will not get it back, because RAID0 does not provide redundancy I policy data recovery. So RAID0 can be used in a read-only database data table, or is the result of the copied database, if you lose the data is not sensitive, then you can use RAID 0, short, this level is a high performance, non-redundant.

  • RAID 1 disk mirroring it improves the performance of read and write performance is reduced, because it uses a method to do a disk redundancy, so if you have two 50G disk, then add up to 100G, but in RAID 1 next, then you can only use 50G, this method will affect the disk space usage, reduce the I / O write performance. Popular point of view: you will be a 100M file written to 1:00 RAID, while the contents of the disk write A, the same content will be written to disk B. As a result, the contents of two disks are exactly the same (That legendary "redundancy" is not what profound things). Originally only need to write a hard drive, but now to be written to two hard drives go, efficiency will definitely become low. As for the "read" operation, the RAID 1 environment, since the two disks have the same content, the read operations are performed simultaneously on the two disks, the read performance has been improved, the redundant data on connection, but if the first drive hang or data corruption, the second disk is started. Of course, two hard drives are hung up, it is really collapsed. Haha. It is worth mentioning that some of the books or articles speaking, RAID 1 is the first hard drive after writing is completed, it will copy the data to this argument as a mirror backup to be verified second disk, press I understand that while the copy written.
  • RAID1 and RAID 5 is different is that it is more parity, parity of all information will be all over each disk in RAID1 than some high performance, but once the disk I / O failure occurs, it will cause a sharp decline in performance, this method also simultaneously between the RAID1 RAID0 folded in, it is more common practice. Simple language expressed using at least three hard disks (which may be more) form an array of RAID5, when data is written to the hard disk, according to an embodiment is written directly to the hard disk of the hard drive, if it is RAID5 the data writing will be divided into three parts according to the algorithm, and then write this three hard disks, while writing check information will be written on the hard disk 3 which, when the time to read data written respectively in content data read from the hard disk 3, and then by checking parity information. Wherein when there is damage to a hard disk, the data stored on the hard disk two additional data content can be calculated in the third hard disk. This means that RAID5 storage mode allowing only one hard disk fails, needs to be replaced as soon as possible if it fails. When replacing the failed disk, the data written during the failure will be recalibrated. If the fault is not resolved and the bad one, that is, the disastrous.
  • RAID 10 (RAID 01 and no difference, is that the former do RAID 0 RAID 1 on the basis of the latter backwards over it) is a combination of RAID0 and RAID1, which provides high performance, high availability, better performance than RAID5 particularly suitable for applications written a lot, but the cost is relatively high no matter how many disks you will lose half of all disk storage. Need to complete at least four hard disks, for data A and B divided data respectively stored half, C and D respectively correspond to A and B do mirroring. As a result, there really is perfect, but also my best ideal. You do not need RAID 5 parity. Obviously, with such costs will be higher. It is also regrettable is the "short board effect" performance,

Through the above description RAID 10 will understand performance mode RAID 50, right? Not presented here.

Here is a combination of all levels of RAID performance and application scenarios:

Soft RAID configuration methods and concepts introduced

Soft RAID configuration commands --mdadm

Format:

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

The above options and parameters introduced:

  • -C --create: creation mode
  • -a --auto {yes | no}: agreed to create a device which, if not you must first create a RAID device using the mknod command this parameter, but is recommended to create a one-time parameter -a yes;
  • -l --level #: array mode, the array supported modes are linear, raid0, raid1, raid4, raid5, raid6, raid10, multipath, faulty, container;
  • -n #: # blocks using this device to create RAID (-n 3 is represented by three hard disk to create the RAID)
  • -x #: # only hot spare block (-x 1 represents only a hot spare) of the current array

Creating RAID example (with RAID 5, for example)

Requirements are as follows:

  1. Using four RAID partitions. 5, wherein as a preliminary disk partition, when the work is damaged RAID, disk preliminary top;
  2. Each partition size is 20GB;
  3. Using a partition to partition preparation;
  4. Mount / test directory use

Start the configuration:

1, create RAID 5:

[root@localhost ~]# fdisk -l | grep  磁盘      #以下就是用来做RAID 5的磁盘
                    ..........................#省略部分内容
磁盘 /dev/sdb:21.5 GB, 21474836480 字节,41943040 个扇区
磁盘标签类型:gpt
磁盘 /dev/sdc:21.5 GB, 21474836480 字节,41943040 个扇区
磁盘标签类型:gpt
磁盘 /dev/sdd:21.5 GB, 21474836480 字节,41943040 个扇区
磁盘标签类型:gpt
磁盘 /dev/sde:21.5 GB, 21474836480 字节,41943040 个扇区
磁盘标签类型:gpt
                    ..........................#省略部分内容
[root@localhost ~]# mdadm -C /dev/md0 -a yes -l 5 -n 3 -x 1 /dev/sd[b,c,d,e]
                     ........................#忽略部分提示信息
Continue creating array? y                   #输入“y”进行确认
mdadm: Defaulting to version 1.2 metadata
mdadm: array /dev/md0 started.       #/dev/md0创建成功。
[root@localhost ~]# cat /proc/mdstat       #查询刚刚创建的RAID信息
Personalities : [raid6] [raid5] [raid4] 
md0 : active raid5 sdd[4] sde[3](S) sdc[1] sdb[0]   #组成RAID的实体磁盘及其顺序
 41908224 blocks super 1.2 level 5, 512k chunk, algorithm 2 [3/3] [UUU]  
 #相关信息,chunk大小及RAID等级说明,后面的三个U代表正常,若不是U则代表有误。

unused devices: <none>

[root@localhost ~]# mdadm -D /dev/md0      #这个命令查看出来的结果更人性化写
/dev/md0:                          #RAID的设备文件名
           Version : 1.2
     Creation Time : Thu Sep  5 09:37:42 2019    #创建RAID的时间
        Raid Level : raid5      #RAID的等级,这里是RAID5
        Array Size : 41908224 (39.97 GiB 42.91 GB)    #整组RAID的可用量
     Used Dev Size : 20954112 (19.98 GiB 21.46 GB)     #每颗磁盘的可用容量
      Raid Devices : 3      #组成RAID的磁盘数量
     Total Devices : 4       #包括spare的总磁盘数
       Persistence : Superblock is persistent

       Update Time : Thu Sep  5 09:39:28 2019
             State : clean          #目前这个RAID的使用状态
    Active Devices : 3        #启动的设备数量
   Working Devices : 4       #目前使用于此RAID的设备数量
    Failed Devices : 0            #损坏的设备数量
     Spare Devices : 1      #预备磁盘的数量

            Layout : left-symmetric
        Chunk Size : 512K             #chunk的小区块容量

Consistency Policy : resync

              Name : localhost.localdomain:0  (local to host localhost.localdomain)
              UUID : d395d245:8f9294b4:3223cd47:b0bee5d8
            Events : 18
#以下是每个磁盘的使用情况,包括三个active  sync和一个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是指此RAID内的磁盘顺序

2, mount and use the format:

[root@localhost ~]# mkfs.xfs /dev/md0          #格式化刚刚创建的RAID 5
[root@localhost ~]# mkdir /test       #创建挂载点
[root@localhost ~]# mount /dev/md0 /test       #挂载
[root@localhost ~]# df -hT /test      #确认挂载,使用起来和普通文件系统没有区别
文件系统       类型  容量  已用  可用 已用% 挂载点
/dev/md0       xfs    40G   33M   40G    1% /test
#将挂载信息写入/etc/fstab中进行开机自动挂载了,设备名可以是/dev/md0,也可以是设备的UUID。
[root@localhost ~]# blkid /dev/md0     #查询该RAID 5的UUID
/dev/md0: UUID="93830b3a-69e4-4cbf-b255-f43f2ae4864b" TYPE="xfs" 
[root@localhost ~]# vim /etc/fstab   #打开/etc/fstab,写入下面内容
UUID=93830b3a-69e4-4cbf-b255-f43f2ae4864b /test xfs     defaults        0 0

3, the test RAID 5:

About test, the parameters must involve a written management RAID, as follows:

  • -f --fail: the device will be disposed behind the error state;
  • -a --add: the latter will be added to the apparatus in md;
  • -r --remove: This will be later removed from the apparatus in the md;
[root@localhost ~]# echo "hi,girl,good morning." > /test/a.txt   #写入数据
[root@localhost ~]# cat /test/a.txt     #查看
hi,girl,good morning.
[root@localhost ~]# mdadm /dev/md0 -f /dev/sdb    #将/dev/sdb损坏
mdadm: set /dev/sdb faulty in /dev/md0
[root@localhost ~]# mdadm -D /dev/md0     #查看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        #查到失败的磁盘有1个
     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       #这就是刚才损坏的磁盘
#可以发现作为预备磁盘已经顶替了损坏的磁盘了
[root@localhost ~]# df -hT /test      #可用容量还是40G
文件系统       类型  容量  已用  可用 已用% 挂载点
/dev/md0       xfs    40G   33M   40G    1% /test
root@localhost ~]# mdadm /dev/md0 -r /dev/sdb     #将损坏的磁盘移除RAID组
mdadm: hot removed /dev/sdb from /dev/md0
[root@localhost ~]# mdadm /dev/md0 -a /dev/sdf      #添加一块磁盘到RAID组
mdadm: added /dev/sdf
[root@localhost ~]# mdadm -D /dev/md0    #查看RAID组的成员状态
/dev/md0:
                       .............#省略部分内容
    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   
             #新添加的磁盘已经成为了RAID组的预备磁盘

4, the RAID disk group reset to normal

[root@localhost ~]# umount /test
[root@localhost ~]# vim /etc/fstab
                       .............#省略部分内容
UUID=93830b3a-69e4-4cbf-b255-f43f2ae4864b /test xfs     defaults        0 0             
#将设置的RAID  5自动挂载删除
[root@localhost ~]# dd if=/dev/zero of=/dev/md0 bs=1M count=50
#损坏RAID的超级区块
[root@localhost ~]# mdadm --stop /dev/md0     #停止RAID的使用
mdadm: stopped /dev/md0
#以下操作是将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         #确认下面不存在该RAID
Personalities : [raid6] [raid5] [raid4] 
unused devices: <none>

After the above operation is restored became a regular disk, but the original data are not, no in-depth study later use, you can use some of the re-testing of the command system scan or reboot the system, you can mount use, this may not mount on.

Re-testing command:

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

-------- end of this article so far, thanks for reading --------

Guess you like

Origin blog.51cto.com/14154700/2435738