Linux实现最常用的磁盘阵列(2)

3、格式化、挂载、使用/dev/md0:

[root@localhost ~]# mkfs.ext4 /dev/md0 #将/dev/md0格式化

[root@localhost ~]# mkdir /raid5 ##创建挂载目录

[root@localhost ~]# mount /dev/md0 /raid5/ #挂载/dev/md0到/raid5目录下

[root@localhost ~]# cd /raid5/

[root@localhost raid5]# touch raid5.file

[root@localhost raid5]# ls

lost+found raid5.file

4、设置开机启动RAID5:

[root@localhost ~]# mdadm --detail --scan #查看raid简要信息

ARRAY /dev/md0 metadata=1.2 spares=1 name=localhost.localdomain:0 UUID=f16324c8:0f2a0be2:04c57c07:5f44f53e

[root@localhost ~]# mdadm --detail --scan >/etc/mdadm.conf #创建软raid的配置文件!注意:此文件如果不创建下次开机重启后/dev/md0将会被系统自动识别为其他非/dev/md0名称的设备,对于实现开机挂载和使用都不方便。

[root@localhost ~]# vim /etc/fstab #编辑fstab文件添加如下行

/dev/md0 /raid5 ext4 defaults 0 0

4、管理RAID5:

查看raid的状态:

[root@localhost ~]# cat /proc/mdstat #查看raid的状态

Personalities : [raid6] [raid5] [raid4]

md0 : active raid5 sdb8[5] sdb9[4](S) sdb7[2] sdb6[1] sdb5[0]

9414144 blocks super 1.2 level 5, 512k chunk, algorithm 2 [4/4] [UUUU]

unused devices: <none>

查看特定raid设备的详细信息:

[root@localhost ~]# mdadm --detail /dev/md0

……………………………………………省略………………………………………………..

Number Major Minor RaidDevice State

0 8 21 0 active sync /dev/sdb5

1 8 22 1 active sync /dev/sdb6

2 8 23 2 active sync /dev/sdb7

5 8 24 3 active sync /dev/sdb8

4 8 25 - spare /dev/sdb9

模拟硬盘损坏:

[root@localhost ~]# mdadm /dev/md0 --fail /dev/sdb5 #模拟硬盘损坏

[root@localhost ~]# mdadm –detail #验证

……………………………………………省略………………………………………………..

Name : localhost.localdomain:0 (local to host localhost.localdomain)

UUID : f16324c8:0f2a0be2:04c57c07:5f44f53e

Events : 25

Number Major Minor RaidDevice State

4 8 25 0 spare rebuilding /dev/sdb9

1 8 22 1 active sync /dev/sdb6

2 8 23 2 active sync /dev/sdb7

5 8 24 3 active sync /dev/sdb8

0 8 21 - faulty spare /dev/sdb5

####/dev/sdb5的状态变成了faulty,/dev/sdb9则立即变成active

模拟拔出硬盘:

[root@localhost ~]# mdadm /dev/md0 --remove /dev/sdb5 #模拟拔出硬盘

mdadm: hot removed /dev/sdb5 from /dev/md0

[root@localhost ~]# mdadm –detail #验证

……………………………………………省略………………………………………………..

Name : localhost.localdomain:0 (local to host localhost.localdomain)

UUID : f16324c8:0f2a0be2:04c57c07:5f44f53e

Events : 4

Number Major Minor RaidDevice State

4 8 25 0 active sync /dev/sdb9

1 8 22 1 active sync /dev/sdb6

2 8 23 2 active sync /dev/sdb7

5 8 24 3 active sync /dev/sdb8

####/dev/sdb5已经从/dev/md0中消失了:

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:http://www.heiqu.com/a67fc1315ece1ae3d1f6a93482de0ea8.html