按t去修改分区。 键入 fd设置为 Linux的RAID 类型
Command (m for help): t
Partition number (1-9): 1 更改主分区1的类型
Hex code (type L to list codes): fd
Changed system type of partition 1 to fd (Linux raid autodetect)
安装软RAID
[[email protected] ~]#yum install mdadm –y
查看当前系统中是否存在raid
[[email protected] ~]#cat /proc/mdstat
配置RAID5
mdadm -C /dev/md0 -a yes -l 5 -n 3 -x 1 /dev/sdb{5..8}
-C Create 创建
-a 是否启用/dev/md0
-l 创建raid几
-n 指定几块硬盘
-x 指定几个备份磁盘
{5..8}指定5,6,7,8划分到raid5
[[email protected] ~]# cat /proc/mdstat
Personalities : [raid6] [raid5] [raid4]
md0 : active raid5 sdb7[4] sdb8[3](S) sdb6[1] sdb5[0]
2117632 blocks super 1.2 level 5, 512k chunk, algorithm 2 [3/3] [UUU]
unused devices: <none>
sdb8[3](S) (S)表示是备份磁盘
每个chunk是512k
查看具体的详情信息
[[email protected] ~]# mdadm -D /dev/md0
/dev/md0:
Version : 1.2
Creation Time : Thu Aug 4 18:13:04 2016
Raid Level : raid5
Array Size : 2117632 (2.02 GiB 2.17 GB)
Used Dev Size : 1058816 (1034.00 MiB 1084.23 MB)
Raid Devices : 3
Total Devices : 4
Persistence : Superblock is persistent
Update Time : Thu Aug 4 18:15:05 2016
State : clean
Active Devices : 3 正在使用的有3个磁盘
Working Devices : 4 一共有4块磁盘
Failed Devices : 0
Spare Devices : 1 做备份的有1块磁盘
Layout : left-symmetric 算法
Chunk Size : 512K
Name : moban:0 (local to host moban)
UUID : ec217443:7469c351:36e435ba:d24d02d6
Events : 18
Number Major Minor RaidDevice State
0 8 21 0 active sync /dev/sdb5
1 8 22 1 active sync /dev/sdb6
4 8 23 2 active sync /dev/sdb7
3 8 24 - spare /dev/sdb8 备份盘
格式化
[[email protected] ~]# mkfs.ext4 /dev/md0
查看详情信息
[[email protected] ~]# tune2fs -l /dev/md0
Block size: 4096 block数量
RAID stride: 128 raid5每一次给磁盘写block数量
RAID stripe width: 256 一个轮回的block总数
由于没有配置DAID位图,当磁盘插拔后。就会从头更新数据。效率低
注意:当关闭md0后,想要重新启动使用mdadm –As命令
[[email protected] ~]# mdadm -S /dev/md0
mdadm: error opening /dev/md0: No such file or directory
[[email protected] ~]# cat /proc/mdstat
Personalities : [raid6] [raid5] [raid4]
unused devices: <none>
[[email protected] ~]# mdadm -As
mdadm: /dev/md/0 has been started with 3 drives and 1 spare.
[[email protected] ~]# cat /proc/mdstat
Personalities : [raid6] [raid5] [raid4]
md0 : active raid5 sdb5[0] sdb8[3](S) sdb7[4] sdb6[1]
2117632 blocks super 1.2 level 5, 512k chunk, algorithm 2 [3/3] [UUU]
unused devices: <none>
重命名RAID
[[email protected] ~]# mdadm -S /dev/md0 关闭md0
mdadm: stopped /dev/md0
[[email protected] ~]# mdadm -A /dev/md1 --uuid
[[email protected] ~]# mdadm –Es 查看
ARRAY /dev/md/0 metadata=1.2 UUID=ec217443:7469c351:36e435ba:d24d02d6 name=moban:0
spares=1
[[email protected] ~]# mdadm -A /dev/md1 --uuid=ec217443:7469c351:36e435ba:d24d02d6 /dev/sdb{5..8} 重组并重命名为md1 uuid必须一致
mdadm: /dev/sdb5 is busy - skipping
mdadm: /dev/sdb6 is busy - skipping
mdadm: /dev/sdb7 is busy - skipping
mdadm: /dev/sdb8 is busy - skipping
[[email protected] ~]# cat /proc/mdstat
Personalities : [raid6] [raid5] [raid4]
md1 : active raid5 sdb5[0] sdb8[3](S) sdb7[4] sdb6[1]
2117632 blocks super 1.2 level 5, 512k chunk, algorithm 2 [3/3] [UUU]
unused devices: <none>
假设把一台旧服务器的硬盘换到新服务器上,但是新的服务器上已经有了md0,那么我们要做的重点是重命名RAID,把就服务器上的md0重命名为md1
如何删除RAID
[[email protected] ~]# mdadm -S /dev/md1 关闭md1
mdadm: stopped /dev/md1
[[email protected] ~]# mdadm --zero-superblock /dev/sdb{5..8} 清除磁盘的superblock
配置RAID位图
[[email protected] ~]# mdadm -G /dev/md0 --bitmap=internal 开启位图
[[email protected] ~]#mdadm -D /dev/md0
/dev/md0:
Version : 1.2
Creation Time : Thu Aug 4 20:32:50 2016
Raid Level : raid5
Array Size : 2117632 (2.02 GiB 2.17 GB)
Used Dev Size : 1058816 (1034.00 MiB 1084.23 MB)
Raid Devices : 3
Total Devices : 3
Persistence : Superblock is persistent
Intent Bitmap : Internal
[[email protected] ~]# mdadm -G /dev/md0 --bitmap=none 关闭位图
配置RAID磁盘漂移
现在有两个RAID5,md0和md1,当md0上的任意一个磁盘损坏时,md1上的备份盘可以让md0使用。
[[email protected] ~]# mdadm -C /dev/md1 -a yes -l 5 -n 3 -x 1 /dev/sdb{5..8}
mdadm: Defaulting to version 1.2 metadata
mdadm: array /dev/md1 started.
[[email protected] ~]# mdadm -D /dev/md0|tail -6
Events : 30
Number Major Minor RaidDevice State
0 8 17 0 active sync /dev/sdb1
1 8 18 1 active sync /dev/sdb2
3 8 19 2 active sync /dev/sdb3
[[email protected] ~]# mdadm -D /dev/md1|tail -6
Number Major Minor RaidDevice State
0 8 21 0 active sync /dev/sdb5
1 8 22 1 active sync /dev/sdb6
4 8 23 2 spare rebuilding /dev/sdb7
3 8 24 - spare /dev/sdb8
RAID磁盘的漂移
配置磁盘族
[[email protected] ~]# mdadm –Ds
ARRAY /dev/md0 metadata=1.2 name=moban:0 UUID=73a49dd6:6c4e5778:984f3302:037a04ac
ARRAY/dev/md1metadata=1.2spares=1name=moban:1UUID=9bf61bc7:61d59781:969858a1:b10d22e4
[[email protected] ~]# mdadm –Ds >/etc/mdadm.conf
[[email protected] ~]#vi /etc/mdadm.conf
ARRAY /dev/md0 metadata=1.2 name=moban:0 UUID=73a49dd6:6c4e5778:984f3302:037a04ac spare-group=xx
ARRAY/dev/md1metadata=1.2spares=1name=moban:1UUID=9bf1bc7:61d59781:969858a1:b10d22e4 spare-group=xx 加入到同一个磁盘族
MAILADDR [email protected] 发送给谁
MAILFROM [email protected] 发送者是谁
假设sdb3损坏,md1上的sdb8备份盘会自动滑到md0上,所以md1上就没有备份磁盘了。
[[email protected] ~]# mdadm /dev/md0 -f /dev/sdb3 -r /dev/sdb3
mdadm: set /dev/sdb3 faulty in /dev/md0
mdadm: hot removed /dev/sdb3 from /dev/md0
[[email protected] ~]# mdadm -D /dev/md0|tail -4
Number Major Minor RaidDevice State
0 8 17 0 active sync /dev/sdb1
1 8 18 1 active sync /dev/sdb2
3 8 24 2 spare rebuilding /dev/sdb8
[[email protected] ~]# mdadm -D /dev/md1|tail -4
Number Major Minor RaidDevice State
0 8 21 0 active sync /dev/sdb5
1 8 22 1 active sync /dev/sdb6
4 8 23 2 active sync /dev/sdb7
当恢复md0的sdb3后sdb3就成了md0的备份盘,假设md1的某个磁盘坏了,sdb3会自动滑到md1上。
[[email protected] ~]# mdadm /dev/md0 -a /dev/sdb3 恢复sdb3
[[email protected] ~]# mdadm /dev/md0 -a /dev/sdb3
mdadm: added /dev/sdb3
[[email protected] ~]# mdadm -D /dev/md0|tail -6
Number Major Minor RaidDevice State
0 8 17 0 active sync /dev/sdb1
1 8 18 1 active sync /dev/sdb2
3 8 24 2 active sync /dev/sdb8
4 8 19 - spare /dev/sdb3
[[email protected] ~]# mdadm -D /dev/md1|tail -4
Number Major Minor RaidDevice State
0 8 21 0 active sync /dev/sdb5
1 8 22 1 active sync /dev/sdb6
4 8 23 2 active sync /dev/sdb7