5.1.3 创建raid
[root@centos7 Bash]$ mdadm -C /dev/md5 -a yes -l 5 -n 3 /dev/sd{b1,c1,d1} -c 256 # -C指定创建, -a yes 自动创建设备 , -l 设定level , -n 设定磁盘个数, -c chunk大小
Continue creating array? y
mdadm: Defaulting to version 1.2 metadata
mdadm: array /dev/md5 started.
[root@centos7 Bash]$ mdadm -Ds # 查看信息
ARRAY /dev/md5 metadata=1.2 name=centos7.magedu.com:5 UUID=2c8ae60d:a799fcb7:9008a046:ae6ea430
[root@centos7 Bash]$ mdadm -Ds >/etc/mdadm.conf # 将软raid信息写入到配置文件中去
[root@centos7 Bash]$ mkdir /mnt/md5 # 创建挂载点目录
[root@centos7 Bash]$ mkfs.ext4 /dev/md5 # 创建文件系统
mke2fs 1.42.9 (28-Dec-2013)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=64 blocks, Stripe width=128 blocks
131072 inodes, 523776 blocks
26188 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=536870912
16 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912
Allocating group tables: done
Writing inode tables: done
Creating journal (8192 blocks): done
Writing superblocks and filesystem accounting information: done
[root@centos7 Bash]$ mount /dev/md5 /mnt/md5 # 挂载设备
[root@centos7 Bash]$ tail -n 1 /etc/mtab
/dev/md5 /mnt/md5 ext4 rw,seclabel,relatime,stripe=128,data=ordered 0 0 # 查看挂载信息
[root@centos7 Bash]$ tail -n 1 /etc/mtab >>/etc/fstab #添加到fstab文件中,确保开机启动,这里建议使用uuid
5.1.4 验证raid
[root@centos7 md5]$ mdadm -D /dev/md5 #查看详细raid5详细信息,可以发现有3个都是working状态的
/dev/md5:
Version : 1.2
Creation Time : Wed Dec 6 19:28:22 2017
Raid Level : raid5
Array Size : 2095104 (2046.00 MiB 2145.39 MB)
Used Dev Size : 1047552 (1023.00 MiB 1072.69 MB)
Raid Devices : 3
Total Devices : 3
Persistence : Superblock is persistent
Update Time : Wed Dec 6 19:39:06 2017
State : clean
Active Devices : 3
Working Devices : 3
Failed Devices : 0
Spare Devices : 0
Layout : left-symmetric
Chunk Size : 256K
Consistency Policy : resync
Name : centos7.magedu.com:5 (local to host centos7.magedu.com)
UUID : 2c8ae60d:a799fcb7:9008a046:ae6ea430
Events : 18
Number Major Minor RaidDevice State
0 8 17 0 active sync /dev/sdb1
1 8 33 1 active sync /dev/sdc1
3 8 49 2 active sync /dev/sdd1
[root@centos7 md5]$ man mdadm
[root@centos7 md5]$ mdadm /dev/md5 -f /dev/sdc1 # -f 设定指定设备故障, 将/dev/sdc1 这个盘标记失败, 看是否数据能访问,我这里使用-f标记失败,工作中可以根据硬盘指示灯判断磁盘状态
mdadm: set /dev/sdc1 faulty in /dev/md5
[root@centos7 md5]$ mdadm -D /dev/md5 #在次查看信息,发现工作的是2个, 一个失败的设备
/dev/md5:
Version : 1.2
Creation Time : Wed Dec 6 19:28:22 2017
Raid Level : raid5
Array Size : 2095104 (2046.00 MiB 2145.39 MB)
Used Dev Size : 1047552 (1023.00 MiB 1072.69 MB)
Raid Devices : 3
Total Devices : 3
Persistence : Superblock is persistent
Update Time : Wed Dec 6 19:41:08 2017
State : clean, degraded # 这里注意了。 我们的一个盘坏掉了。 raid5状态为降级使用了。
Active Devices : 2
Working Devices : 2
Failed Devices : 1
Spare Devices : 0
Layout : left-symmetric
Chunk Size : 256K
Consistency Policy : resync
Name : centos7.magedu.com:5 (local to host centos7.magedu.com)
UUID : 2c8ae60d:a799fcb7:9008a046:ae6ea430
Events : 20
Number Major Minor RaidDevice State
0 8 17 0 active sync /dev/sdb1
- 0 0 1 removed
3 8 49 2 active sync /dev/sdd1
1 8 33 - faulty /dev/sdc1
[root@centos7 md5]$ cat a.txt # 发现我们的数据还是能访问的。没有问题。