共享热备盘
由于条件有限,本试验是在Vmware虚拟机上模拟完成的。试验使用的是两个raid1组之间的共享一个热备盘,一开始md0有一个热备盘,而md1没有热备盘,通过修改配置文件可以使它们共享一块热备盘。如此可在节省磁盘的同时,同时也增强了安全性。
- 1、环境搭建:
- # fdisk -l | grep '^/dev/' //查看当前磁盘的分区结构
- /dev/sda1 * 1 13 104391 83 Linux
- /dev/sda2 14 2610 20860402+ 8e Linux LVM
- /dev/sdb1 1 2610 20964793+ fd Linux raid autodetect
- /dev/sdc1 1 2610 20964793+ fd Linux raid autodetect
- /dev/sdd1 1 2610 20964793+ fd Linux raid autodetect
- /dev/sde1 1 2610 20964793+ fd Linux raid autodetect
- /dev/sdf1 1 2610 20964793+ fd Linux raid autodetect
- [root@localhost ~]#
- [root@localhost ~]# mdadm -C /dev/md0 -l 1 -n 2 /dev/sdb1/dev/sdc1 #创建raid1设备1——》md0
- mdadm: array /dev/md0 started.
- [root@localhost ~]# mdadm -C /dev/md1 -l 1 -n 2 /dev/sdd1/dev/sde1 #创建raid1设备2——》md1
- mdadm: array /dev/md1 started.
- [root@localhost ~]#
- [root@localhost ~]# mdadm /dev/md0 -a /dev/sdf #增加一块热备盘到md0中去,当然也可以一开始建立md0的时候使用选项-x可以实现: mdadm -C /dev/md0 -l 1 -n 2 -x1 /dev/sdb1 /dev/sdc1/dev/sdf1
- mdadm: added /dev/sdf
- [root@localhost ~]#
- 完成以上操作之后格式化建立的raid
- [root@localhost ~]# mkfs.ext3 /dev/md0
- [root@localhost ~]# mkfs.ext3 /dev/md1
- [root@localhost ~]# mdadm -D /dev/md0 #查看md0的详细raid信息
- /dev/md0:
- Version : 0.90
- Creation Time : Mon Feb 6 21:14:26 2012
- Raid Level : raid1
- Array Size : 20964672 (19.99 GiB 21.47 GB)
- Used Dev Size : 20964672 (19.99 GiB 21.47 GB)
- Raid Devices : 2
- Total Devices : 3
- Preferred Minor : 0
- Persistence : Superblock is persistent
- Update Time : Mon Feb 6 21:21:37 2012
- State : clean
- Active Devices : 2
- Working Devices : 3
- Failed Devices : 0
- Spare Devices : 1
- UUID :d3139435:a8e981cc:db393640:b48c5bcf
- Events : 0.2
- Number Major Minor RaidDevice State
- 0 8 17 0 active sync /dev/sdb1
- 1 8 33 1 active sync /dev/sdc1
- 2 8 80 - spare /dev/sdf
- #这里可以发现热备盘是在md0上的
- [root@localhost ~]# mdadm -D /dev/md1
- /dev/md1:
- Version : 0.90
- Creation Time : Mon Feb 6 21:14:46 2012
- Raid Level : raid1
- Array Size : 20964672 (19.99 GiB 21.47 GB)
- Used Dev Size : 20964672 (19.99 GiB 21.47 GB)
- Raid Devices : 2
- Total Devices : 2
- Preferred Minor : 1
- Persistence : Superblock is persistent
- Update Time : Mon Feb 6 21:21:44 2012
- State : clean
- Active Devices : 2
- Working Devices : 2
- Failed Devices : 0
- Spare Devices : 0
- UUID :96798114:27a61808:4e3e764e:ae834ac5
- Events : 0.2
- Number Major Minor RaidDevice State
- 0 8 49 0 active sync /dev/sdd1
- 1 8 65 1 active sync /dev/sde1
- #md1上没有热备盘
- [root@localhost ~]#
- 生成信息重定向到配置文件中
- [root@localhost ~]# mdadm -Ds >/etc/mdadm.conf
- [root@localhost ~]# cat /etc/mdadm.conf
- ARRAY /dev/md0 level=raid1num-devices=2 metadata=0.90 spares=1 UUID=d3139435:a8e981cc:db393640:b48c5bcf
- ARRAY /dev/md1 level=raid1num-devices=2 metadata=0.90 UUID=96798114:27a61808:4e3e764e:ae834ac5
- [root@localhost ~]# vim /etc/mdadm.conf
- [root@localhost ~]# cat /etc/mdadm.conf #修改内容如下
- ARRAY /dev/md0 level=raid1num-devices=2 metadata=0.90 spare-group=sparedisks UUID=d3139435:a8e981cc:db393640:b48c5bcf
- ARRAY /dev/md1 level=raid1num-devices=2 metadata=0.90 spare-group=sparedisks UUID=96798114:27a61808:4e3e764e:ae834ac5
- [root@localhost ~]#
- 2、启动监控,监控室必须的,要知道系统是没有那么聪明的,哈哈
- [root@localhost ~]# mdadm --monitor --mail=root@localhost--syslog --program=/root/md.sh --delay=300 /dev/md* --daemonise #启用监控两组raid设备,并且有状况发送信息给root用户,以及后台执行
- 3867
- [root@localhost ~]#
- #当然也可以直接使用如下命令使破坏的过程日志显示在屏幕上,而不是发邮件的形式给管理员
- [root@localhost ~]# mdadm --monitor /dev/md*
- 3、模拟破坏过程
- [root@localhost ~]# mdadm /dev/md1 -f /dev/sde1 #破坏/dev/sde1
- [root@localhost ~]# mdadm -D /dev/md0 #再次查看当前md0的详细状态
- /dev/md0:
- Version : 0.90
- Creation Time : Mon Feb 6 21:14:26 2012
- RaidLevel : raid1
- Array Size : 20964672 (19.99 GiB 21.47 GB)
- Used Dev Size : 20964672 (19.99 GiB 21.47 GB)
- Raid Devices : 2
- Total Devices : 2
- Preferred Minor : 0
- Persistence : Superblock is persistent
- Update Time : Mon Feb 6 21:29:04 2012
- State : clean
- Active Devices : 2
- Working Devices : 2
- Failed Devices : 0
- Spare Devices : 0
- UUID :d3139435:a8e981cc:db393640:b48c5bcf
- Events : 0.4
- Number Major Minor RaidDevice State
- 0 8 17 0 active sync /dev/sdb1
- 1 8 33 1 active sync /dev/sdc1
- #设备/dev/sdf已经不在md0中了
- [root@localhost ~]#
- [root@localhost ~]# mdadm -D /dev/md1 #查看md1的详细信息
- /dev/md1:
- Version : 0.90
- Creation Time : Mon Feb 6 21:14:46 2012
- Raid Level : raid1
- Array Size : 20964672 (19.99 GiB 21.47 GB)
- Used Dev Size : 20964672 (19.99 GiB 21.47 GB)
- Raid Devices : 2
- Total Devices : 3
- Preferred Minor : 1
- Persistence : Superblock is persistent
- Update Time : Mon Feb 6 21:29:04 2012
- State : clean, degraded, recovering
- Active Devices : 1
- Working Devices : 2
- Failed Devices : 1
- Spare Devices : 1
- Rebuild Status : 14% complete
- UUID :96798114:27a61808:4e3e764e:ae834ac5
- Events : 0.6
- Number Major Minor RaidDevice State
- 0 8 49 0 active sync /dev/sdd1
- 2 8 80 1 spare rebuilding /dev/sdf
- 3 8 65 - faulty spare /dev/sde1
- #此时我们可以看到sdf热备盘已经转到md1下了