创建raid5分区
1、
分区:fdisk /dev/sdb
n:创建分区
t:更改分区类型(fd)
w:保存分区
[root@compute ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 100G 0 disk
├─sda1 8:1 0 1G 0 part /boot
└─sda2 8:2 0 99G 0 part
├─centos-root 253:0 0 50G 0 lvm /
├─centos-swap 253:1 0 7.9G 0 lvm [SWAP]
└─centos-home 253:2 0 41.1G 0 lvm /home
sdb 8:16 0 20G 0 disk
├─sdb1 8:17 0 9.3G 0 part
│ ├─cinder--volumes-cinder--volumes--pool_tmeta 253:3 0 12M 0 lvm
│ │ └─cinder--volumes-cinder--volumes--pool 253:5 0 8.9G 0 lvm
│ └─cinder--volumes-cinder--volumes--pool_tdata 253:4 0 8.9G 0 lvm
│ └─cinder--volumes-cinder--volumes--pool 253:5 0 8.9G 0 lvm
└─sdb2 8:18 0 9.3G 0 part
sdc 8:32 0 1G 0 disk
sdd 8:48 0 1G 0 disk
sde 8:64 0 1G 0 disk
sdf 8:80 0 1G 0 disk
sr0 11:0 1 4.2G 0 rom
[root@compute ~]# 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 0x4d912b22.
Command (m for help): m
Command action
a toggle a bootable flag
b edit bsd disklabel
c toggle the dos compatibility flag
d delete a partition
g create a new empty GPT partition table
G create an IRIX (SGI) partition table
l list known partition types
m print this menu
n add a new partition
o create a new empty DOS partition table
p print the partition table
q quit without saving changes
s create a new empty Sun disklabel
t change a partition's system id
u change display/entry units
v verify the partition table
w write table to disk and exit
x extra functionality (experts only)
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-2097151, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-2097151, default 2097151):
Using default value 2097151
Partition 1 of type Linux and of size 1023 MiB is set
Command (m for help): t #改变分区格式为fd,fd也就是raid分区的模式
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.
------------------------------------------------------------------------------------
2、
安装raid工具
yum -y install mdadm
[root@compute ~]# yum -y install mdadm
------------------------------------------------------------------------------------
3、
创建raid5
-n 磁盘数量
-l 级别
[root@compute ~]# mdadm -Cv /dev/md5 -n3 -l5 /dev/sd[c-e]1
------------------------------------------------------------------------------------
4、查看raid详细信息
mdadm -D /dev/md5
[root@compute ~]# mdadm -D /dev/md5
/dev/md5:
Version : 1.2
Creation Time : Fri Oct 29 13:00:50 2021
Raid Level : raid5
Array Size : 2091008 (2042.00 MiB 2141.19 MB)
Used Dev Size : 1045504 (1021.00 MiB 1070.60 MB)
Raid Devices : 3
Total Devices : 3
Persistence : Superblock is persistent
Update Time : Fri Oct 29 13:00:56 2021
State : clean
Active Devices : 3
Working Devices : 3
Failed Devices : 0
Spare Devices : 0
Layout : left-symmetric
Chunk Size : 512K
Consistency Policy : resync
Name : compute:5 (local to host compute)
UUID : ad78ce89:6d8e64e9:5abc0815:971660b5
Events : 18
Number Major Minor RaidDevice State
0 8 33 0 active sync /dev/sdc1
1 8 49 1 active sync /dev/sdd1
3 8 65 2 active sync /dev/sde1
------------------------------------------------------------------------------------
5、格式化raid5
[root@compute bin]# mkfs.ext4 /dev/md5
6、挂载使用
[root@compute mnt]# mount /dev/md5 /mnt/disk5
RAID5冗余备份与数据灾难恢复
1、添加一块磁盘(1GB),分区,创建文件系统(过程同上,不做赘述)
[root@compute disk5]# lsblk | grep sdf
sdf 8:80 0 1G 0 disk
└─sdf1 8:81 0 1023M 0 part
2、热备一块磁盘
[root@compute ~]# mdadm /dev/md5 -a /dev/sdf1
mdadm: added /dev/sdf1
[root@compute ~]# mdadm -D /dev/md5
/dev/md5:
Version : 1.2
Creation Time : Fri Oct 29 13:00:50 2021
Raid Level : raid5
Array Size : 2091008 (2042.00 MiB 2141.19 MB)
Used Dev Size : 1045504 (1021.00 MiB 1070.60 MB)
Raid Devices : 3
Total Devices : 4
Persistence : Superblock is persistent
Update Time : Fri Oct 29 14:10:04 2021
State : clean
Active Devices : 3
Working Devices : 4
Failed Devices : 0
Spare Devices : 1
Layout : left-symmetric
Chunk Size : 512K
Consistency Policy : resync
Name : compute:5 (local to host compute)
UUID : ad78ce89:6d8e64e9:5abc0815:971660b5
Events : 19
Number Major Minor RaidDevice State
0 8 33 0 active sync /dev/sdc1
1 8 49 1 active sync /dev/sdd1
3 8 65 2 active sync /dev/sde1
————》》 4 8 81 - spare /dev/sdf1
3、模拟磁盘损坏(停用其中一块磁盘)
[root@compute ~]# mdadm /dev/md5 -f /dev/sde1
mdadm: set /dev/sde1 faulty in /dev/md5
[root@compute ~]# mdadm -D /dev/md5
/dev/md5:
Version : 1.2
Creation Time : Fri Oct 29 13:00:50 2021
Raid Level : raid5
Array Size : 2091008 (2042.00 MiB 2141.19 MB)
Used Dev Size : 1045504 (1021.00 MiB 1070.60 MB)
Raid Devices : 3
Total Devices : 4
Persistence : Superblock is persistent
Update Time : Fri Oct 29 14:15:06 2021
State : clean
Active Devices : 3
Working Devices : 3
Failed Devices : 1
Spare Devices : 0
Layout : left-symmetric
Chunk Size : 512K
Consistency Policy : resync
Name : compute:5 (local to host compute)
UUID : ad78ce89:6d8e64e9:5abc0815:971660b5
Events : 38
Number Major Minor RaidDevice State
0 8 33 0 active sync /dev/sdc1
1 8 49 1 active sync /dev/sdd1
4 8 81 2 active sync /dev/sdf1
3 8 65 - faulty /dev/sde1
4、移除损坏的磁盘或移除热备份磁盘
[root@compute lost+found]# mdadm /dev/md5 -r /dev/sde1
mdadm: hot removed /dev/sde1 from /dev/md5
[root@compute lost+found]# mdadm -D /dev/md5
/dev/md5:
Version : 1.2
Creation Time : Fri Oct 29 13:00:50 2021
Raid Level : raid5
Array Size : 2091008 (2042.00 MiB 2141.19 MB)
Used Dev Size : 1045504 (1021.00 MiB 1070.60 MB)
Raid Devices : 3
Total Devices : 3
Persistence : Superblock is persistent
Update Time : Fri Oct 29 14:16:53 2021
State : clean
Active Devices : 3
Working Devices : 3
Failed Devices : 0
Spare Devices : 0
Layout : left-symmetric
Chunk Size : 512K
Consistency Policy : resync
Name : compute:5 (local to host compute)
UUID : ad78ce89:6d8e64e9:5abc0815:971660b5
Events : 39
Number Major Minor RaidDevice State
0 8 33 0 active sync /dev/sdc1
1 8 49 1 active sync /dev/sdd1
4 8 81 2 active sync /dev/sdf1