linux系统中磁盘阵列 + 备份盘 (RAID5+1备份盘)
linux系统中 RAID10 磁盘阵列由两个RAID1+一个raid0组成,当其中一个raid1中的两块硬盘同时损坏时,数据就无法恢复了。(应该是最简单情况)
这种情况下,我们可以使用RAID备份盘技术来预防这类事故的发生。
RAID备份盘技术的核心理念就是准备一块足够大的硬盘,这块硬盘平时处于闲置状态,一旦RAID磁盘阵列中用硬盘出现故障后则会马上自动顶替上去。
以RAID5 + 备份盘为例
部署RAID5至少需要三块硬盘,然后备份盘需要一块硬盘,因此测试最少需要4块硬盘。
1、将虚拟机还原(快照),并创建4块硬盘
[root@linuxprobe ~]# cd /dev
[root@linuxprobe dev]# find sd*
sda
sda1
sda2
sdb
sdc
sdd
sde
2、创建RAID5磁盘阵列+备份盘
[root@linuxprobe dev]# mdadm -Cv /dev/md0 -n 3 -l 5 -x 1 /dev/sdb /dev/sdc /dev/sdd /dev/sde
## -C 表示创建磁盘阵列,-v 表示显示创建过程,-n 3 表示一共使用3块硬盘,-l 5 表示RAID的级别,-x 1 表示有一块备份盘
mdadm: layout defaults to left-symmetric
mdadm: layout defaults to left-symmetric
mdadm: chunk size defaults to 512K
mdadm: size set to 20954624K
mdadm: Defaulting to version 1.2 metadata
mdadm: array /dev/md0 started.
3、查看RAID5 磁盘阵列 + 备份盘的详细信息
[root@linuxprobe dev]# mdadm -D /dev/md0
/dev/md0:
Version : 1.2
Creation Time : Wed Oct 28 23:52:38 2020
Raid Level : raid5
Array Size : 41909248 (39.97 GiB 42.92 GB)
Used Dev Size : 20954624 (19.98 GiB 21.46 GB)
Raid Devices : 3
Total Devices : 4
Persistence : Superblock is persistent
Update Time : Wed Oct 28 23:54:24 2020
State : clean
Active Devices : 3
Working Devices : 4
Failed Devices : 0
Spare Devices : 1
Layout : left-symmetric
Chunk Size : 512K
Name : linuxprobe.com:0 (local to host linuxprobe.com)
UUID : c2a4a51b:96460fb7:71b1c2e3:b5f17bbd
Events : 20
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
4、将RAID5磁盘阵列格式化为ext4格式
[root@linuxprobe dev]# mkfs.ext4 /dev/md0
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=256 blocks
2621440 inodes, 10477312 blocks
523865 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=2157969408
320 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
4096000, 7962624
Allocating group tables: done
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
5、将RAID5 磁盘阵列挂载
[root@linuxprobe dev]# df -h ## 查看挂载情况
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/rhel-root 18G 2.9G 15G 17% /
devtmpfs 985M 0 985M 0% /dev
tmpfs 994M 80K 994M 1% /dev/shm
tmpfs 994M 8.9M 986M 1% /run
tmpfs 994M 0 994M 0% /sys/fs/cgroup
/dev/sda1 497M 119M 379M 24% /boot
/dev/sr0 3.5G 3.5G 0 100% /run/media/root/RHEL-7.0 Server.x86_64
[root@linuxprobe dev]# mkdir /RAID ## 创建挂载点
[root@linuxprobe dev]# mount /dev/md0 /RAID/ ## 挂载
[root@linuxprobe dev]# df -h ## 查看挂载结果
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/rhel-root 18G 2.9G 15G 17% /
devtmpfs 985M 0 985M 0% /dev
tmpfs 994M 80K 994M 1% /dev/shm
tmpfs 994M 8.9M 986M 1% /run
tmpfs 994M 0 994M 0% /sys/fs/cgroup
/dev/sda1 497M 119M 379M 24% /boot
/dev/sr0 3.5G 3.5G 0 100% /run/media/root/RHEL-7.0 Server.x86_64
/dev/md0 40G 49M 38G 1% /RAID
6、写入开机自动挂载
[root@linuxprobe dev]# cat /etc/fstab ## 查看配置文件
#
# /etc/fstab
# Created by anaconda on Wed Oct 28 20:19:08 2020
#
# 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
#
/dev/mapper/rhel-root / xfs defaults 1 1
UUID=2f2c5a2f-df13-4b36-99c3-9edd1b976d40 /boot xfs defaults 1 2
/dev/mapper/rhel-swap swap swap defaults 0 0
[root@linuxprobe dev]# echo -e "/dev/md0\t/RAID\text4\tdefaults\t0\t0" >> /etc/fstab ## 修改配置文件
[root@linuxprobe dev]# cat /etc/fstab ## 查看配置文件
#
# /etc/fstab
# Created by anaconda on Wed Oct 28 20:19:08 2020
#
# 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
#
/dev/mapper/rhel-root / xfs defaults 1 1
UUID=2f2c5a2f-df13-4b36-99c3-9edd1b976d40 /boot xfs defaults 1 2
/dev/mapper/rhel-swap swap swap defaults 0 0
/dev/md0 /RAID ext4 defaults 0 0
7、删除RAID5磁盘阵列中的一块硬盘(损坏),假设为/dev/sdc, 删除后迅速查看RAID5磁盘阵列的详细情况
[root@linuxprobe dev]# mdadm /dev/md0 -f /dev/sdc ## 删除硬盘 /dev/sdc
mdadm: set /dev/sdc faulty in /dev/md0
[root@linuxprobe dev]# mdadm -D /dev/md0 ## 查看RAID5磁盘阵列的详细信息,/dev/sdc移除,/dev/sde补上
/dev/md0:
Version : 1.2
Creation Time : Wed Oct 28 23:52:38 2020
Raid Level : raid5
Array Size : 41909248 (39.97 GiB 42.92 GB)
Used Dev Size : 20954624 (19.98 GiB 21.46 GB)
Raid Devices : 3
Total Devices : 4
Persistence : Superblock is persistent
Update Time : Thu Oct 29 00:04:04 2020
State : clean, degraded, recovering
Active Devices : 2
Working Devices : 3
Failed Devices : 1
Spare Devices : 1
Layout : left-symmetric
Chunk Size : 512K
Rebuild Status : 12% complete
Name : linuxprobe.com:0 (local to host linuxprobe.com)
UUID : c2a4a51b:96460fb7:71b1c2e3:b5f17bbd
Events : 23
Number Major Minor RaidDevice State
0 8 16 0 active sync /dev/sdb
3 8 64 1 spare rebuilding /dev/sde
4 8 48 2 active sync /dev/sdd
1 8 32 - faulty /dev/sdc