Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Linux soft raid

2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

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] $lsblk

NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT

Sda 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 0 512B 0 part

└─ sda5 8:5 0 19.5G 0 part / app

Sdb 8:16 0 100G 0 disk

Sdc 8:32 0 20G 0 disk

Sdd 8:48 0 20G 0 disk

Sde 8:64 0 20G 0 disk

Sdf 8:80 0 20G 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

Copy the code

[root@centos7 Bash] $fdisk / dev/sdb

Welcome 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 table

Building a new DOS disklabel with disk identifier 0x93d380cf.

Command (m for help): n

Partition type:

P primary (0 primary, 0 extended, 4 free)

E extended

Select (default p): P

Partition number (1-4, default 1):

First sector (2048-209715199, default 2048):

Using default value 2048

Last sector, + sectors or + size {KMagne Mpeng} (2048-209715199, default 209715199): + 1G

Partition 1 of type Linux and of size 1 GiB is set

Command (m for help): t

Selected partition 1

Hex code (type L to list all codes): fd

Changed type of partition 'Linux' to' Linux raid autodetect'

Command (m for help): P

Disk / dev/sdb: 107.4 GB, 107374182400 bytes, 209715200 sectors

Units = sectors of 1 * 512 = 512 bytes

Sector size (logical/physical): 512 bytes / 512 bytes

I size (minimum/optimal): 512 bytes / 512 bytes

Disk label type: dos

Disk identifier: 0x93d380cf

Device Boot Start End Blocks Id System

/ dev/sdb1 2048 2099199 1048576 fd Linux raid autodetect

Command (m for help): W

The partition table has been altered!

Calling ioctl () to re-read partition table.

Syncing disks.

[root@centos7 Bash] $fdisk / dev/sdc

Welcome 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 table

Building a new DOS disklabel with disk identifier 0xc56b90d8.

Command (m for help): n

Partition type:

P primary (0 primary, 0 extended, 4 free)

E extended

Select (default p): P

Partition number (1-4, default 1):

First sector (2048-41943039, default 2048):

Using default value 2048

Last sector, + sectors or + size {KMagne Mpeng} (2048-41943039, default 41943039): + 1G

Partition 1 of type Linux and of size 1 GiB is set

Command (m for help): t

Selected partition 1

Hex code (type L to list all codes): fd

Changed type of partition 'Linux' to' Linux raid autodetect'

Command (m for help): P

Disk / dev/sdc: 21.5 GB, 21474836480 bytes, 41943040 sectors

Units = sectors of 1 * 512 = 512 bytes

Sector size (logical/physical): 512 bytes / 512 bytes

I size (minimum/optimal): 512 bytes / 512 bytes

Disk label type: dos

Disk identifier: 0xc56b90d8

Device Boot Start End Blocks Id System

/ dev/sdc1 2048 2099199 1048576 fd Linux raid autodetect

Command (m for help): W

The partition table has been altered!

Calling ioctl () to re-read partition table.

Syncing disks.

[root@centos7 Bash] $fdisk / dev/sdd

Welcome 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 table

Building a new DOS disklabel with disk identifier 0x7e0900d8.

Command (m for help): n

Partition type:

P primary (0 primary, 0 extended, 4 free)

E extended

Select (default p): P

Partition number (1-4, default 1):

First sector (2048-41943039, default 2048):

Using default value 2048

Last sector, + sectors or + size {KMagne Mpeng} (2048-41943039, default 41943039): + 1G

Partition 1 of type Linux and of size 1 GiB is set

Command (m for help): P

Disk / dev/sdd: 21.5 GB, 21474836480 bytes, 41943040 sectors

Units = sectors of 1 * 512 = 512 bytes

Sector size (logical/physical): 512 bytes / 512 bytes

I size (minimum/optimal): 512 bytes / 512 bytes

Disk label type: dos

Disk identifier: 0x7e0900d8

Device Boot Start End Blocks Id System

/ dev/sdd1 2048 2099199 1048576 83 Linux

Command (m for help): t

Selected partition 1

Hex code (type L to list all codes): fd

Changed type of partition 'Linux' to' Linux raid autodetect'

Command (m for help): W

The partition table has been altered!

Calling ioctl () to re-read partition table.

Syncing disks.

Copy the code

5.1.3 create raid

Copy the code

[root@centos7 Bash] $mdadm-C / dev/md5-a yes-l 5-n 3 / dev/sd {b1Powerc1PowerD1}-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? Y

Mdadm: Defaulting to version 1.2 metadata

Mdadm: 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 # writes soft raid information to the configuration file

[root@centos7 Bash] $mkdir / mnt/md5 # create mount point directory

[root@centos7 Bash] $mkfs.ext4 / dev/md5 # create a file system

Mke2fs 1.42.9 (28-Dec-2013)

Filesystem label=

OS type: Linux

Block size=4096 (log=2)

Fragment size=4096 (log=2)

Stride=64 blocks, Stripe width=128 blocks

131072 inodes, 523776 blocks

26188 blocks (5.00%) reserved for the super user

First data block=0

Maximum filesystem blocks=536870912

16 block groups

32768 blocks per group, 32768 fragments per group

8192 inodes per group

Superblock backups stored on blocks:

32768, 98304, 163840, 229376, 294912

Allocating group tables: done

Writing inode tables: done

Creating journal (8192 blocks): done

Writing superblocks and filesystem accounting information: done

[root@centos7 Bash] $mount / dev/md5 / mnt/md5 # Mount the 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 # is added to the fstab file to ensure boot. Uuid is recommended here.

Copy the code

5.1.4 verify raid

Copy the code

[root@centos7 md5] $mdadm-D / dev/md5 # View the details of raid5, and you can find that three of them are working status

/ dev/md5:

Version: 1.2

Creation Time: Wed Dec 6 19:28:22 2017

Raid Level: raid5

Array Size: 2095104 (2046.00 MiB 2145.39 MB)

Used Dev Size: 1047552 (1023.00 MiB 1072.69 MB)

Raid Devices: 3

Total Devices: 3

Persistence: Superblock is persistent

Update Time: Wed Dec 6 19:39:06 2017 State: clean Active Devices: 3

Working Devices: 3

Failed Devices: 0

Spare Devices: 0

Layout: left-symmetric Chunk Size: 256K

Consistency Policy: resync

Name: centos7.magedu.com:5 (local to host centos7.magedu.com) UUID: 2c8ae60d:a799fcb7:9008a046:ae6ea430 Events: 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 set the specified device failure and mark the / dev/sdc1 disk to see if the data can be accessed. I failed to use the-f flag here. The disk status can be judged according to the hard disk indicator at work.

Mdadm: set / dev/sdc1 faulty in / dev/md5

[root@centos7 md5] $mdadm-D / dev/md5 # after checking the information, it was found that there were two working devices and one failed device.

/ dev/md5:

Version: 1.2

Creation Time: Wed Dec 6 19:28:22 2017

Raid Level: raid5

Array Size: 2095104 (2046.00 MiB 2145.39 MB)

Used Dev Size: 1047552 (1023.00 MiB 1072.69 MB)

Raid Devices: 3

Total Devices: 3

Persistence: Superblock is persistent

Update Time: Wed Dec 6 19:41:08 2017 State: clean, degraded # pay attention here. One of our disks is broken. The raid5 status is used for downgrade. Active Devices: 2

Working Devices: 2

Failed Devices: 1

Spare Devices: 0

Layout: left-symmetric Chunk Size: 256K

Consistency Policy: resync

Name: centos7.magedu.com:5 (local to host centos7.magedu.com) UUID: 2c8ae60d:a799fcb7:9008a046:ae6ea430 Events: 20Number Major Minor RaidDevice State 08 17 0 active sync / dev/sdb1-00 1 removed 3 8 49 2 active sync / dev/sdd1 1 8 33 -faulty / dev/sdc1

[root@centos7 md5] $cat a.txt # found that our data is still accessible. No problem.

Copy the code

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.

Copy the code

[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.2

Creation Time: Wed Dec 6 19:28:22 2017

Raid Level: raid5

Array Size: 2095104 (2046.00 MiB 2145.39 MB)

Used Dev Size: 1047552 (1023.00 MiB 1072.69 MB)

Raid Devices: 3

Total Devices: 4

Persistence: Superblock is persistent

Update Time: Wed Dec 6 19:50:01 2017 State: clean # status is back to normal. No problem Active Devices: 3

Working Devices: 3

Failed Devices: 1

Spare Devices: 0

Layout: left-symmetric Chunk Size: 256K

Consistency Policy: resync

Name: centos7.magedu.com:5 (local to host centos7.magedu.com) UUID: 2c8ae60d:a799fcb7:9008a046:ae6ea430 Events: 43Number Major Minor RaidDevice State 08 17 0 active sync / dev/sdb1 4 8 65 1 active sync / dev/sde1 3 8 49 2 active sync / dev/sdd1 1 8 33-faulty / dev/sdc1 # this disk is broken We have added a new disk and this disk can be wiped out.

[root@centos7 md5] $man mdadm

[root@centos7 md5] $mdadm / dev/md5-- remove / dev/sdc1 # this disk is removed from raid5.

Mdadm: hot removed / dev/sdc1 from / dev/md5

Copy the code

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

Copy the code

[root@centos7 mnt] $umount / dev/md5 # Uninstall the device

[root@centos7 mnt] $mdadm-S / dev/md5 # stop raid5

Mdadm: stopped / dev/md5

[root@centos7 mnt] $sed-I'$d' / etc/fstab # Delete the line on raid5 mount in fstab

[root@centos7 mnt] $cat / etc/fstab # make sure there is no big problem with fstab

#

/ etc/fstabCreated 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 1

UUID=f4e867e8-bcde-43a2-adc7-c80b0948e85f / app ext4 noatime,usrquota,grpquota 1 2

UUID=1d6cbe88-ffb4-4adf-bacf-76be1fa75708 / boot ext4 defaults 1 2

# 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 0

[root@centos7 mnt] $rm-rf / etc/mdadm.conf # Delete raid default configuration file

[root@centos7 mnt] $mdadm-- zero-superblock / dev/sd {b1mene1recoverd1recoverc1} # clear the super block information on the setting

Copy the code

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

Copy the code

[root@centos7 mnt] $lsblk # is a device created using fdisk, but I won't write about it here. Finally, using the lsblk display, we can see that sdb1,sdb2,sdd1,sde1 has a total of six disks.

NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT

Sda 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 0 512B 0 part

└─ sda5 8:5 0 19.5G 0 part / app

Sdb 8:16 0 100G 0 disk

├─ sdb1 8:17 0 1G 0 part

└─ sdb2 8:18 0 1G 0 part

Sdc 8:32 0 20G 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

Copy the code

5.2.3 create raid

Copy the code

[root@centos7 mnt] $mdadm-C / dev/md11-a yes-l 1-n 2 / dev/sd {b1Magne C1} # create the first raid1

Mdadm: / dev/sdb1 appears to be part of a raid array:

Level=raid5 devices=3 ctime=Wed Dec 6 19:28:22 2017

Mdadm: 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.90

Mdadm: / dev/sdc1 appears to be part of a raid array:

Level=raid5 devices=3 ctime=Wed Dec 6 19:28:22 2017

Continue creating array? Y

Mdadm: Defaulting to version 1.2 metadata

Mdadm: array / dev/md11 started.

[root@centos7 mnt] $mdadm-C / dev/md12-a yes-l 1-n 2 / dev/sd {b2menc c2} # create a second raid1

Mdadm: 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.90

Continue creating array? Y

Mdadm: Defaulting to version 1.2 metadata

Mdadm: array / dev/md12 started.

[root@centos7 mnt] $mdadm-C / dev/md13-a yes-l 1-n 2 / dev/sd {d1mene1} # create a third raid1

Mdadm: / dev/sdd1 appears to be part of a raid array:

Level=raid5 devices=3 ctime=Wed Dec 6 19:28:22 2017

Mdadm: 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.90

Mdadm: / dev/sde1 appears to be part of a raid array:

Level=raid5 devices=3 ctime=Wed Dec 6 19:28:22 2017

Continue creating array? Y

Mdadm: Defaulting to version 1.2 metadata

Mdadm: 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 system

Size=2095104K mtime=Wed Dec 6 19:29:45 2017

Mdadm: / dev/md13 appears to contain an ext2fs file system

Size=2095104K mtime=Wed Dec 6 19:29:45 2017

Continue creating array? Y

Mdadm: Defaulting to version 1.2 metadata

Mdadm: array / dev/md10 started.

[root@centos7 mnt] $mkfs.ext

Mkfs.ext2 mkfs.ext3 mkfs.ext4

[root@centos7 mnt] $mkfs.ext4 / dev/md10 # create a file system

Mke2fs 1.42.9 (28-Dec-2013)

Filesystem label=

OS type: Linux

Block size=4096 (log=2)

Fragment size=4096 (log=2)

Stride=128 blocks, Stripe width=384 blocks

196224 inodes, 784896 blocks

39244 blocks (5.00%) reserved for the super user

First data block=0

Maximum filesystem blocks=805306368

24 block groups

32768 blocks per group, 32768 fragments per group

8176 inodes per group

Superblock backups stored on blocks:

32768, 98304, 163840, 229376, 294912

Allocating group tables: done

Writing inode tables: done

Creating journal (16384 blocks): done

Writing superblocks and filesystem accounting information: done

[root@centos7 mnt] $mdadm-Ds # View configuration information

ARRAY / dev/md11 metadata=1.2 name=centos7.magedu.com:11 UUID=0ce2cd6c:cd21fab6:3e65cfb5:64bd86f3

ARRAY / dev/md12 metadata=1.2 name=centos7.magedu.com:12 UUID=8af31dff:efab06ed:48e2613b:a599c774

ARRAY / dev/md13 metadata=1.2 name=centos7.magedu.com:13 UUID=a8c99d60:2d0c61e7:97a76809:9396c020

ARRAY / dev/md10 metadata=1.2 name=centos7.magedu.com:10 UUID=50b2fa58:4ce65d67:8c50c853:fa175a28

[root@centos7 mnt] $mdadm-Ds > > / etc/mdadm.conf # write the configuration file to the configuration file of mdadm

[root@centos7 mnt] $mkdir / mnt/md10 # create a mount directory

[root@centos7 mnt] $mount / dev/md10 / mnt/md10 # Mount the file system

[root@centos7 mnt] $tail-n 1 / etc/mtab # look at the last line in the mtab file, which is our md10 mount information

/ dev/md10 / mnt/md10 ext4 rw,seclabel,relatime,stripe=384,data=ordered 0 0

[root@centos7 mnt] $tail-n 1 / etc/mtab > > / etc/fstab # add to boot

Copy the code

5.2.4 raid cleanup

Copy the code

[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 setting

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/fstabCreated 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 1

UUID=f4e867e8-bcde-43a2-adc7-c80b0948e85f / app ext4 noatime,usrquota,grpquota 1 2

UUID=1d6cbe88-ffb4-4adf-bacf-76be1fa75708 / boot ext4 defaults 1 2

# 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 0

[root@centos7 mnt] $mdadm-D # check the mdadm information again to make sure it is gone

Mdadm: No devices given.

[root@centos7 mnt] $mdadm-- zero-superblock / dev/sd {b1Personb2MagneC1MagneC2Magned1Magnee1} # request md metadata information

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.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report