Detailed explanation of Linux RAID

linux technology stack

Basic concepts of RAID

磁盘阵列(Redundant Arrays of Independent Disks,RAID), meaning "an array of independent disks with redundant capabilities". Simply put, RAID is a disk subsystem composed of multiple independent high-performance disk drives, thereby providing higher storage performance and data redundancy technology than a single disk.

The original intention of RAID was to provide high-end storage capabilities and redundant data security for large servers. In the entire system, RAID it is regarded as a storage space composed of two or more disks. It improves the  I/O performance of the storage system by reading and writing data on multiple disks concurrently. Most RAID levels have complete data verification and corrective measures to improve the fault tolerance of the system, and even mirroring methods greatly enhance the reliability of the system, which is where Redundant comes from.

RAID0It has the advantages of low cost, high read and write performance, and 100% high storage space utilization, but it does not provide data redundancy protection. Once the data is damaged, it cannot be recovered.

RAID1Called mirroring, it writes data to the working disk and the mirror disk completely and consistently, and its disk space utilization is 50%.

RAID5 It should be the most common RAID level at present. RAID5 takes into account various factors such as storage performance, data security and storage cost. It can be understood as a compromise between RAID0 and RAID1, and is currently the data protection solution with the best comprehensive performance. RAID5 can basically meet the needs of most storage applications, and most data centers use it as a protection solution for application data.

RAID6 Level is a RAID method designed to further enhance data protection based on RAID5. It can be regarded as an extended RAID5 level. RAID6 has fast read performance and higher fault tolerance. However, its cost is much higher than RAID5, its write performance is poor, and its design and implementation are very complex. Therefore, RAID6 is rarely used in practice and is mainly used in situations that require very high data security levels. It is generally an economical alternative to RAID10 solutions.

Soft RAID

软 RAID There are no dedicated control chips and I/O chips, and all RAID functions are completely implemented by the operating system and CPU. Modern operating systems basically provide soft RAID support by adding a software layer on top of the disk device driver to provide a layer of abstraction between physical drives and logical drives. Currently, the most common RAID levels supported by the operating system are  RAID0RAID1 ,  RAID10 , ,  RAID01 and  RAID5 etc. For example, Windows Server supports three levels of RAID0, RAID1 and RAID5, Linux supports RAID0, RAID1, RAID4, RAID5, RAID6, etc., and operating systems such as Mac OS X Server, FreeBSD, NetBSD, OpenBSD, and Solaris also support corresponding RAID levels.

The configuration management and data recovery of software RAID are relatively simple, but the processing of all RAID tasks is completely completed by the CPU, such as calculating the check value, so the execution efficiency is relatively low. This method requires a large amount of computing resources and supports RAID mode. Few, it is difficult to apply widely.

Soft RAID is implemented by the operating system, so the partition where the system is located cannot be used as a logical member disk of RAID, and soft RAID cannot protect system disk D. For some operating systems, RAID configuration information is saved in the system information instead of being saved as a separate file on the disk. This way when the system crashes unexpectedly and needs to be reinstalled, the RAID information will be lost. In addition, the fault-tolerant technology of disks does not mean that it fully supports online replacement, hot plugging or hot swapping. Whether it can support hot swapping of faulty disks is related to the implementation of the operating system, and some operating systems do hot swapping.

Hard RAID

RAIDIt has its own RAID control processing and I/O processing chips, and even array buffers. The CPU occupancy rate and overall performance are the best among the three types of implementations, but the implementation cost is also the highest. Hard RAID usually supports hot swap technology to replace failed disks while the system is running.

Hard RAID includes a RAID card and a RAID chip integrated on the motherboard. Server platforms mostly use RAID cards. The RAID card consists of 4 parts: RAID core processing chip (CPU on the RAID card), ports, cache and battery. Among them, port refers to the disk interface type supported by the RAID card, such as  IDE/ATA, SCSI , SATA , SAS , FC and other interfaces.

Soft and hard mixed RAID

Software RAID has poor performance and cannot protect system partitions, making it difficult to apply to desktop systems. Hard RAID is very expensive, and different RAIDs are independent of each other and are not interoperable. Therefore, people adopt a combination of software and hardware to implement RAID, thereby obtaining a compromise between performance and cost, that is, a higher cost performance.

Although this kind of RAID uses a processing control chip, in order to save costs, the chip is often relatively cheap and has weak processing capabilities. Most of the RAID task processing is still completed by the CPU through the firmware driver.

Linux configuration RAID

There is a md(multiple devices)module in the Linux kernel that manages RAID devices at the bottom level. It will provide us with an application tool at the application layer mdadm. mdadm is the command used to create and manage software RAID under Linux. Explanation of common parameters of mdadm command:

Add hard drive in VMware

Check the added hard disk in the /dev directory. The naming rule of the hard disk is sd{az} as the number.

Create RAID0

[root@yxb ~]# mdadm -Ds
-D  打印阵列设备详细信息 s  得到阵列缺失信息
ARRAY /dev/md0 metadata=1.2 name=yxb:0 UUID=7445f1d4:ea900c41:13dbf238:1f64b93f

View RAIDdevice details

[root@yxb ~]# mdadm -D /dev/md0
/dev/md0:
           Version : 1.2
     Creation Time : Mon Jul 19 14:40:06 2021
        Raid Level : raid0
        Array Size : 10477568 (9.99 GiB 10.73 GB)
      Raid Devices : 2
     Total Devices : 2
       Persistence : Superblock is persistent

       Update Time : Mon Jul 19 14:40:06 2021
             State : clean 
    Active Devices : 2
   Working Devices : 2
    Failed Devices : 0
     Spare Devices : 0

        Chunk Size : 512K

Consistency Policy : none

              Name : yxb:0  (local to host yxb)
              UUID : 7445f1d4:ea900c41:13dbf238:1f64b93f
            Events : 0

    Number   Major   Minor   RaidDevice State
       0       8       16        0      active sync   /dev/sdb
       1       8       32        1      active sync   /dev/sdc

[root@yxb ~]# cat /proc/mdstat  #从内存中查看,重启后,信息丢失,所以要保存
Personalities : [raid0] 
md0 : active raid0 sdc[1] sdb[0]
      10477568 blocks super 1.2 512k chunks
      
unused devices: <none>

[root@yxb ~]# mdadm -Dsv > /etc/mdadm.conf  #保存配置信息

RAID0Create and mount the file system created

Automatically mount on boot

[root@yxb ~]# blkid /dev/md0
/dev/md0: UUID="db925633-9e54-48ef-ad63-5c49f05faada" TYPE="xfs" 
[root@yxb ~]# echo "UUID=db925633-9e54-48ef-ad63-5c49f05faada /raid0 xfs defaults 0 0" >> /etc/fstab 

Create RAID1

-C create -v details -l array level -n number of array members -x number of array spare disks Save RAID information to the configuration file

Simulate hard drive failure

[root@yxb ~]# mdadm /dev/md1 -f /dev/sde mdadm: set /dev/sde faulty in /dev/md1

Spare rebuilding hot standby rebuilding, that is, sdd will synchronize its data to sdfrebuild Status: 13% complete synchronization status (the files in md1 are still in normal use at this time, because sdd is working)

Remove damaged hard drive

[root@yxb ~]# mdadm -r /dev/md1 /dev/sde mdadm: hot removed /dev/sde from /dev/md1

There is no hot spare disk anymore. Add a new hot spare disk.

[root@yxb ~]# mdadm -a /dev/md1 /dev/sde
mdadm: added /dev/sde

Create RAID5

Expand the RAID5 disk array and add the hot spare disk to md5. The number of disks that can be used in md5 is 4.

[root@yxb ~]# mdadm -G /dev/md5 -n 4 -c 32

The array can only be expanded when it is in a normal state. Expansion is not allowed during downgrading and reconstruction. For raid5, member disks can only be added, not reduced. For raid1, member disks can be added or reduced.

Stop MD5 array

[root@yxb ~]# mdadm -Dsv > /etc/mdadm.conf #停止前,一定要先保存配置文件
[root@yxb ~]# mdadm -S /dev/md5 #-S  停止阵列
mdadm: stopped /dev/md5

Activate MD5 array

[root@yxb ~]# mdadm -As  #-A 激活磁盘阵列 s 扫描配置文件得到阵列信息
mdadm: /dev/md5 has been started with 4 drives.

Delete RAID

[root@yxb ~]# umount /dev/md0 /raid0 #如果你已经挂载 raid,就先卸载。

[root@yxb ~]# mdadm -Ss #停止 raid  设备
[root@yxb ~]# rm -rf /etc/mdadm.conf #删除 raid  配置文件
[root@yxb ~]# mdadm --zero-superblock /dev/sdb #清除物理磁盘中的 raid 标识
[root@yxb ~]# mdadm --zero-superblock /dev/sdc #清除物理磁盘中的 raid 标识
[root@yxb ~]# mdadm -Dsv #清除物理磁盘中的 raid 标识

recommend:

C/C++Linux server development/senior architect systematic learning address
Finally, friends are welcome to join the C/C++Linux learning exchange group: 960994558
The group provides free C/C++Linux server development/senior architect learning Information includes C/C++, Linux, golang technology, Nginx, ZeroMQ, MySQL, Redis, fastdfs, MongoDB, ZK, streaming media, CDN, P2P, K8S, Docker, TCP/IP, coroutine, DPDK, ffmpeg, etc.)

Guess you like

Origin blog.csdn.net/qq_41819851/article/details/131106294