1、soft raid (package:mdadm-2.6.9-2.el5)
常用raid有0,1,5三种模式。5中还可以加入一个备用的磁盘,以待备用,当磁盘坏了,马上加入阵列,并替换坏的磁盘。
在此只做raid5的实验。
step 1、在虚拟机上加入5个磁盘。在linux下识别为:/dev/sd{b,c,d,e,f}
step 2、使用mdadm指令创建raid5
mdadm --create /dev/md0 -l 5 -n 3 -x 1 /dev/sdb /dev/sdc /dev/sdd /dev/sde
step 3、查看状态
cat /proc/mdstat 或者
mdadm --detail /dev/md0
[root@localhost ~]# mdadm --detail /dev/md0
/dev/md0:
Version : 0.90
Creation Time : Wed Apr 18 05:43:05 2012
Raid Level : raid5
Array Size : 10485632 (10.00 GiB 10.74 GB)
Used Dev Size : 5242816 (5.00 GiB 5.37 GB)
Raid Devices : 3
Total Devices : 4
Preferred Minor : 0
Persistence : Superblock is persistent
Update Time : Wed Apr 18 05:47:32 2012
State : clean
Active Devices : 3
Working Devices : 4
Failed Devices : 0
Spare Devices : 1
Layout : left-symmetric
Chunk Size : 64K
UUID : b009524a:05f9aca5:c12992b9:ba85a2a0
Events : 0.2
Number Major Minor RaidDevice State
0 8 16 0 active sync /dev/sdb
1 8 32 1 active sync /dev/sdc
2 8 48 2 active sync /dev/sdd
3 8 64 - spare /dev/sde
step 4、把md0装置写入配置文件(如果不写入些文件可能会导致重启后此raid5不能使用)
mdadm --detail --scan >>/etc/mdadm.conf
step 5、格式化磁盘
mke2fs -j /dev/md0
step 6、挂载并测试
mount /dev/md0 /mnt
step 7、如果需要开机的时候就自动挂载的话写入/etc/fstab.
测试当磁盘坏的时候,spare disk自动替换
step 1、 mdadm --manage /dev/md0 --fail /dev/sdc
step 2、 mdadm --detail /dev/md0
[root@localhost ~]# mdadm --detail /dev/md0
/dev/md0:
Version : 0.90
Creation Time : Wed Apr 18 05:43:05 2012
Raid Level : raid5
Array Size : 10485632 (10.00 GiB 10.74 GB)
Used Dev Size : 5242816 (5.00 GiB 5.37 GB)
Raid Devices : 3
Total Devices : 4
Preferred Minor : 0
Persistence : Superblock is persistent
Update Time : Wed Apr 18 06:07:01 2012
State : clean, degraded, recovering
Active Devices : 2
Working Devices : 3
Failed Devices : 1
Spare Devices : 1
Layout : left-symmetric
Chunk Size : 64K
Rebuild Status : 9% complete (正在还原)
UUID : b009524a:05f9aca5:c12992b9:ba85a2a0
Events : 0.4
Number Major Minor RaidDevice State
0 8 16 0 active sync /dev/sdb
3 8 64 1 spare rebuilding /dev/sde
2 8 48 2 active sync /dev/sdd
4 8 32 - faulty spare /dev/sdc(此处显示有一个坏)
setp 3、替换坏的磁盘
mdadm --manage /dev/md0 --add /dev/sdf --remove /dev/sdc
setp 4、检查是否成功替换
mdadm --detail /dev/md0
[root@localhost ~]# mdadm --detail /dev/md0
/dev/md0:
Version : 0.90
Creation Time : Wed Apr 18 05:43:05 2012
Raid Level : raid5
Array Size : 10485632 (10.00 GiB 10.74 GB)
Used Dev Size : 5242816 (5.00 GiB 5.37 GB)
Raid Devices : 3
Total Devices : 4
Preferred Minor : 0
Persistence : Superblock is persistent
Update Time : Wed Apr 18 06:20:58 2012
State : clean
Active Devices : 3
Working Devices : 4
Failed Devices : 0
Spare Devices : 1
Layout : left-symmetric
Chunk Size : 64K
UUID : b009524a:05f9aca5:c12992b9:ba85a2a0
Events : 0.8
Number Major Minor RaidDevice State
0 8 16 0 active sync /dev/sdb
1 8 64 1 active sync /dev/sde
2 8 48 2 active sync /dev/sdd
3 8 80 - spare /dev/sdf(已成功替换)