文章目录
一、虚拟机规格
二、配置静态IP
打开虚拟网络编辑器,查看NAT模式的VMnet8所属子网,如:192.168.44.0/24
查看本机的网卡连接设备名称,如ens33
[root@storage ~]# nmcli connection show
NAME UUID TYPE DEVICE
ens33 dc847f0f-1ac6-4167-9ba8-4b328f7bf190 ethernet ens33
给本机网卡配置静态IP,参数说明如下:
- ipv4.method manual:IP配置模式为静态
- ipv4.addr 192.168.44.10/24:IP地址及MASK
- ipv4.gateway 192.168.44.2:IP网关地址
- ipv4.dns 114.114.114.114:DNS地址
[root@storage ~]# nmcli connection modify ens33 ipv4.method manual ipv4.addr 192.168.44.10/24 ipv4.gateway 192.168.44.2 ipv4.dns 114.114.114.114
激活网卡
[root@storage ~]# nmcli connection show
三、安装madadm软件
[root@1347 ~]# yum install -y mdadm
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.163.com
* * extras: mirrors.163.com
* * updates: mirrors.huaweicloud.com
~~省略~~
Installed: mdadm.x86_64 0:4.1-4.el7
Complete!
[root@1347 ~]#
四、利用三块硬盘组成RAID5阵列
参数说明如下:
- /dev/md0:RAID阵列名称
- –level=5:RAID级别
- –raid-devices=3:RAID阵列磁盘数目
[root@1347 ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 20G 0 disk
├─sda1 8:1 0 1G 0 part /boot
└─sda2 8:2 0 19G 0 part
├─centos-root 253:0 0 17G 0 lvm /
└─centos-swap 253:1 0 2G 0 lvm [SWAP]
sdb 8:16 0 10G 0 disk
sdc 8:32 0 10G 0 disk
sdd 8:48 0 10G 0 disk
sr0 11:0 1 942M 0 rom
[root@1347 ~]# mdadm --create /dev/md0 --level 5 --raid-devices 3 /dev/sdb /dev/sdc /dev/sdd
mdadm: Defaulting to version 1.2 metadata
mdadm: array /dev/md0 started.
[root@1347 ~]#
五、查看RAID阵列信息
[root@1347 ~]# mdadm --detail /dev/md0
/dev/md0:
Version : 1.2
Creation Time : Thu Nov 12 13:30:02 2020
Raid Level : raid5
Array Size : 20953088 (19.98 GiB 21.46 GB)
Used Dev Size : 10476544 (9.99 GiB 10.73 GB)
Raid Devices : 3
Total Devices : 3
Persistence : Superblock is persistent
Update Time : Thu Nov 12 13:31:07 2020
State : clean
Active Devices : 3
Working Devices : 3
Failed Devices : 0
Spare Devices : 0
Layout : left-symmetric
Chunk Size : 512K
Consistency Policy : resync
Name : 1347:0 (local to host 1347)
UUID : 937ab7b1:aca1cf45:3e06bc65:d22abe2e
Events : 18
Number Major Minor RaidDevice State
0 8 16 0 active sync /dev/sdb
1 8 32 1 active sync /dev/sdc
3 8 48 2 active sync /dev/sdd
[root@1347 ~]#
六、格式化RAID阵列
[root@1347 ~]# mkfs.ext4 /dev/md0
mke2fs 1.42.9 (28-Dec-2013)
文件系统标签=
OS type: Linux
块大小=4096 (log=2)
分块大小=4096 (log=2)
Stride=128 blocks, Stripe width=256 blocks
1310720 inodes, 5238272 blocks
261913 blocks (5.00%) reserved for the super user
第一个数据块=0
Maximum filesystem blocks=2153775104
160 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
Allocating group tables: 完成
正在写入inode表: 完成
Creating journal (32768 blocks): 完成
Writing superblocks and filesystem accounting information: 完成
[root@1347 ~]#
七、模拟RAID阵列磁盘失效
将/dev/sdb磁盘失效,查看RAID阵列状态,可以发现State 存在degraded(降级)
[root@1347 ~]# mdadm --manage /dev/md0 --fail /dev/sdb
mdadm: set /dev/sdb faulty in /dev/md0
[root@1347 ~]#
[root@1347 ~]# mdadm --detail /dev/md0
/dev/md0:
Version : 1.2
Creation Time : Thu Nov 12 13:30:02 2020
Raid Level : raid5
Array Size : 20953088 (19.98 GiB 21.46 GB)
Used Dev Size : 10476544 (9.99 GiB 10.73 GB)
Raid Devices : 3
Total Devices : 3
Persistence : Superblock is persistent
Update Time : Thu Nov 12 13:32:51 2020
State : clean, degraded
Active Devices : 2
Working Devices : 2
Failed Devices : 1
Spare Devices : 0
Layout : left-symmetric
Chunk Size : 512K
Consistency Policy : resync
Name : 1347:0 (local to host 1347)
UUID : 937ab7b1:aca1cf45:3e06bc65:d22abe2e
Events : 20
Number Major Minor RaidDevice State
- 0 0 0 removed
1 8 32 1 active sync /dev/sdc
3 8 48 2 active sync /dev/sdd
0 8 16 - faulty /dev/sdb
[root@1347 ~]#
八、模拟RAID阵列修复
将sdb磁盘移出RAID阵列
[root@1347 ~]# mdadm --manage /dev/md0 --remove /dev/sdb
mdadm: hot removed /dev/sdb from /dev/md0
将sdb磁盘加入RAID阵列
[root@1347 ~]# mdadm --manage /dev/md0 --add /dev/sdb
mdadm: added /dev/sdb
[root@1347 ~]#
查看RAID阵列的信息,发现RAID阵列State为recovering(恢复),Rebuild Status : 38% complete,恢复状态已完成4%
[root@1347 ~]# mdadm --detail /dev/md0
/dev/md0:
Version : 1.2
Creation Time : Thu Nov 12 13:30:02 2020
Raid Level : raid5
Array Size : 20953088 (19.98 GiB 21.46 GB)
Used Dev Size : 10476544 (9.99 GiB 10.73 GB)
Raid Devices : 3
Total Devices : 3
Persistence : Superblock is persistent
Update Time : Thu Nov 12 13:33:44 2020
State : clean, degraded, recovering
Active Devices : 2
Working Devices : 3
Failed Devices : 0
Spare Devices : 1
Layout : left-symmetric
Chunk Size : 512K
Consistency Policy : resync
Rebuild Status : 4% complete
Name : 1347:0 (local to host 1347)
UUID : 937ab7b1:aca1cf45:3e06bc65:d22abe2e
Events : 23
Number Major Minor RaidDevice State
4 8 16 0 spare rebuilding /dev/sdb
1 8 32 1 active sync /dev/sdc
3 8 48 2 active sync /dev/sdd
[root@1347 ~]#
隔一分钟后再次查看RAID阵列的信息,可以发现阵列磁盘数据已恢复,磁盘阵列等级已正常
[root@1347 ~]# mdadm --detail /dev/md0
/dev/md0:
Version : 1.2
Creation Time : Thu Nov 12 13:30:02 2020
Raid Level : raid5
Array Size : 20953088 (19.98 GiB 21.46 GB)
Used Dev Size : 10476544 (9.99 GiB 10.73 GB)
Raid Devices : 3
Total Devices : 3
Persistence : Superblock is persistent
Update Time : Thu Nov 12 13:36:15 2020
State : clean
Active Devices : 3
Working Devices : 3
Failed Devices : 0
Spare Devices : 0
Layout : left-symmetric
Chunk Size : 512K
Consistency Policy : resync
Name : 1347:0 (local to host 1347)
UUID : 937ab7b1:aca1cf45:3e06bc65:d22abe2e
Events : 40
Number Major Minor RaidDevice State
4 8 16 0 active sync /dev/sdb
1 8 32 1 active sync /dev/sdc
3 8 48 2 active sync /dev/sdd
[root@1347 ~]#
九、给RAID阵列配置热备盘
为了方便,此处先将sdd磁盘失效,查看RAID阵列状态,可以发现其State 存在degraded(降级)
[root@1347 ~]# mdadm --manage /dev/md0 --fail /dev/sdd
mdadm: set /dev/sdd faulty in /dev/md0
[root@1347 ~]# mdadm --detail /dev/md0
/dev/md0:
Version : 1.2
Creation Time : Thu Nov 12 13:30:02 2020
Raid Level : raid5
Array Size : 20953088 (19.98 GiB 21.46 GB)
Used Dev Size : 10476544 (9.99 GiB 10.73 GB)
Raid Devices : 3
Total Devices : 3
Persistence : Superblock is persistent
Update Time : Thu Nov 12 13:42:01 2020
State : clean, degraded
Active Devices : 2
Working Devices : 2
Failed Devices : 1
Spare Devices : 0
Layout : left-symmetric
Chunk Size : 512K
Consistency Policy : resync
Name : 1347:0 (local to host 1347)
UUID : 937ab7b1:aca1cf45:3e06bc65:d22abe2e
Events : 42
Number Major Minor RaidDevice State
4 8 16 0 active sync /dev/sdb
1 8 32 1 active sync /dev/sdc
- 0 0 2 removed
3 8 48 - faulty /dev/sdd
再将sdd磁盘移出RAID阵列(之后便可将sdd配置为RAID阵列的热备盘)
[root@1347 ~]# mdadm --manage /dev/md0 --remove /dev/sdd
mdadm: hot removed /dev/sdd from /dev/md0
[root@1347 ~]# mdadm --detail /dev/md0
/dev/md0:
Version : 1.2
Creation Time : Thu Nov 12 13:30:02 2020
Raid Level : raid5
Array Size : 20953088 (19.98 GiB 21.46 GB)
Used Dev Size : 10476544 (9.99 GiB 10.73 GB)
Raid Devices : 3
Total Devices : 2
Persistence : Superblock is persistent
Update Time : Thu Nov 12 13:42:46 2020
State : clean, degraded
Active Devices : 2
Working Devices : 2
Failed Devices : 0
Spare Devices : 0
Layout : left-symmetric
Chunk Size : 512K
Consistency Policy : resync
Name : 1347:0 (local to host 1347)
UUID : 937ab7b1:aca1cf45:3e06bc65:d22abe2e
Events : 43
Number Major Minor RaidDevice State
4 8 16 0 active sync /dev/sdb
1 8 32 1 active sync /dev/sdc
- 0 0 2 removed
将sde配置为RAID阵列的热备盘,再次查看RAID阵列的信息,可以发现有sde的状态为Spare
[root@1347 ~]# mdadm --manage /dev/md0 --add /dev/sdd
mdadm: added /dev/sdd
[root@1347 ~]# mdadm --detail /dev/md0
/dev/md0:
Version : 1.2
Creation Time : Thu Nov 12 13:30:02 2020
Raid Level : raid5
Array Size : 20953088 (19.98 GiB 21.46 GB)
Used Dev Size : 10476544 (9.99 GiB 10.73 GB)
Raid Devices : 3
Total Devices : 3
Persistence : Superblock is persistent
Update Time : Thu Nov 12 13:43:00 2020
State : clean, degraded, recovering
Active Devices : 2
Working Devices : 3
Failed Devices : 0
Spare Devices : 1
Layout : left-symmetric
Chunk Size : 512K
Consistency Policy : resync
Rebuild Status : 5% complete
Name : 1347:0 (local to host 1347)
UUID : 937ab7b1:aca1cf45:3e06bc65:d22abe2e
Events : 45
Number Major Minor RaidDevice State
4 8 16 0 active sync /dev/sdb
1 8 32 1 active sync /dev/sdc
3 8 48 2 spare rebuilding /dev/sdd
[root@1347 ~]#