mdadm 创建 Raid 5 并实现开机自动挂载的步骤:
-----------------------------------------------------------------------------------------------------
1.创建Raid5:
root@ext3:~# mdadm -Cv /dev/md5 -l5 -n4 /dev/sd[bcde]
mdadm: layout defaults to left-symmetric
mdadm: chunk size defaults to 64K
mdadm: size set to 8388544K
mdadm: array /dev/md5 started.
------------------------------------------------------------------------------------------------------
2.查看创建的状态
root@ext3:~# cat /proc/mdstat
Personalities : [linear] [multipath] [raid0] [raid1] [raid6] [raid5] [raid4] [raid10]
md5 : active raid5 sde[4] sdd[2] sdc[1] sdb[0]
25165632 blocks level 5, 64k chunk, algorithm 2 [4/3] [UUU_]
[===================>.] recovery = 97.2% (8156160/8388544) finish=0.0min speed=56856K/sec
unused devices:
-----------------------------------------------------------------------------------------------------
3.查看Raid信息:
root@ext3:~# mdadm -D /dev/md5
/dev/md5:
Version : 00.90
Creation Time : Tue Dec 20 10:14:58 2011
Raid Level : raid5 -------------------------->阵列级别;
Array Size : 25165632 (24.00 GiB 25.77 GB)---------->阵列容量大小;
Used Dev Size : 8388544 (8.00 GiB 8.59 GB)------------->Raid单位成员容量大小;【硬盘或分区大小】
Raid Devices : 4 -------------------------------->Raid成员个数
Total Devices : 4 -------------------------------->Raid中下属成员的总计个数
Preferred Minor : 5
Persistence : Superblock is persistent
Update Time : Tue Dec 20 10:17:39 2011
State : clean --------------------------------| 【1】
Active Devices : 4 --------------------------------->被激活的Raid成员个数
Working Devices : 4 --------------------------------->正常工作的成员个数
Failed Devices : 0 --------------------------------->出问题的成员个数
Spare Devices : 0 --------------------------------->备用Raid成员个数。自动替换有问题成员
Layout : left-symmetric
Chunk Size : 64K
UUID : 26d4210b:35eabd50:0e857feb:0ef1adb6 (local to host ext3) 系统中是唯一的
Events : 0.18
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 3 active sync /dev/sde |
【1】 Raid有三种状态:clean表示正常,degraded表示有问题,recovering表示正在恢复或构建;
----------------------------------------------------------------------------------------------------------
4.将Raid信息写入配置文件方便管理: mdadm -Ds >>/etc/mdadm/mdadm.conf
root@ext3:~# tail -1 /etc/mdadm/mdadm.conf
ARRAY /dev/md5 level=raid5 num-devices=4 UUID=26d4210b:35eabd50:0e857feb:0ef1adb6
重启raid -S 是停止 -A是激活
-----------------------------------------------------------------------------------------------------------
5.格式化Raid : mkfs.ext4 /dev/md5
-----------------------------------------------------------------------------------------------------------
6.挂载到目录 :mount /dev/md5 /data
root@ext3:~# mount |grep data
/dev/md5 on /data type ext4 (rw)
root@ext3:~# df -h /data
Filesystem Size Used Avail Use% Mounted on
/dev/md5 24G 172M 23G 1% /data
-----------------------------------------------------------------------------------------------------------
7.设置开机自动挂载:
root@ext3:~# echo "/dev/md5 /data ext4 defaults 0 0 " >>/etc/fstab
root@ext3:~# tail -1 /etc/fstab
/dev/md5 /data ext4 defaults 0 0
-----------------------------------------------------------------------------------------------------------
8.重启测试-------->OK
-----------------------------------------------------------------------------------------------------------
参数:
-V --verbose,显示创建过程中的详细事件
-l --level=Y Y表示Raid的级别 -nZ --RAID-devices=Z 表示Raid成员个数
-A --assemble 激活已存在的 raid -S --stop 停止正在运行的设备
-s --scan 扫描Raid设备 -D --detail 产看RAID的详细信息
-E --examine 查看RAID成员的详细信息 -f --fail 把设备列为问题设备
-r --remove 把Raid成员移出Raid -a --add 向raid中添加一个成员
--run 强制启动 --zero-superblock 清除超级块中的Raid信息
-C --create 创建(Raid信息写入Raid成员)
-----------------------------------------------------------------------------------------------------------
进阶:Raid(无损)扩充容量流程:
1.查看当前Raid信息:
root@ext3:~# mdadm -D /dev/md5
/dev/md5:
Version : 00.90
Creation Time : Tue Dec 20 10:14:58 2011
Raid Level : raid5
Array Size : 25165632 (24.00 GiB 25.77 GB)
Used Dev Size : 8388544 (8.00 GiB 8.59 GB)
Raid Devices : 4
Total Devices : 4
Preferred Minor : 5
Persistence : Superblock is persistent
Update Time : Tue Dec 20 11:24:22 2011
State : clean
Active Devices : 4
Working Devices : 4
Failed Devices : 0
Spare Devices : 0
Layout : left-symmetric
Chunk Size : 64K
UUID : 26d4210b:35eabd50:0e857feb:0ef1adb6 (local to host ext3)
Events : 0.18
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 3 active sync /dev/sde
-----------------------------------------------------------------------------------------------------------
2. 添加设备:root@ext3:~# mdadm /dev/md5 -a /dev/sdf
mdadm: added /dev/sdf
查看状态:
root@ext3:~# mdadm -D /dev/md5
/dev/md5:
Version : 00.90
Creation Time : Tue Dec 20 10:14:58 2011
Raid Level : raid5
Array Size : 25165632 (24.00 GiB 25.77 GB)
Used Dev Size : 8388544 (8.00 GiB 8.59 GB)
Raid Devices : 4
Total Devices : 5
Preferred Minor : 5
Persistence : Superblock is persistent
Update Time : Tue Dec 20 11:25:52 2011
State : clean
Active Devices : 4
Working Devices : 5
Failed Devices : 0
Spare Devices : 1 -------------------------->(此时未被加入到Raid阵列被认为是spare设备)
Layout : left-symmetric
Chunk Size : 64K
UUID : 26d4210b:35eabd50:0e857feb:0ef1adb6 (local to host ext3)
Events : 0.19
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 3 active sync /dev/sde
4 8 80 - spare /dev/sdf *状态是spare,备用成员
3. 此时容量未扩充,将备用成员成为真正的Raid成员--来实现扩容目的
用到的是Raid的Grow模式,增长模式(范围是RAID1、RAID4、RAID5、RAID6),
一个简单的指令把备用成员“推”到真正成员的位置上:
root@ext3:~# mdadm -G /dev/md5 -n5
mdadm: Need to backup 768K of critical section..
mdadm: ... critical section passed.
查看Raid的详细信息:
root@ext3:~# mdadm -D /dev/md5
/dev/md5:
Version : 00.91
Creation Time : Tue Dec 20 10:14:58 2011
Raid Level : raid5
Array Size : 25165632 (24.00 GiB 25.77 GB)
Used Dev Size : 8388544 (8.00 GiB 8.59 GB)
Raid Devices : 5
Total Devices : 5
Preferred Minor : 5
Persistence : Superblock is persistent
Update Time : Tue Dec 20 11:41:42 2011
State : clean, recovering
Active Devices : 5 --------------------------------------->正式成员变到5个
Working Devices : 5
Failed Devices : 0
Spare Devices : 0 --------------------------------------->减少到0;
Layout : left-symmetric
Chunk Size : 64K
Reshape Status : 16% complete
Delta Devices : 1, (4->5) --------------------------------->Raid正式成员增加一个,由4个到5个;
UUID : 26d4210b:35eabd50:0e857feb:0ef1adb6 (local to host ext3)
Events : 0.66
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 3 active sync /dev/sde
4 8 80 4 active sync /dev/sdf
扩充后要修改配置文件中的信息内容.