CentOS 6.8 create RAID-5

1 Create three new partitions##

[ root@centos68 ~]# fdisk /dev/sdb
Command(m for help): p

Disk /dev/sdb:53.7 GB,53687091200 bytes
255 heads,63 sectors/track,6527 cylinders
Units = cylinders of16065*512=8225280 bytes
Sector size(logical/physical):512 bytes /512 bytes
I/O size(minimum/optimal):512 bytes /512 bytes
Disk identifier:0xb5c926a7

 Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               13917314632715  Extended
/dev/sdb5               1654525319283  Linux
/dev/sdb6             65513085253223+83  Linux
/dev/sdb7            130919625253223+83  Linux

2 Modify the partition type to fd (Linux raid autodetect)

Command(m for help): t
Partition number(1-7):5
Hex code(type L to list codes): fd
Changed system type of partition 5 to fd(Linux raid autodetect)Command(m for help): t
Partition number(1-7):6
Hex code(type L to list codes): fd
Changed system type of partition 6 to fd(Linux raid autodetect)Command(m for help): t
Partition number(1-7):7
Hex code(type L to list codes): fd
Changed system type of partition 7 to fd(Linux raid autodetect)Command(m for help): p

Disk /dev/sdb:53.7 GB,53687091200 bytes
255 heads,63 sectors/track,6527 cylinders
Units = cylinders of16065*512=8225280 bytes
Sector size(logical/physical):512 bytes /512 bytes
I/O size(minimum/optimal):512 bytes /512 bytes
Disk identifier:0xb5c926a7

 Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               13917314632715  Extended
/dev/sdb5               16545253192   fd  Linux raid autodetect
/dev/sdb6             65513085253223+  fd  Linux raid autodetect
/dev/sdb7            130919625253223+  fd  Linux raid autodetect

Save and exit

Command(m for help): w
The partition table has been altered!

Force to reread the disk partition table (run several times)

[ root@centos68 ~]# partx -a /dev/sdb

3 New Free Partition##

[ root@centos68 ~]# fdisk /dev/sdb

Command(m for help): n

Command action
 l   logical(5 or over)
 p   primary partition(1-4)
l
First cylinder(1963-3917,default1963):
Using default value 1963
Last cylinder,+cylinders or +size{K,M,G}(1963-3917,default3917):+5G

Command(m for help): t
Partition number(1-8):8
Hex code(type L to list codes): fd
Changed system type of partition 8 to fd(Linux raid autodetect)Command(m for help): p

Disk /dev/sdb:53.7 GB,53687091200 bytes
255 heads,63 sectors/track,6527 cylinders
Units = cylinders of16065*512=8225280 bytes
Sector size(logical/physical):512 bytes /512 bytes
I/O size(minimum/optimal):512 bytes /512 bytes
Disk identifier:0xb5c926a7

 Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               13917314632715  Extended
/dev/sdb5               16545253192   fd  Linux raid autodetect
/dev/sdb6             65513085253223+  fd  Linux raid autodetect
/dev/sdb7            130919625253223+  fd  Linux raid autodetect
/dev/sdb8            196326165253223+  fd  Linux raid autodetect

Command(m for help): w
The partition table has been altered!

# Force reread partition table
[ root@centos68 ~]# partx -a /dev/sdb

4 Create RAID-5

[ root@centos68 ~]# mdadm -C /dev/md0 -a yes -n 3-x 1-l 5/dev/sdb{5,6,7,8}
mdadm: Defaulting to version 1.2 metadata
mdadm: array /dev/md0 started.

View the data synchronization process

[ root@centos68 ~]# watch -n1 'cat /proc/mdstat'

View the status of all md type devices

[ root@centos68 ~]# cat /proc/mdstat
Personalities :[raid6][raid5][raid4]
md0 : active raid5 sdb7[4] sdb8[3](S) sdb6[1] sdb5[0]10498048 blocks super1.2 level 5, 512k chunk, algorithm 2[3/3][UUU]

unused devices:<none>

View RAID details

[ root@centos68 ~]# mdadm -D /dev/md0
/dev/md0:
  Version :1.2
 Creation Time : Thu Jun 2503:49:102020
  Raid Level : raid5
  Array Size :10498048(10.01 GiB 10.75 GB)
 Used Dev Size :5249024(5.01 GiB 5.38 GB)
 Raid Devices :3
 Total Devices :4
 Persistence : Superblock is persistent

 Update Time : Thu Jun 2503:53:072020
   State : clean
 Active Devices :3
Working Devices :4
 Failed Devices :0
 Spare Devices :1

   Layout : left-symmetric
  Chunk Size : 512K

   Name : centos68:0(local to host centos68)
   UUID : be5cb284:275497f7:be5982ec:ce03ed15
   Events :18

 Number   Major   Minor   RaidDevice State
  08210  active sync   /dev/sdb5
  18221  active sync   /dev/sdb6
  48232  active sync   /dev/sdb7

  3824-  spare   /dev/sdb8

5 Format Partition##

[ root@centos68 ~]# mke2fs -t ext4 /dev/md0

View

[ root@centos68 ~]# df -lh
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/vg_centos68-lv_root
      50 G  861M   46G   2%/
tmpfs                 931M     0  931M   0%/dev/shm
/dev/sda1             477M   39M  413M   9%/boot
/dev/mapper/vg_centos68-lv_home
      45 G   52M   43G   1%/home
/dev/md0              9.8G   23M  9.3G   1%/data

Achieve automatic mounting at boot

[ root@centos68 ~]# blkid /dev/md0
/dev/md0: UUID="e2303c17-62a6-4938-aa7a-d5b9c52ab4ea" TYPE="ext4"
# It is recommended to use UUID for mounting or LABEL volume label mounting
[ root@centos68 ~]# tail -1/etc/fstab
UUID=e2303c17-62a6-4938-aa7a-d5b9c52ab4ea       /data   defaults,acl    00

6 Simulate bad disk##

[ root@centos68 ~]# mdadm /dev/md0 -f /dev/sdb5
mdadm:set/dev/sdb5 faulty in/dev/md0

View the synchronization process of the spare disk

[ root@centos68 ~]# cat /proc/mdstat #Or use watch-n1 'cat /proc/mdstat'Observe the recovery process dynamically
Personalities :[raid6][raid5][raid4]
md0 : active raid5 sdb7[4] sdb8[3] sdb6[1] sdb5[0](F)10498048 blocks super1.2 level 5, 512k chunk, algorithm 2[3/2][_UU][=>...................]  recovery =6.8%(359808/5249024) finish=0.6min speed=119936K/sec

unused devices:<none>

View RAID details again

== The spare disk sdb8 has replaced the bad disk sdb5==

[ root@centos68 ~]# mdadm -D /dev/md0
/dev/md0:
  Version :1.2
 Creation Time : Thu Jun 2503:49:102020
  Raid Level : raid5
  Array Size :10498048(10.01 GiB 10.75 GB)
 Used Dev Size :5249024(5.01 GiB 5.38 GB)
 Raid Devices :3
 Total Devices :4
 Persistence : Superblock is persistent

 Update Time : Thu Jun 2504:07:212020
   State : clean
 Active Devices :3
Working Devices :3
 Failed Devices :1
 Spare Devices :0

   Layout : left-symmetric
  Chunk Size : 512K

   Name : centos68:0(local to host centos68)
   UUID : be5cb284:275497f7:be5982ec:ce03ed15
   Events :37

 Number   Major   Minor   RaidDevice State
  38240  active sync   /dev/sdb8
  18221  active sync   /dev/sdb6
  48232  active sync   /dev/sdb7

  0821-  faulty   /dev/sdb5

7 Simulate a bad disk and observe whether the data is normally accessed##

Copy test data to RAID-5 mount point /data

[ root@centos68 ~]# cp /etc/passwd /data/[root@centos68 ~]# ll /data/passwd
- rw-r--r--.1 root root 887 Jun 2504:13/data/passwd
[ root@centos68 ~]# cat /etc/passwd

Simulate bad disk /dev/sdb8, observe the state state

[ root@centos68 ~]# mdadm /dev/md0 -f /dev/sdb8
mdadm:set/dev/sdb8 faulty in/dev/md0
[ root@centos68 ~]# mdadm -D /dev/md0
/dev/md0:
  Version :1.2
 Creation Time : Thu Jun 2503:49:102020
  Raid Level : raid5
  Array Size :10498048(10.01 GiB 10.75 GB)
 Used Dev Size :5249024(5.01 GiB 5.38 GB)
 Raid Devices :3
 Total Devices :4
 Persistence : Superblock is persistent

 Update Time : Thu Jun 2504:15:232020
   State : clean, degraded #Degraded operating mode
 Active Devices :2
Working Devices :2
 Failed Devices :2
 Spare Devices :0

   Layout : left-symmetric #The default layout is left symmetrical
  Chunk Size : 512K

   Name : centos68:0(local to host centos68)
   UUID : be5cb284:275497f7:be5982ec:ce03ed15
   Events :39

 Number   Major   Minor   RaidDevice State
  0000  removed
  18221  active sync   /dev/sdb6
  48232  active sync   /dev/sdb7

  0821-  faulty   /dev/sdb5
  3824-  faulty   /dev/sdb8

Test whether the data is normally accessed

[ root@centos68 ~]# cd /data
[ root@centos68 data]# cat passwd
root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin

8 Remove bad disk##

[ root@centos68 data]# mdadm /dev/md0 -r /dev/sdb5
mdadm: hot removed /dev/sdb5 from/dev/md0
[ root@centos68 data]# mdadm /dev/md0 -r /dev/sdb8
mdadm: hot removed /dev/sdb8 from/dev/md0
[ root@centos68 data]# mdadm -D /dev/md0
/dev/md0:
  Version :1.2
 Creation Time : Thu Jun 2503:49:102020
  Raid Level : raid5
  Array Size :10498048(10.01 GiB 10.75 GB)
 Used Dev Size :5249024(5.01 GiB 5.38 GB)
 Raid Devices :3
 Total Devices :2
 Persistence : Superblock is persistent

 Update Time : Thu Jun 2504:19:052020
   State : clean, degraded
 Active Devices :2
Working Devices :2
 Failed Devices :0
 Spare Devices :0

   Layout : left-symmetric
  Chunk Size : 512K

   Name : centos68:0(local to host centos68)
   UUID : be5cb284:275497f7:be5982ec:ce03ed15
   Events :45

 Number   Major   Minor   RaidDevice State
  0000  removed
  18221  active sync   /dev/sdb6
  48232  active sync   /dev/sdb7

9 Add Disk##

[ root@centos68 data]# mdadm /dev/md0 -a /dev/sdb5
mdadm: added /dev/sdb5

View the data synchronization process

[ root@centos68 data]# watch -n1 'cat /proc/mdstat'

Every 1.0s: cat /proc/mdstat                                   Thu Jun 2504:23:042020

Personalities :[raid6][raid5][raid4]
md0 : active raid5 sdb5[3] sdb7[4] sdb6[1]10498048 blocks super1.2 level 5, 512k chunk, algorithm 2[3/2][_UU][================>....]  recovery =82.0%(4309708/5249024) finish=0.1min speed=1
00386 K/sec

unused devices:<none>

Reference document: https://cloud.tencent.com/developer/article/1562726

Recommended Posts

CentOS 6.8 create RAID-5
CentOS 8 (2)
CentOS 8 (1)
Centos 7 RAID 5 detailed explanation and configuration
centos7 python3.7+vi
Create CentOS Docker image with httpd service
CentOS + Jenkins
1.5 Install Centos7
2019-07-09 CentOS7 installation
centos7_1708 installation
Centos 7.5 python3.6
CentOS 7 install KVM and create a virtual machine