/dev/sdb1 1 1044 8385898+ fd Linux raid autodetect
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
按照上面的方法分别把/dev/sdc,/dev/sdd/也创建raid分区。完成后,用fdisk -l查看
[root@ ~]# fdisk -l Disk /dev/sda: 15.0 GB, 15032385536 bytes 255 heads, 63 sectors/track, 1827 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Device Boot Start End Blocks Id System /dev/sda1 * 1 13 104391 83 Linux /dev/sda2 14 1827 14570955 8e Linux LVM Disk /dev/sdb: 8589 MB, 8589934592 bytes 255 heads, 63 sectors/track, 1044 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Device Boot Start End Blocks Id System /dev/sdb1 1 1044 8385898+ fd Linux raid autodetect Disk /dev/sdc: 8589 MB, 8589934592 bytes 255 heads, 63 sectors/track, 1044 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Device Boot Start End Blocks Id System /dev/sdc1 1 1044 8385898+ fd Linux raid autodetect Disk /dev/sdd: 8589 MB, 8589934592 bytes 255 heads, 63 sectors/track, 1044 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Device Boot Start End Blocks Id System /dev/sdd1 1 1044 8385898+ fd Linux raid autodetect Disk /dev/sde: 8589 MB, 8589934592 bytes 255 heads, 63 sectors/track, 1044 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Device Boot Start End Blocks Id System
2.创建阵列
mdadm可以支持LINEAR、RAID0 (striping)、 RAID1(mirroring)、 RAID4、RAID5、RAID6和MULTIPATH的阵列模式。
命令格式:
mdadm --create device -chunk=X --level=Y --raid-devices=Z devices
[root@ ~]# mdadm --create /dev/md0 --level=5 --raid-devices=3 /dev/sdb /dev/sdc /dev/sdd mdadm: array /dev/md0 started.
--level表示创建的阵列模式,--raid-devices表示参与阵列的磁盘数量
3.配置文件
[root@ ~]#cp /usr/share/doc/mdadm-2.5.4/mdadm.conf-example /etc/mdadm.conf [root@ ~]#echo DEVICE /dev/sd[bcd]1 >>/etc/mdadm.conf [root@ ~]#mdadm -Ds >>/etc/mdadm.conf
4.格式化Raid
接下来,只要把/dev/md0作为一个单独的磁盘设备进行操作就可以:
[root@ ~]# mkfs.ext3 /dev/md0 mke2fs 1.39 (29-May-2006) Filesystem label= OS type: Linux Block size=4096 (log=2) Fragment size=4096 (log=2) 2097152 inodes, 4194272 blocks 209713 blocks (5.00%) reserved for the super user First data block=0 Maximum filesystem blocks=0 128 block groups 32768 blocks per group, 32768 fragments per group 16384 inodes per group Superblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 4096000 Writing inode tables: done Creating journal (32768 blocks): done Writing superblocks and filesystem accounting information: done This filesystem will be automatically checked every 36 mounts or 180 days, whichever comes first. Use tune2fs -c or -i to override. [root@ ~]# mkdir /mnt/software [root@ ~]# mount /dev/md0 /mnt/software
5. 开机自动挂载
更改/etc/fstab文件,添加一行
/dev/md0 /mnt/software ext3 defaults 0 0
二. 其他的操作
mdadm有7中模式,下面列出了7种模式的命令格式,详细的选项,请参考man手册。
ASSEMBLE MODE :madam --assemble md-device options-and-component-devices
mdadm --assembel --scan md-devices-and-options
mdamd --assembel --scan options
BUILD MODE: mdadm --build device --chunk=X --level=Y --raid-devices=Z devices
CREATE MODE: mdadm --create device --chunk=X --level=Y --raid-devices=Z devices
MANAGE MODE: mdadm device options devices
MISC MODE: mdadm options ... devices ...
MONITOR MODE: mdadm --monitor options... devices...
GROW MODE:
1.查看
MISC模式
#mdadm --detail /dev/md0 #mdadm -D /dev/md0
2.停止
MISC模式
#mdadm -S /dev/md0
3.启动
ASSEMBLE模式
#mdadm -A /dev/md0 /dev/sd[bcd]1 启动指定的RAID,可以理解为将一个raid重新装配到系统中。 如果在前面已经配置了/etc/mdadm.conf文件,可以使用: #mdadm -As /dev/md0
4.添加删除磁盘
mdadm可以在Manage模式下,对运行中的阵列进行添加及删除磁盘。常用于标识failed磁盘,增加spare(冗余)磁盘,以及替换磁盘等。
[root@ ~]# mdadm /dev/md0 --fail /dev/sdd --remove /dev/sdd mdadm: set /dev/sdd faulty in /dev/md0 mdadm: hot removed /dev/sdd [root@ ~]# mdadm -D /dev/md0 /dev/md0: Version : 00.90.03 Creation Time : Fri Aug 1 21:35:31 2008 Raid Level : raid5 Array Size : 16777088 (16.00 GiB 17.18 GB) Device Size : 8388544 (8.00 GiB 8.59 GB) Raid Devices : 3 Total Devices : 2 Preferred Minor : 0 Persistence : Superblock is persistent Update Time : Fri Aug 1 23:34:12 2008 State : clean, degraded Active Devices : 2 Working Devices : 2 Failed Devices : 0 Spare Devices : 0 Layout : left-symmetric Chunk Size : 64K UUID : 28a22990:eac5c231:3fe907f1:1145e264 Events : 0.6 Number Major Minor RaidDevice State 0 8 16 0 active sync /dev/sdb 1 8 32 1 active sync /dev/sdc 2 0 0 2 removed [root@ ~]# mdadm /dev/md0 --add /dev/sdd mdadm: re-added /dev/sdd [root@ ~]# mdadm -D /dev/md0 /dev/md0: Version : 00.90.03 Creation Time : Fri Aug 1 21:35:31 2008 Raid Level : raid5 Array Size : 16777088 (16.00 GiB 17.18 GB) Device Size : 8388544 (8.00 GiB 8.59 GB) Raid Devices : 3 Total Devices : 3 Preferred Minor : 0 Persistence : Superblock is persistent Update Time : Fri Aug 1 23:34:12 2008 State : clean, degraded, recovering Active Devices : 2 Working Devices : 3 Failed Devices : 0 Spare Devices : 1 Layout : left-symmetric Chunk Size : 64K Rebuild Status : 0% complete UUID : 28a22990:eac5c231:3fe907f1:1145e264 Events : 0.6 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 spare rebuilding /dev/sdd
--fail指定坏磁盘,--remove移走。
需要注意的是,对于某些RAID级别,如RAID0,是不能用--fail --remove --add的。
5.监控
MONITOR模式
# nohup mdadm --monitor --mail root --delay 200 /dev/md0 &
每200秒监控一次,当RAID出现错误时,发送邮件给root用户。
6.增加spare磁盘
可以通过在创建的时候指定冗余磁盘
#mdadm --create --verbose /dev/md0 --level=3 --raid-devices=3 -x1 /dev/sdb1 /dev/sdc1 /dev/sdd1 /dev/sde1