RAID5磁盘阵列组技术至少需要3块盘来做,加上1块备份盘(这块硬盘设备平时是闲置状态不用工作,一旦RAID磁盘阵列组中有硬盘出现故障后则会马上自动顶替上去),总共是需要向虚拟机中模拟4块硬盘设备。
[root@victory ~]# fdisk -l Disk /dev/sdb: 2147 MB, 2147483648 bytes, 4194304 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes Disk /dev/sde: 2147 MB, 2147483648 bytes, 4194304 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes Disk /dev/sdd: 2147 MB, 2147483648 bytes, 4194304 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes Disk /dev/sda: 5368 MB, 5368709120 bytes, 10485760 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x0006ae1e Device Boot Start End Blocks Id System
/dev/sda1 * 2048 616447 307200 83 Linux
/dev/sda2 616448 10485759 4934656 8e Linux LVM Disk /dev/sdc: 2147 MB, 2147483648 bytes, 4194304 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes Disk /dev/mapper/rhel-root: 3976 MB, 3976200192 bytes, 7766016 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes Disk /dev/mapper/rhel-swap: 1073 MB, 1073741824 bytes, 2097152 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
现在来创建一个RAID5磁盘阵列组+备份盘,-n 3参数代表创建这个RAID5所需的硬盘个数,-l 5参数代表RAID磁盘阵列的级别,而-x 1参数则代表有1块备份盘,当查看/dev/md0磁盘阵列组的时候就能看到有一块备份盘在等待中了。
[root@victory ~]# mdadm -Cv /dev/md0 -n 3 -l 5 -x 1 /dev/sdb /dev/sdc /dev/sdd /dev/sde
mdadm: layout defaults to left-symmetric
mdadm: layout defaults to left-symmetric
mdadm: chunk size defaults to 512K
mdadm: size set to 2095104K
mdadm: Defaulting to version 1.2 metadata
mdadm: array /dev/md0 started.
[root@victory ~]# mdadm -D /dev/md0
/dev/md0:
Version : 1.2
Creation Time : Tue Aug 1 23:31:26 2017
Raid Level : raid5
Array Size : 4190208 (4.00 GiB 4.29 GB)
Used Dev Size : 2095104 (2046.34 MiB 2145.39 MB)
Raid Devices : 3
Total Devices : 4
Persistence : Superblock is persistent Update Time : Tue Aug 1 23:31:39 2017
State : clean, degraded, recovering
Active Devices : 2
Working Devices : 4
Failed Devices : 0
Spare Devices : 2 Layout : left-symmetric
Chunk Size : 512K Rebuild Status : 65% complete Name : victory.rusky.com:0 (local to host victory.rusky.com)
UUID : ca1f08c6:07e51bc7:668168b7:2bb84496
Events : 11 Number Major Minor RaidDevice State
0 8 16 0 active sync /dev/sdb
1 8 32 1 active sync /dev/sdc
4 8 48 2 spare rebuilding /dev/sdd --表示正在创建中 3 8 64 - spare /dev/sde [root@victory ~]# mdadm -D /dev/md0
/dev/md0:
Version : 1.2
Creation Time : Tue Aug 1 23:31:26 2017
Raid Level : raid5
Array Size : 4190208 (4.00 GiB 4.29 GB)
Used Dev Size : 2095104 (2046.34 MiB 2145.39 MB)
Raid Devices : 3
Total Devices : 4
Persistence : Superblock is persistent Update Time : Tue Aug 1 23:31:47 2017
State : clean
Active Devices : 3
Working Devices : 4
Failed Devices : 0
Spare Devices : 1 Layout : left-symmetric
Chunk Size : 512K Name : victory.rusky.com:0 (local to host victory.rusky.com)
UUID : ca1f08c6:07e51bc7:668168b7:2bb84496
Events : 18 Number Major Minor RaidDevice State
0 8 16 0 active sync /dev/sdb
1 8 32 1 active sync /dev/sdc
4 8 48 2 active sync /dev/sdd 3 8 64 - spare /dev/sde
[root@victory ~]#
把这块制作的RAID5磁盘阵列组格式化为xfs文件格式后挂载到目录上吧,这样就可以使用了。
[root@victory ~]# echo "/dev/md0 /fuckRAID xfs defaults 0 0" >> /etc/fstab
[root@victory ~]# cat /etc/fstab #
# /etc/fstab
# Created by anaconda on Tue Aug ::
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(), findfs(), mount() and/or blkid() for more info
#
/dev/mapper/rhel-root / xfs defaults
UUID=e7987771-c54c-4b36-8a5c-8e71f129c3fe /boot xfs defaults
/dev/mapper/rhel-swap swap swap defaults
/dev/md0 /fuckRAID xfs defaults
[root@victory ~]# mkdir /fuckRAID
[root@victory ~]# mount -a
[root@victory ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/rhel-root .7G 896M .9G % /
devtmpfs 910M 910M % /dev
tmpfs 920M 920M % /dev/shm
tmpfs 920M 8.4M 912M % /run
tmpfs 920M 920M % /sys/fs/cgroup
/dev/sda1 297M 114M 184M % /boot
tmpfs 184M 184M % /run/user/
/dev/md0 .0G 33M .0G % /fuckRAID
[root@victory ~]#
再次把硬盘设备/dev/sdb移出磁盘阵列组,这样快速看下/dev/md0磁盘阵列组的状态就会发现备份盘已经被自动顶替上去,这是非常实用的,在RAID磁盘阵列组数据安全保证的基础上进一步提高数据可靠性。
[root@victory ~]# cd /fuckRAID/
[root@victory fuckRAID]# ll
total
[root@victory fuckRAID]# cd ~
[root@victory ~]# cd /fuckRAID/
[root@victory fuckRAID]# touch testaddFile
[root@victory fuckRAID]# ll
total
-rw-r--r--. root root Aug : testaddFile
[root@victory fuckRAID]# mdadm /dev/md0 -f /dev/sdb
mdadm: set /dev/sdb faulty in /dev/md0
[root@victory fuckRAID]# mdadm -D /dev/md0
/dev/md0:
Version : 1.2
Creation Time : Tue Aug ::
Raid Level : raid5
Array Size : (4.00 GiB 4.29 GB)
Used Dev Size : (2046.34 MiB 2145.39 MB)
Raid Devices :
Total Devices :
Persistence : Superblock is persistent Update Time : Tue Aug ::
State : clean
Active Devices :
Working Devices :
Failed Devices :
Spare Devices : Layout : left-symmetric
Chunk Size : 512K Name : victory.rusky.com: (local to host victory.rusky.com)
UUID : ca1f08c6:07e51bc7:668168b7:2bb84496
Events : Number Major Minor RaidDevice State
active sync /dev/sde
active sync /dev/sdc
active sync /dev/sdd - faulty /dev/sdb
[root@victory fuckRAID]# ll
total
-rw-r--r--. root root Aug : testaddFile
[root@victory fuckRAID]#