Software disk array (software RAID) Introduction

Source: Internet
Author: User
Tags uuid disk usage
Introduction

RAID, English is all called: Redundant Arrays of independent Disks, Chinese translation: Independent fault-tolerant disk array, formerly known as a fault-tolerant low-cost disk array, is now generally referred to as a disk array. The thing is presented by UC Berkeley, which can be used to integrate multiple smaller hard disks into a larger disk, and also to protect data. Now the disk array is divided into: software RAID and hardware RAID, in the application if the requirements of the enterprise is relatively high, is generally used hardware RAID, because the speed of software, how can not be compared to the speed of hardware, of course, the hardware is too bad, but the general enterprise will not use the bad hardware.

Because of the limited resources here, the introduction is soft raid.first, RAID level and function1, RAID-0 (grade mode, stripe): The best first to introduce is RAID-0, this mode of RAID requires the use of at least two or more hard drives, and the hard disk model, capacity size of what the best is consistent. This level of RAID will divide each piece of disk into a small piece of the same size, equal number of chunk (size can be set on its own, usually between 4k-1m), when there are files to write to disk, the system will be divided into the size of the chunk, and then to each disk, However, this kind of storage is not a disk to save a disk, but interleaved storage, and does not store the data in a disk, as shown in the figure below:
The figure does not draw the chunk, but it can also roughly reflect the RAID-0 data storage mode. When a file is to be stored in RAID-0, the file is first cut into the same size as the chunk and then stored in a different disk. Since files are cut into small chunks stored on different disks (not on the same disk as the entire file), the storage burden of each disk is lowered and the speed of file storage is naturally improved. When the number of disks that make up the RAID-0, the faster the data is stored, the more efficient and the higher the total storage capacity will grow along with the number of disks. But this will also cause a very obvious problem, that is, although the disk data storage speed, disk capacity is also larger, but the security of the data is significantly reduced, the number of disks, the lower the security of data, because RAID-0 this mode is no data backup, At the same time the same file is sliced and there are different disks, the data becomes very fragmented, once a disk is out of the question, then all the data on the RAID-0 disk can be corrupted, the number of disks is inversely proportional to the security of the data (I don't know, the exact mathematical relationship, Just feel so good to express some. )。 In the composition of RAID-0, although it is required to ensure that the disk model, capacity, as far as possible consistency, but because the real problem is still possible to use the disk in terms of the capacity of the inconsistency, when the capacity of the disk is inconsistent, especially the smaller capacity of the disk is full, the system will automatically store the data into the larger disk, However, this will result in a decrease in storage efficiency, which should be considered clearly when used. 2, RAID-1 (mapping mode, mirror): Full backup RAID-1 The requirements of the disk and RAID-0, it is best to model, the same size of more than two disks, if the disk capacity is not the same, the system will be a small capacity of the disk capacity as a benchmark. The reason for this is related to RAID-1 data storage, RAID-1 store data on each disk, the equivalent of each disk will have a copy of the exact same data, how many pieces of disk will have the number of data, data security will be greatly improved. The RAID-1 data is stored as shown in the following figure:
As shown in the figure, when you use RAID-1 for file storage, the system automatically stores the files in two disks, that is, a disk is used as a redundant backup, and the security of the data is greatly improved. The figure uses only two disks, but you can actually use more disks to make up the RAID-1, but the data stored in these disks is exactly the same, and the damage to a piece of disk does not damage the integrity of the data, so this model is well suited to situations where data security is very demanding. RAID-1 the security of the data is really well guaranteed, but also exposes some problems, that is, the storage efficiency of data is greatly reduced, after all, our disk at the same time can only be a disk read and write operations, so the number of disks composed of RAID-1, the more Data storage efficiency is also lower, this is a very troublesome problem, after all, fish and bear cake can not be at the same time. 3, RAID-10 and RAID-01 RAID-10 and RAID-01 These two models are based on RAID-0 and RAID-1 two models of the characteristics of the combination of advantages, to a large extent can overcome the RAID-0 and RAID-1 single mode deficiencies, but in the actual use of a Use more or RAID-10 This combination mode, the reason is that this combination mode in the cost, data redundancy and data access efficiency can achieve a more ideal state, the following figure is RAID-10 This combination mode of data storage mode:
As shown above, the RAID-10 pattern is composed of RAID-1 and then RAID-0. Disk A + disk B makes up the first set of RAID 1,disk C + disk D to make up the second set of RAID-1, and then the two groups are then consolidated into a set of RAID-0. If there is 1G of data to write, then because of the RAID-0 relationship, both groups of RAID-1 will write 512MB, and because of RAID-1 relationship, so each disk will be written to 512MB. As a result, no problem occurs for any set of RAID-1 disks that are corrupted, because they are RAID-1 image data. This is also the current storage equipment manufacturers the most recommended method. 4, RAID-5: Efficiency and data backup balance considerations to make a RAID-5, you need at least three disks. This type of disk array is written in a manner similar to RAID-0, unlike RAID-0, where each loop is written (striping), a data check is written to each disk, and the data of this checksum records the data that is written to the disk, Can be used for recovery of disk data when other disks are damaged. The specific reading and writing situation is shown in the following figure:
As shown in the figure above, RAID-5 in the data storage with the RAID-0 way is a bit similar, the difference is that the RAID-5 more than a data verification of the part (record the data at the same time, can be called: the same parity check code), the same parity code with every disk storage, The storage location will be different, scattered in each disk, can reduce the probability of data corruption, in case of damage to the disk, by the non-damaged disk data and this data check the portion of the calculation, you can recover the lost data, the data security is much better than RAID-0. RAID-5 on the disk read performance and RAID-0 not much difference, but in the same hardware environment, write performance on the RAID-5 than RAID-0 may be almost. Because in writing, RAID-5 to calculate the same as the check code, in this calculation, it will occupy the computing resources of the computer, and RAID-0 because there is no parity check code, so there is no need to calculate this step, the efficiency will be slightly higher than the RAID-5 (the key to see the hardware environment). Read without these operations, so the reading performance is not very different. There is also a RAID-6 pattern, similar to RAID-5, are all through the same parity check code to ensure the security of the data, the difference is that the RAID-6 is two parity check code, and the verification code is stored in the same way as RAID-5, are distributed storage. The good thing about this mode is that the RAID-6 allows two disks in the system to be damaged at the same time, still ensuring that the data can be restored (because there are two redundancy checks), and RAID-5 can only damage one disk at a time. 5, Spare Disk: The function of the preparation of disks Spare can also be called hot spares, it is the role of disk array in the disk damage, the system will automatically enable the hot spare, and automatically rebuild the disk array damaged disk data, this will be the advantage of hot spare. A hot spare can have a piece, or it can have multiple pieces. Of course, to use a hot spare, the first disk array to support the function of the hot spare, while the hardware system is best to support hot-plug, otherwise you have to manually remove the damaged disk, and then manually install the new disk, and manually installed to the shutdown. 6, the advantages of the disk array the application of the disk array is mainly to consider the following points: Data security and reliability: Refers to the security of the network data, but when the disk is damaged, whether the data can be safe to rescue or use it; Capacity: Multiple disks can be combined, so a single file system can have considerable capacity. The key is to ensure that the reliability and security of the data (integrity) is the focus of RAID use, after all, in the enterprise data is very important, in daily life is generally not used in this need. The following table provides several raidThe respective characteristics of the level: (n is assumed to have n blocks of disk composition)

Project RAID-0 RAID-1 RAID-10 RAID-5 RAID-6
Minimum number of disks 2 2 4 3 4
Maximum number of fault-tolerant disks No N-1 N/2 1 2
Data security Not at all. Best Best Good Better than RAID-5.
Theoretical writing efficiency N 1 N/2
Theoretical readout efficiency N N N N
Actual amount of disk usage N 1 N/2 N-1 N-2
General application An environment that emphasizes efficiency but does not require high data importance Data storage and Backup Common in server and cloud systems Data storage and Backup Data storage and Backup

Note: because RAID-5 and RAID-6 read and write both need to go through the parity computer system, so read/write performance will not just be satisfied with the number of disks used.
In addition, depending on the use of the situation, generally recommended disk array level is not the same, you need to choose according to their own environment. second, software RAID and hardware RAID also mentioned before raid is divided into software RAID and hardware RAID, the following will describe what is software RAID, what is hardware RAID, and what is the difference between the two. A hardware disk array (HARDWARERAID) is a disk array created from a disk array. On the disk array card will have a special chip to handle the RAID task, can greatly reduce the original system's computational pressure and I/O pressure, the efficiency will be improved, and now a significant portion of the disk array cards are supported hot-swappable, so it is very convenient to replace the damaged disk. But the bad thing is that the disk array card is more expensive, especially those with a better disk array card will be particularly expensive, and the function is not guaranteed to be particularly complete, so in this case there is software RAID to simulate hardware RAID. Soft drop raid is a kind of simulation hardware RAID product, is to run on the system above, is to occupy a certain system resources, especially computing and I/O resources, so in terms of efficiency compared with the hardware RAID there is still a considerable gap. Although the current machine computing speed is very fast, but for some of the more demanding scenarios or enterprises, it is generally best to try not to choose software RAID, after all, the total cost of use of hardware RAID is a good deal. three, software disk array settings

The CentOS7 system used in this experiment environment, the system installed with the official original image is built-in Mdadm software to implement the disk array setup. This software is supported partition or disk for the unit, so we can be for the partition (partition) disk array design, while the Mdadm software is very powerful, it can not only support the above described in the RAID mode, Moreover, it can simulate the function of hot-plug, which can be changed directly when the system is in normal use.

in practice, the hardware disk array in Linux is a whole block of actual disk size, so the device name displayed in the system is also according to/dev/sd[a-z], and software RAID is simulated by the system, not actually exist, So the device name shown in the system is/dev/md0,/dev/md1 .... The two are different on the device name.
1. Introduction of software RAID instructions
The setup of the software RAID is simple, just one instruction, but this directive is similar to the XFS_QUOTA directive that sets quota in CentOS7, which is followed by a number of optional options. Instruction format: mdadm–create/dev/md[0-9]–auto=yes–level=[015]–chunk =NK–RAID-DEVICES=N–SPARE-DEVICES=N/DEV/SDX/DEV/HDX ...

Common options and Parameters:

option Description
–create Create a disk array (RAID)
–auto Set up the following software disk array (RAID) devices, such as/dev/md0,/dev/md1 ...
–chunk Set the chunk size of the device, or it can be as stripe size, usually 64K or 512K
–raid-devices Set the number of disks that make up the disk array (RAID)
–spare-devices Set the number of hot spares
–level Set the level of disk array (RAID), generally recommended 0,1,5
–detail Display details of the followed-up disk array (RAID)

2. Create a disk array:
MDADM–CREATE/DEV/MD0–AUTO=YES–LEVEL=5–CHUNK=256K–RAID-DEVICES=4–SPARE-DEVICES=1/DEV/SDC {1,2,3,4,5}

Following the instructions in the previous figure, a device name of/dev/md0, the level: RAID-5 level, a chunk size of 256K, a disk array consisting of four disks and a single hot spare, will be created. It is important to note that the number of disks that comprise the raid and the number of hot spares must be equal to the number of disk devices that follow. 3. View the information for creating raid: mdadm–detail/dev/md0

As shown in the figure, the disk array md0 is composed of partitions/dev/sdc1,/DEV/SDC2,/DEV/SDC3,/DEV/SDC4, and/DEV/SDC5 is set up as a hot spare. If the creation of no error, but the use of this instruction can not be queried, it is possible to wait a few minutes before using this command query, because when the system is created, it takes time to create, create a bit slower, it may not be found when the search.

The cat/proc/mdstat in the image above can be used to view the files of the system software disk array to see the status of the software disk array in the system: the first line of the above callout: indicates that md0 is RAID-5, and that the disk is composed of: SDC4,SDC3,SDC2,SDC1 four disks ; The brackets after each disk device name indicate that the disk is in the disk array, and the "S" in the parentheses behind the SDC5 indicates that the device is a hot spare.
The second line means: This disk array has 3,142,656 blocks, using the raid-5,chunk size of 256K, using the algorithm 2 disk array algorithm. The first "4" in the following [4/4] means that the disk array device requires 4 disk devices, and the latter "4" indicates that 4 disks in the disk array are functioning properly. The last side of [UUUU] represents the boot of the four disks required for the disk array, "U" stands for normal operation, and if "_" represents a non-normal condition. 4, the RAID format and mount use:

The format parameter in the image above means: su: Indicates that the chunk size is 256K; SW: Indicates the number of formatted disks, set to 3, so the format of three disk, so DF query out the size of 3GB; Extsize: Represents the data width computed by the above two items: 256k*3=768k. iv. Rescue mode for simulating raid errors

This rescue mode is mainly used for devices in the disk array in the event of an accident, in some cases, the rescue mode is supported online use.
instruction Format: mdadm–manage/dev/md[0-9] [–add device] [–remove device] [–fail device]
option Description
–add Add the device you followed to the raid
–remove Remove the device you followed from the raid
–fail Set the following device to an error state

1) Set the status of the disk to an error state:

2) Views: mdadm–detail/dev/md0

3) Remove the faulty device and add a new device:

4) Views: mdadm–detail/dev/md0
Note: The above operations are completed online Five, boot automatically start raid and automatically mount

Now the new system release version will automatically search for/dev/md[0-9 at boot time], and turn on the pre-set function, although, it is recommended to modify the settings in the configuration file, or it will automatically turn on the mount when booting, but the system is random, it may not be easy for us to manage.

The modifications are simple, and only two configuration files can be modified. One is to modify the/etc/fstab file, which is set to automatically mount the boot configuration file, and the other is to modify the/etc/mdadm.conf, this is the software RAID configuration file.
1) query md0 's UUID ID and UUID number:
2) Modify/etc/fstab: (the file is added with the UUID number)
3) Modify/etc/mdadm.conf: (the file is added to the UUID ID)
4) View:
Vi. shutting down software RAID
Since this experiment was done on a disk partition, in order to avoid trouble in the future I will be in the partition, so the previous set of software RAID shut down.

Here are the steps to close:
1) First remove the RAID device: Umount/srv/raid;
2) Remove the line from the/etc/fstab file about the RAID device;
3) The metadata block covering the raid device and the Superblock:dd If=/dev/zero of=/dev/md0 bs=1m count=50;
4) Close the RAID device: mdadm–stop/dev/md0;
5) RAID-related data for each disk that will comprise the raid device: DD If=/dev/zero of=/dev/sdc{1..5} bs=1m count=10
6) Delete or comment out the line of data about the RAID device in the/etc/mdadm.conf file
7) Views: Cat/proc/mdstat

Note: The DD instruction above is to overwrite all information about the RAID device on the disk, and if it is not overwritten, the system will automatically set up the RAID device when it is turned on, and the name is randomly assigned.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.