The Redundant Array of Independent Disks (RAID) was proposed by the University of California, Berkeley in 1987. It is a logical virtual hard disk consisting of multiple hard disks. There is no difference between operations and operations on a single hard disk. However, data is stored on different hard disks.
Benefits of Disk Arrays
Integrate multiple hard disks: You can integrate multiple small hard disks into one large hard disk.
Data has high security: the disk array has the ability to modify errors. It places the check code (parity) on different hard disks. When Data fails, the check code is used to restore the original data.
Improve access efficiency: when data is written, it is cut into multiple small blocks and written in Different Hard disks. In this way, data can be read from different physical hard disks, this accelerates disk I/O.
Disk Array category
Linux disk arrays are divided into seven types based on the storage location of files.
Linear: data is first stored on the first hard disk. When the disk space is used up, the data is stored to the second, second, and second disks ........ Hard disks. When data or hard disk fails, this mode is not fault tolerant.
Raid-0: When writing data, the data is cut into many small blocks and the data of these blocks is stored separately on each hard disk. Unlike linear, raid distributes data evenly to different hard disks. Therefore, it is not fault tolerant.
Raid-1: In this mode, data is stored on each hard disk, and the data on each hard disk is the same.
Raid-2: Data is separated by bit and stored separately on each hard disk. However, this method retains several additional hard disks ., When data is written, the disk array synchronizes the verification code stored on each hard disk, and then stores the verification code on the retained hard disk. When a hard disk is damaged, you can use this verification code to restore correct data for Fault Tolerance purposes.
Raid-3: each data part is separated by byte and stored in each hard disk. In this way, a fixed parity code is reserved for hard disk storage. However, because the same-bit verification code is stored in the same hard disk, the hard disk should have a fast transmission speed. Otherwise, the system performance will be affected.
Raid-4: A piece of data is cut into a fixed block and stored in each Hard Disk separately. Compared with raid-3, this method has the same fault tolerance function in addition to different partitioning methods.
Raid-5: A piece of data is divided into fixed blocks and stored in each Hard Disk separately. Although this method is the same as RAID-4, data is separated by blocks. The difference is that raid-5 does not reserve a Fixed hard disk to store verification codes, instead, the verification code is stored in all hard disks. Therefore, this method does not affect the system performance because the verification code is stored on a hard disk.
4. Disk Arrays supported by Linux
Currently, Linux supports five disk array modes: linear, raid-0, raid-1, raid-4, and raid-5. In five modes, raid-4 and raid-5 run in similar ways. Next, we will introduce how to create a linear, raid-1, and raid-5 disk array.
1. Create a linear disk array
Hardware requirement: Two or more hard disks.
Create a linear disk array:
Set the file to/etc/raidtab.
The file format is as follows:
Raiddev/dev/md0 specifies the device name of the disk array
Raid-Level Linear specifies that the linear mode is used.
NR-raid-Disks 2 this disk array consists of two hard disks
Chunk-size 32 size of each written block when data is written to the disk array
(Unit: kb, and must be the power of 2 ). Because
In this mode, data is written in sequence instead of in blocks.
One disk.
Persistent-superblock 1: Set whether to write the superblock to the disk and set it to "1"
Indicates writing. If "0" is set, no writing is performed.
Device/dev/sda2 specify the name of the first hard disk partition according to the actual situation
Raid-disk 0 is the first partition used by the secondary disk array.
Hard Disk. Start with "0.
Device/dev/sdb1 specifies the name of the second hard disk partition according to the actual situation.
Raid-Disk 1 is set to the second partition used by the disk array.
Hard Disk.
After creating the setting file, run the following command to initialize the newly created/dev/md0 disk array.
# Mkraid/dev/MDO
# Mke2fs? J/dev/md0 format disk array
# Mount? T ext3/dev/md0 MNT/md0 load md0 to/mnt/md0.
Check the disk array status record file to stop and start the disk array.
Stop disk array: First unload the mounted disk array
# Umount/dev/md0
# Raidstop/dev/md0
Start the disk array:
# Raidstart/dev/md0
View the disk array Usage Status:
# More/proc/mdstat
Personalities: [linear]
Read_head 1024 sectors
Md0: active linear sda2 (1) SDB (0)
20483524 blocks 32 K rounding
Unused devices:
The preceding status indicates the information related to the running status of the disk array. When the disk array is not in the startup status, the following status is displayed:
Personalities: [linear]
Read_ahead 1024 sectors
Unused devices:
Delete a disk array: First stop the disk array, and then delete the/etc/raidtab file.
2. Create a raid-1 Disk Array
The raid-1 Disk Array Storage Method writes the same copy of data to each hard disk at the same time, and the data stored on that hard disk is identical.
Hardware requirements: to create a raid-1 disk array, at least two hard disks are required. The optimal size of each hard disk is the same. This is because each Hard Disk stores the same data, so there is a hard disk larger than other capacity, the disk is hard to use the extra hard disk space.
Create a disk array: In this example, two hard disk partitions, sda1 and sdb1, are used to create a disk array. The content of the/etc/raidtab is as follows.
Raiddev/dev/md0 specifies the device name of the disk array
Raid-Level 1 specifies the raid-1 mode.
NR-raid-Disks 2 this disk array consists of two hard disks
NR-Spare-Disks 0 disk array backup disk count
Chunk-size 4 size of each write block when data is written to the disk array
(Unit: kb, and must be the power of 2 ). Because
In this mode, data is written in sequence instead of in blocks.
One disk.
Persistent-superblock 1: Set whether to write the superblock to the disk and set it to "1"
Indicates writing. If "0" is set, no writing is performed.
Device/dev/sda1 specifies the name of the first hard disk partition according to the actual situation.
Raid-disk 0 is the first partition used by the secondary disk array.
Hard Disk. Start with "0.
Device/dev/sdb1 specifies the name of the second hard disk partition according to the actual situation.
Raid-Disk 1 settings
After the setting file is created, the methods for creating a file system, starting, and viewing the running status are the same as those for linear.
3. Create a raid-5 disk array
Here we will introduce raid-5, which serves to strike a balance between raid-0 and raid-1. It also has fault tolerance capabilities and does not waste too much hard disk space, it also helps improve disk I/O performance.
Hardware requirements:
Because raid-5 requires the same-digit Verification Code, at least three or more hard disks are required to create a disk array in this mode.
Create a disk array: In this example, sda1, sdb1, and sdc1 are used as three partitions to form a raid-5 disk. The following is the setting file/etc/raidtab.
Raiddev/dev/md0 specifies the device name of the disk array
Raid-Level 5 uses the linear mode
NR-raid-Disks 3 this disk array consists of two hard disks
NR-Spare-Disks 0 disk array backup disk count
Chunk-size 32 size of each written block when data is written to the disk array
(Unit: kb, and must be the power of 2 ). Because
In this mode, data is written in sequence instead of in blocks.
One disk.
Persistent-superblock 1: Set whether to write the superblock to the disk and set it to "1"
Indicates writing. If "0" is set, no writing is performed.
Parity-algorithm left-distance Ric specifies which one to use Algorithm Calculation of the same-bit verification code, but the algorithms used are: Left-semi Ric, left-asypolicric, right-semi Ric, right-asymmetric4. Left-semi Ric is generally used for optimal storage efficiency.
Device/dev/sda1 specifies the name of the first hard disk partition according to the actual situation.
Raid-disk 0 is the first partition used by the secondary disk array.
Hard Disk. Start with "0.
Device/dev/sdb1 specifies the name of the second hard disk partition according to the actual situation.
Raid-Disk 1 settings
Device/dev/sdb1 specifies the name of the third hard disk partition according to the actual situation.
Raid-Disk 2 Settings
After the modification is completed, create a disk array, start, stop, and view the status.
In this chapter, we will only introduce raid-linear, raid-1, raid-5, and the most common disk array settings.
The setting method for other types of disk arrays is similar to the setting method described above.
Finally, let's compare the above three disk arrays.
Disk Array comparison:
Disk Space: The linear mode saves the most disk space. The total disk space of the disk array is the sum of all hard disks.
Raid-1 (disk image) is the most wasteful disk because the data stored on each hard disk is the same.
Raid-5 uses a disk to store the same-bit verification code. Therefore, the disk capacity is n-1.
Disk capacity.
Read/write performance: in linear mode, since data is stored on the hard disk in sequence, this mode runs with a hard disk.
There is no difference. This mode does not increase the read/write efficiency. If multiple people put data
It can be stored on different hard disks and accessed at the same time to improve disk read/write efficiency.
Raid-1 because each Hard Disk stores the same data, it takes a lot of CPU time.
The write count is affected. Since data can be read from different hard disks, theoretically there will be a fast number. In raid-5 mode, because data is read and written into blocks, data is stored in a single-bit synchronous disk in blocks, which significantly improves the access speed. The theoretical speed is n-1, but the actual transmission efficiency is not that high.
Fault Tolerance: The linear disk array does not have all fault tolerance capabilities. If one of the hard disks fails, the data of the entire disk array will be lost. Raid-1 has a very good fault tolerance capability, because the data on each hard disk is the same, so when a hard disk fails. The system can continue to work. Raid-5 disk array. When one of the hard disks fails, you can use other hard disks to calculate the correct data. If two or more hard disks are faulty at the same time, this is the same-bit verification code, and it is not enough to restore the data, which means the data cannot be saved.
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.