RAID 5原理如上图所示:
RAID 5最少要求3个磁盘,因此添加磁盘/dev/sdf、/dev/sdg、/dev/sdh。
卸载md1分区:
[root@11g ~]# umount /dev/md1
分区:
[root@11g ~]# fdisk /dev/sdf
同RAID 0
[root@11g ~]# fdisk /dev/sdg
同RAID 0
[root@11g ~]# fdisk /dev/sdh
同RAID 0
[root@11g ~]# fdisk –l
Device Boot Start End Blocks Id System
/dev/sda1 * 1 13 104391 83 Linux
/dev/sda2 14 3916 31350847+ 8e Linux LVM
/dev/sdb1 1 512 524272 fd Linux raid autodetect
/dev/sdc1 1 512 524272 fd Linux raid autodetect
/dev/sdd1 1 204 208880 fd Linux raid autodetect
/dev/sde1 1 204 208880 fd Linux raid autodetect
/dev/sdf1 1 204 208880 fd Linux raid autodetect
/dev/sdg1 1 204 208880 fd Linux raid autodetect
/dev/sdh1 1 204 208880 fd Linux raid autodetect
创建:
[root@11g ~]# mdadm -C /dev/md2 -l5 -n2 -x1 /dev/sd[f,g,h]1
mdadm: array /dev/md2 started.
注:“n2”表示2个活动磁盘。
“x1”表示1个热备磁盘。
格式化 /dev/md2:
[root@11g ~]# mkfs.ext3 /dev/md2
挂载到 /mdtest:
[root@11g ~]# mount /dev/md2 /mdtest
拷贝数据到 /mdtest:
[root@11g ~]# cp -R /etc/default/ /mdtest/
模拟某个磁盘丢失(检测热备磁盘是否能顶替损坏丢失磁盘):
[root@11g ~]# mdadm /dev/md2 -f /dev/sdf1
mdadm: set /dev/sdf1 faulty in /dev/md2
查看磁盘状态:
[root@11g ~]# cat /proc/mdstat
Personalities : [raid1] [raid0] [raid6] [raid5] [raid4]
md2 : active raid5 sdg1[1] sdh1[0] sdf1[2](F) --- sdf为F,不可用状态
208768 blocks level 5, 64k chunk, algorithm 2 [2/2] [UU]
md1 : active raid1 sde1[1]
208768 blocks [2/1] [_U]
md0 : active raid0 sdc1[1] sdb1[0]
1048320 blocks 64k chunks
unused devices: <none>
移除损坏的磁盘:
[root@11g ~]# mdadm /dev/md2 -r /dev/sdf1
mdadm: hot removed /dev/sdf1
查看磁盘状态:
[root@11g ~]# cat /proc/mdstat
Personalities : [raid1] [raid0] [raid6] [raid5] [raid4]
md2 : active raid5 sdg1[1] sdh1[0]
208768 blocks level 5, 64k chunk, algorithm 2 [2/2] [UU]
unused devices: <none>
访问磁盘数据:
[root@11g ~]# ls /mdtest/default/
nss useradd
数据仍可以读取
添加热备磁盘:
[root@11g ~]# mdadm /dev/md2 -a /dev/sdf1
添加成功