linux系统下
mdadm 参数
-C 创建
-a自动创建md0
-l 指定raid级别
-n 指定使用硬盘数量
-x 指定备份硬盘数量
mdadm -S /dev/md0 关闭RAID ,关掉之前要先卸载掉
mdadm -R /dev/md0 重新启动RAID,但是可能由于操作系统或者软件版本问题会找不到md0设备需要重启机器 (确保mdadm.conf已写好)
搭建raid5:
最少三块硬盘
- #mdadm -C /dev/md0 -a yes -l 5 -n 3 /dev/sd[b-d]
注意:这条命令执行完后,cat /proc/mdstat 查看创建进度,等到100%再进行下步操作
2. mdadm.conf 主要作用开机自动加载软raid
#mdadm -D --scan > /etc/mdadm.conf (稍加)
3.实验环境下可以用mdadm命令模拟raid故障
mdadm /dev/md0 -f /dev/sdd
# mdadm /dev/md0 -f /dev/sdd
mdadm: set /dev/sdd faulty in /dev/md0
[[email protected] ~]# mdadm -D /dev/md0
/dev/md0:
Version : 1.2
Creation Time : Sat May 25 23:07:06 2013
Raid Level : raid5
Array Size : 2095104 (2046.34 MiB 2145.39 MB)
Used Dev Size : 1047552 (1023.17 MiB 1072.69 MB)
Raid Devices : 3
Total Devices : 3
Persistence : Superblock is persistent
Update Time : Sat May 25 23:13:44 2013
State : clean, degraded
Active Devices : 2
Working Devices : 2
Failed Devices : 1
Spare Devices : 0
Layout : left-symmetric
Chunk Size : 512K
Name : xiaoluo:0 (local to host xiaoluo)
UUID : 029e2fe7:8c9ded40:f5079536:d249ccf7
Events : 19
Number Major Minor RaidDevice State
8 16 0 active sync /dev/sdb
8 32 1 active sync /dev/sdc
0 0 2 removed
8 48 - faulty spare /dev/sdd ##这块硬盘被标志成了坏的硬盘
4./dev/sdd 这块硬盘被标志成了坏的硬盘,因为我们使用的是RAID 5这个级别,所以一块硬盘损坏了,并不会对数据造成损坏,数据还是完好无整的
#mdadm /dev/md0 -r /dev/sdd 移除坏掉的硬盘
mdadm: hot removed /dev/sdd from /dev/md0
# mdadm -D /dev/md0 查看raid状态
/dev/md0:
Version : 1.2
Creation Time : Sat May 25 23:07:06 2013
Raid Level : raid5
Array Size : 2095104 (2046.34 MiB 2145.39 MB)
Used Dev Size : 1047552 (1023.17 MiB 1072.69 MB)
Raid Devices : 3
Total Devices : 2
Persistence : Superblock is persistent
Update Time : Sat May 25 23:17:12 2013
State : clean, degraded
Active Devices : 2
Working Devices : 2
Failed Devices : 0
Spare Devices : 0
Layout : left-symmetric
Chunk Size : 512K
Name : xiaoluo:0 (local to host xiaoluo)
UUID : 029e2fe7:8c9ded40:f5079536:d249ccf7
Events : 22
Number Major Minor RaidDevice State
8 16 0 active sync /dev/sdb
8 32 1 active sync /dev/sdc
0 0 2 removed ##/dev/sdd 已经被移除掉了
5.如果我们要换上新的硬盘,则可以使用 mdadm /dev/md0 -a /dev/sde 这个命令
# mdadm /dev/md0 -a /dev/sde
mdadm: added /dev/sde
# mdadm -D /dev/md0
/dev/md0:
Version : 1.2
Creation Time : Sat May 25 23:07:06 2013
Raid Level : raid5
Array Size : 2095104 (2046.34 MiB 2145.39 MB)
Used Dev Size : 1047552 (1023.17 MiB 1072.69 MB)
Raid Devices : 3
Total Devices : 3
Persistence : Superblock is persistent
Update Time : Sat May 25 23:19:15 2013
State : clean, degraded, recovering
Active Devices : 2
Working Devices : 3
Failed Devices : 0
Spare Devices : 1
Layout : left-symmetric
Chunk Size : 512K
Rebuild Status : 90% complete
Name : xiaoluo:0 (local to host xiaoluo)
UUID : 029e2fe7:8c9ded40:f5079536:d249ccf7
Events : 40
Number Major Minor RaidDevice State
8 16 0 active sync /dev/sdb
8 32 1 active sync /dev/sdc
8 64 2 spare rebuilding /dev/sde ##新的/dev/sde硬盘已经增加进来了