In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article will explain in detail what is the implementation principle of disk management soft RAID in linux. The editor thinks it is very practical, so I share it with you for reference. I hope you can get something after reading this article.
1 what is RAID
The full name of RAID is redundant Array of Independent disks (Redundant Array of Independent Disks). The basic idea is to combine multiple disks into a disk array group to greatly improve the performance.
RAID is divided into several different levels, each of which makes different tradeoffs between data reliability and read-write performance. In the actual work, choose different RAID schemes according to your own business needs.
2 the implementation of RAID
External disk array: provide adaptive capability through expansion card inline RAID: motherboard integrated RAID controller configure software in BIOS before installing OS RAID: realized through OS
3 standard RAID
3.1 RAID0
RAID0 is called striped storage, which stores data in segments in each disk, and reads and writes can be processed in parallel, so the read and write rate is N times that of a single disk. Without redundancy, the data will be unavailable due to the damage of any disk.
3.2 RAID1
RADI1 is mirrored storage, there is no data check, data is equally written to 2 or more disks, the write speed is relatively slow, but the read speed is relatively fast.
3.3 RAID 4
RADI4 on the basis of RAID1, N disks are used for data storage, and another disk is added as a check disk. There is a total of 1 disk, and any broken disk will not affect the data access.
3.4 RAID 5
RAID5 on the basis of RAID4, from the original disk to store verification data, to each disk has data and verification information.
4 mixed RAID
4.1 RAID01
First compose RAID0, then compose RAID1.
4.2 RAID10
First form RAID1, then form RAID0
5 implementation of soft RAID
5.1the implementation of RAID5
Create a RAID5 device with 2G free space composed of three hard drives, which requires a chunk size of 256k, a file system of ext4, and can be automatically mounted to the / mydata directory when booted.
5.1.1 take a look at our disk first.
[root@centos7 Bash] $lsblkNAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTsda 8:0 0 200G 0 disk ├─ sda1 8:1 0 1G 0 part / boot ├─ sda2 8:2 0 128G 0 part ├─ sda3 8:3 0 48.8G 0 part / ├─ sda4 8:4 0512B 0 part └─ sda5 8:5 019.5G 0 part / appsdb 8:16 0100G 0 disk sdc 8:32 020G 0 disk sdd 8:48 020G 0 disk sde 8:64 020G 0disk sdf 8Rol 800 020G 0 Disk sr0 11:0 1 8.1G 0 rom / run/media/root/CentOS 7 x86_64
Here we use sdb,sdc,sdd to create a primary partition of 1G per disk and build RADI5.
5.1.2 Partition according to actual situation
[root@centos7 Bash] $fdisk / dev/sdbWelcome to fdisk (util-linux 2.23.2). Changes will remain in memory only, until you decide to write them.Be careful before using the write command.Device does not contain a recognized partition tableBuilding a new DOS disklabel with disk identifier 0x93d380cf.Command (m for help): nPartition type: P primary (0 primary, 0 extended, 4 free) e extendedSelect (default p): pPartition number (1-4, default 1): First sector (2048-209715199, default 2048): Using default value 2048Last sector, + sectors or + size {KMagm G} (2048-209715199, default 209715199): + 1GPartition 1 of type Linux and of size 1 GiB is setCommand (m for help): tSelected partition 1Hex code (type L to list all codes): fdChanged type of partition 'Linux' to' Linux raid autodetect'Command (m for help): pDisk / dev/sdb: 107.4 GB, 107374182400 bytes 209715200 sectorsUnits = sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk label type: dosDisk identifier: 0x93d380cf Device Boot Start End Blocks Id System/dev/sdb1 2048 2099199 1048576 fd Linux raid autodetectCommand (m for help): wThe partition table has been altered calling ioctl () to re-read partition table.Syncing disks. [root@centos7 Bash] $fdisk / dev/sdcWelcome to fdisk (util-linux 2.23.2). Changes will remain in memory only Until you decide to write them.Be careful before using the write command.Device does not contain a recognized partition tableBuilding a new DOS disklabel with disk identifier 0xc56b90d8.Command (m for help): nPartition type: P primary (0 primary, 0 extended, 4 free) e extendedSelect (default p): pPartition number (1-4, default 1): First sector (2048-41943039, default 2048): Using default value 2048Last sector, + sectors or + size {KMagol M Magee G} (2048-41943039) Default 41943039): + 1GPartition 1 of type Linux and of size 1 GiB is setCommand (m for help): tSelected partition 1Hex code (type L to list all codes): fdChanged type of partition 'Linux' to' Linux raid autodetect'Command (m for help): pDisk / dev/sdc: 21.5GB, 21474836480 bytes 41943040 sectorsUnits = sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk label type: dosDisk identifier: 0xc56b90d8 Device Boot Start End Blocks Id System/dev/sdc1 2048 2099199 1048576 fd Linux raid autodetectCommand (m for help): wThe partition table has been altered calling ioctl () to re-read partition table.Syncing disks. [root@centos7 Bash] $fdisk / dev/sddWelcome to fdisk (util-linux 2.23.2). Changes will remain in memory only Until you decide to write them.Be careful before using the write command.Device does not contain a recognized partition tableBuilding a new DOS disklabel with disk identifier 0x7e0900d8.Command (m for help): nPartition type: P primary (0 primary, 0 extended, 4 free) e extendedSelect (default p): pPartition number (1-4, default 1): First sector (2048-41943039, default 2048): Using default value 2048Last sector, + sectors or + size {KMagol M Magee G} (2048-41943039) Default 41943039): + 1GPartition 1 of type Linux and of size 1 GiB is setCommand (m for help): pDisk / dev/sdd: 21.5GB, 21474836480 bytes 41943040 sectorsUnits = sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk label type: dosDisk identifier: 0x7e0900d8 Device Boot Start End Blocks Id System/dev/sdd1 2048 2099199 1048576 83 LinuxCommand (m for help): tSelected partition 1Hex code (type L to list all codes): fdChanged type of partition 'Linux' to' Linux raid autodetect'Command (m for help): wThe partition table has been altered calling ioctl () to re-read partition table.Syncing disks.
5.1.3 create raid
[root@centos7 Bash] $mdadm-C / dev/md5-a yes-l 5-n 3 / dev/sd {b1 chunk C1 authoring D1}-c 256 #-C specifies creation,-a yes automatically creates devices,-l sets level,-n sets the number of disks,-c chunk size Continue creating array? Ymdadm: Defaulting to version 1.2metadatamdadm: array / dev/md5 started. [root@centos7 Bash] $mdadm-Ds # View information ARRAY / dev/md5 metadata=1.2 name=centos7.magedu.com:5 UUID=2c8ae60d:a799fcb7:9008a046:ae6ea430 [root@centos7 Bash] $mdadm-Ds > / etc/mdadm.conf # write soft raid information to the configuration file to [root@centos7 Bash] $mkdir / mnt/md5 # create a mount point directory [root@centos7 Bash] $mkfs.ext4 / dev/md5 # create file system mke2fs 1.42.9 (28-Dec-2013) Filesystem label=OS type: LinuxBlock size=4096 (log=2) Fragment size=4096 (log=2) Stride=64 blocks Stripe width=128 blocks131072 inodes, 523776 blocks26188 blocks (5.00%) reserved for the super userFirst data block=0Maximum filesystem blocks=53687091216 block groups32768 blocks per group, 32768 fragments per group8192 inodes per groupSuperblock backups stored on blocks: 32768,98304,163840,229376, 294912Allocating group tables: doneWriting inode tables: done Creating journal (8192 blocks): doneWriting superblocks and filesystem accounting information: done [root@centos7 Bash] $mount / dev/md5 / mnt/md5 # Mount device [root@centos7 Bash] $tail-n 1 / etc/mtab/dev/md5 / mnt/md5 ext4 rw,seclabel,relatime Stripe=128,data=ordered 0 0 # View mount information [root@centos7 Bash] $tail-n 1 / etc/mtab > > / etc/fstab # add to the fstab file Make sure the boot starts. Uuid is recommended here.
5.1.4 verify raid
[root@centos7 md5] $mdadm-D / dev/md5 # View detailed raid5 details You can find three / dev/md5:Version: 1.2Creation Time: Wed Dec 6 19:28:22 2017Raid Level: raid5Array Size: 2095104 (2046.00 MiB 2145.39 MB) Used Dev Size: 1047552 (1023.00 MiB 1072.69 MB) Raid Devices: 3Total Devices: 3Persistence: Superblock is persistentUpdate Time: Wed Dec 6 19:39:06 2017State: clean Active Devices: 3Working Devices: 3Failed Devices: 0Spare Devices: 0Layout: left-symmetricChunk Size: 256KConsistency Policy: resyncName: centos7.magedu.com:5 (local to host centos7.magedu.com) UUID: 2c8ae60d:a799fcb7:9008a046:ae6ea430Events: 18Number Major Minor RaidDevice State 08 17 0 active sync / dev/sdb1 18 33 1 active sync / dev/sdc1 3 8 49 2 active sync / dev/sdd1 [root@centos7 md5] $man mdadm [root@centos7 md5] $mdadm / dev/md5-f / dev/sdc1 #-f sets specified equipment failure Failed to mark the / dev/sdc1 disk to see if the data can be accessed. I failed to use the-f mark here. During the work, you can judge the disk status according to the hard disk indicator mdadm: set / dev/sdc1 faulty in / dev/md5 [root@centos7 md5] $mdadm-D / dev/md5 # check the information this time, and find that two are working. A failed device / dev/md5:Version: 1.2Creation Time: Wed Dec 6 19:28:22 2017Raid Level: raid5Array Size: 2095104 (2046.00 MiB 2145.39 MB) Used Dev Size: 1047552 (1023.00 MiB 1072.69 MB) Raid Devices: 3Total Devices: 3Persistence: Superblock is persistentUpdate Time: Wed Dec 6 19:41:08 2017State: clean, degraded # pay attention here. One of our disks is broken. The raid5 status is used for downgrade. Active Devices: 2Working Devices: 2Failed Devices: 1Spare Devices: 0Layout: left-symmetricChunk Size: 256KConsistency Policy: resyncName: centos7.magedu.com:5 (local to host centos7.magedu.com) UUID: 2c8ae60d:a799fcb7:9008a046:ae6ea430Events: 20Number Major Minor RaidDevice State0 8 170 active sync / dev/sdb1- 00 1 removed3 8 49 2 active sync / dev/sdd11 8 33-faulty / dev/sdc1 [root@centos7 md5] $cat a.txt # found that our data is still accessible. No problem.
5.1.5 replace equipment
I am here to perform the replacement after the disk is broken, there can be one more spare disk, which can be replaced automatically if it is broken.
[root@centos7 md5] $mdadm / dev/md5-a / dev/sde1 # above our sdc1 data is corrupted, we need to replace his location with a new disk. Add a sde1 disk here, omitting the fdisk operation here. Mdadm: added / dev/sde1 [root@centos7 md5] $mdadm-Ds # View details ARRAY / dev/md5 metadata=1.2 name=centos7.magedu.com:5 UUID=2c8ae60d:a799fcb7:9008a046:ae6ea430 [root@centos7 md5] $mdadm-D / dev/md5 # View details / dev/md5:Version: 1.2Creation Time: Wed Dec 6 19:28:22 2017Raid Level: raid5Array Size: 2095104 (2046.00 MiB 2145.39 MB) Used Dev Size: 1047552 (1023.00 MiB 1072.69 MB) Raid Devices: 3Total Devices: 4Persistence: Superblock is persistentUpdate Time: Wed Dec 6 19:50:01 2017State: clean # status returned to normal. No problem Active Devices: 3Working Devices: 3Failed Devices: 1Spare Devices: 0Layout: left-symmetricChunk Size: 256KConsistency Policy: resyncName: centos7.magedu.com:5 (local to host centos7.magedu.com) UUID: 2c8ae60d:a799fcb7:9008a046:ae6ea430Events: 43Number Major Minor RaidDevice State0 8 170 active sync / dev/sdb14 8 65 1 active sync / dev/sde13 8 49 2 active sync / dev/sdd11 8 33-faulty / dev/sdc1 # this disk is broken, we have added a new disk This disk can kill [root@centos7 md5] $man mdadm [root@centos7 md5] $mdadm / dev/md5-- remove / dev/sdc1 # this disk we removed from raid5. Mdadm: hot removed / dev/sdc1 from / dev/md5
5.1.6 extended raid
What we use above is a raid5 of 2: 1, and the disk utilization is 66%. If we want to change it to 3: 1, we can execute a command similar to the following
[root@centos7 mnt] $mkadm-G-r / dev/md5-n 4-a / dev/sdxx # I won't test it here. Use / dev/sdxx instead of a device. -G means Grown growth.-r means resizefs.
5.1.7 clear raid information
[root@centos7 mnt] $umount / dev/md5 # Uninstall device [root@centos7 mnt] $mdadm-S / dev/md5 # stop raid5 mdadm: stopped / dev/md5 [root@centos7 mnt] $sed-I'$d' / etc/fstab# remove the line on raid5 mount in fstab [root@centos7 mnt] $cat / etc/fstab# make sure fstab doesn't have a big problem # # / etc/fstab# Created by anaconda on Tue Nov 7 16:07:01 2017 installation # Accessible filesystems By reference, are maintained under'/ dev/disk'# See man pages fstab (5), findfs (8), mount (8) and/or blkid (8) for more info#UUID=59ccea87-3c4e-4bbc-9e2f-3fadb1dcf2e6 / ext4 defaults 1 1UUID=f4e867e8-bcde-43a2-adc7-c80b0948e85f / app ext4 noatime,usrquota,grpquota 1 2UUID=1d6cbe88-ffb4-4adf-bacf-76be1fa75708 / boot ext4 defaults 12 # UUID=b2c064f5-1ee5-4b5c-9e75-ed41cb99c5aa swap swap defaults 0 0#UUID=a0516c4f-40e6-4919-905a-8b44db12ff7b swap swap defaults Pri=0 0 0#/dev/ sdb2 / test ext4 rw,seclabel,relatime,data=ordered 0 0#/dev/sdb1 / home xfs rw,seclabel,relatime,attr2,inode64,usrquota,grpquota 0 [root@centos7 mnt] $rm-rf / etc/mdadm.conf # Delete the raid default configuration file [root@centos7 mnt] $mdadm-- zero-superblock / dev/sd {b1Magne e1Magne c1} # Clean the super block information on the settings
5.2 implementation of RAID10
Raid10, 6 partitions, 2 raid1,3 group raid0
5.2.1 case study
Under the analysis, we create a raid10 setting, two devices form a raid1,6, two sets of devices can form three raid1, and then three raid1 can be formed into one raid0.
5.2.2 create 6 devices first
[root@centos7 mnt] $lsblk # is a device created using fdisk, but I won't write about it here. Finally use lsblk to display We can see sdb1,sdb2,sdd1. Sde1 has six disks NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTsda 8:0 0200G 0 disk ├─ sda1 8:1 01G 0 part / boot ├─ sda2 8:2 0128G 0 part ├─ sda3 8:3 048.8G 0 part / ├─ sda4 8:4 0512B 0 part └─ sda5 8:5 019.5G 0 part / appsdb 8:16 0100G 0disk ├─ sdb1 8:17 01G 0part └─ sdb2 8:18 01G 0 part sdc 8:32 020G 0 disk ├─ sdc1 8:33 0 1G 0 part └─ sdc2 8:34 0 1G 0 part sdd 8:48 0 20G 0 disk └─ sdd1 8:49 0 1G 0 part sde 8:64 0 20G 0 disk └─ sde1 8:65 0 1G 0 part sdf 8:80 0 20G 0 disk sr0 11:0 1 8.1G 0 rom / run/media/root/CentOS 7 x86_64
5.2.3 create raid
[root@centos7 mnt] $mdadm-C / dev/md11-a yes-l 1-n 2 / dev/sd {b1Magazine C1} # create the first raid1mdadm: / dev/sdb1 appears to be part of a raid array: level=raid5 devices=3 ctime=Wed Dec 6 19:28:22 2017mdadm: Note: this array has metadata at the start and may not be suitable as a boot device. If you plan to store'/ boot' on this device please ensure that your boot-loader understands md/v1.x metadata, or use-- metadata=0.90mdadm: / dev/sdc1 appears to be part of a raid array: level=raid5 devices=3 ctime=Wed Dec 6 19:28:22 2017Continue creating array? Ymdadm: Defaulting to version 1.2 metadatamdadm: array / dev/md11 started. [root@centos7 mnt] $mdadm-C / dev/md12-a yes-l 1-n 2 / dev/sd {b2je c2} # create a second raid1mdadm: Note: this array has metadata at the start and may not be suitable as a boot device. If you plan to store'/ boot' on this device please ensure that your boot-loader understands md/v1.x metadata, or use-- metadata=0.90Continue creating array? Ymdadm: Defaulting to version 1.2 metadatamdadm: array / dev/md12 started. [root@centos7 mnt] $mdadm-C / dev/md13-a yes-l 1-n 2 / dev/sd {D1 dev/sdd1 appears to be part of a raid array:level=raid5 devices=3 ctime=Wed Dec E1} # create a third raid1mdadm: / dev/sdd1 appears to be part of a raid array:level=raid5 devices=3 ctime=Wed Dec 6 19:28:22 2017mdadm: Note: this array has metadata at the start andmay not be suitable as a boot device. If you plan tostore'/ boot' on this device please ensure thatyour boot-loader understands md/v1.x metadata, or use--metadata=0.90mdadm: / dev/sde1 appears to be part of a raid array:level=raid5 devices=3 ctime=Wed Dec 6 19:28:22 2017Continue creating array? Ymdadm: Defaulting to version 1.2 metadatamdadm: array / dev/md13 started. [root@centos7 mnt] $mdadm-C / dev/md10-a yes-l 0-n 3 / dev/md {11 raid1 12 raid1 13} # merge three raid1 into one raid0 mdadm: / dev/md11 appears to contain an ext2fs file systemsize=2095104K mtime=Wed Dec 6 19:29:45 2017mdadm: / dev/md13 appears to contain an ext2fs file systemsize=2095104K mtime=Wed Dec 6 19:29:45 2017Continue creating array? Ymdadm: Defaulting to version 1.2 metadatamdadm: array / dev/md10 started. [root@centos7 mnt] $mkfs.extmkfs.ext2 mkfs.ext3 mkfs.ext4 [root@centos7 mnt] $mkfs.ext4 / dev/md10 # create file system mke2fs 1.42.9 (28-Dec-2013) Filesystem label=OS type: LinuxBlock size=4096 (log=2) Fragment size=4096 (log=2) Stride=128 blocks, Stripe width=384 blocks196224 inodes, 784896 blocks39244 blocks (5.00%) reserved for the super userFirst data block=0Maximum filesystem blocks=80530636824 block groups32768 blocks per group 32768 fragments per group8176 inodes per groupSuperblock backups stored on blocks: 32768, 98304, 163840, 229376 294912Allocating group tables: doneWriting inode tables: done Creating journal (16384 blocks): doneWriting superblocks and filesystem accounting information: done [root@centos7 mnt] $mdadm-Ds # View the configuration information ARRAY / dev/md11 metadata=1.2 name=centos7.magedu.com:11 UUID=0ce2cd6c:cd21fab6:3e65cfb5:64bd86f3ARRAY / dev/md12 metadata=1.2 name=centos7.magedu.com:12 UUID=8af31dff:efab06ed:48e2613b:a599c774ARRAY / dev/md13 metadata=1.2 name=centos7.magedu.com:13 UUID=a8c99d60:2d0c61e7:97a76809:9396c020ARRAY / dev/md10 metadata=1. 2 name=centos7.magedu.com:10 UUID=50b2fa58:4ce65d67:8c50c853:fa175a28 [root@centos7 mnt] $mdadm-Ds > > / etc/mdadm.conf # write configuration file to mdadm configuration file [root@centos7 mnt] $mkdir / mnt/md10 # create mount directory [root@centos7 mnt] $mount / dev/md10 / mnt/md10 # mount file system [root@centos7 mnt] $tail-n 1 / etc/mtab # View the last line in the mtab file That is, our md10 mount information / dev/md10 / mnt/md10 ext4 rw,seclabel,relatime,stripe=384,data=ordered 0 [root@centos7 mnt] $tail-n 1 / etc/mtab > > / etc/fstab # is added to boot
5.2.4 raid cleanup
[root@centos7 mnt] $umount / dev/md10 # Unmount [root@centos7 mnt] $rm-rf / etc/mdadm.conf # Delete the default configuration of mdadm [root@centos7 mnt] $mdadm-S / dev/md10 # stop raid0 setting mdadm: stopped / dev/md10 [root@centos7 mnt] $mdadm-S / dev/md11 # stop raid1 setting mdadm: stopped / dev/md11 [root@centos7 Mnt] $mdadm-S / dev/md12 # stop radi1 setting mdadm: stopped / dev/md12 [root@centos7 mnt] $mdadm-S / dev/md13 # stop raid 1 set mdadm: stopped / dev/md13 [root@centos7 mnt] $sed-I'$d' / etc/fstab # remove the mount of fstab [root@centos7 mnt] $cat / etc/fstab # make sure it is correct # # / etc/ Fstab# Created by anaconda on Tue Nov 7 16:07:01 2017## Accessible filesystems By reference, are maintained under'/ dev/disk'# See man pages fstab (5), findfs (8), mount (8) and/or blkid (8) for more info#UUID=59ccea87-3c4e-4bbc-9e2f-3fadb1dcf2e6 / ext4 defaults 1 1UUID=f4e867e8-bcde-43a2-adc7-c80b0948e85f / app ext4 noatime,usrquota,grpquota 1 2UUID=1d6cbe88-ffb4-4adf-bacf-76be1fa75708 / boot ext4 defaults 12 # UUID=b2c064f5-1ee5-4b5c-9e75-ed41cb99c5aa swap swap defaults 0 0#UUID=a0516c4f-40e6-4919-905a-8b44db12ff7b swap swap defaults Pri=0 0 0#/dev/ sdb2 / test ext4 rw,seclabel,relatime,data=ordered 0 0#/dev/sdb1 / home xfs rw,seclabel,relatime,attr2,inode64,usrquota,grpquota 0 [root@centos7 mnt] $mdadm-D # check the mdadm information again Make sure that there is no mdadm: No devices given. [root@centos7 mnt] $mdadm-- zero-superblock / dev/sd {b1Theme b2rect c1rec c2Magnee D1} # request md metadata information about "what is the implementation principle of disk management soft RAID in linux" this article ends here. I hope the above content can be helpful to you, so that you can learn more knowledge, if you think the article is good. Please share it for more people to see.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.