RAID10磁盘阵列尽管会造成50%磁盘的浪费,但是实现了硬盘读写速度的提升,同时也实现了数据安全性的效果,在生产中应用最为广泛。
部署磁盘阵列的核心命令为mdadm。
1、RAID10磁盘阵列的部署至少需要4块硬盘,首先在虚拟机中添加4块硬盘(关闭系统后添加)
2、在/dev/目录查看是否有硬盘
[root@PC1linuxprobe dev]# cd /dev
[root@PC1linuxprobe dev]# find sd*
sda
sda1
sda2
sdb
sdc
sdd
sde
3、部署RAID10磁盘阵列
[root@PC1linuxprobe dev]# mdadm -Cv /dev/md0 -a yes -n 4 -l 10 /dev/sdb /dev/sdc /dev/sdd /dev/sde ## 其中-a yes参数表示自动创建设备文件,/dev/md0为部署的RAID10磁盘阵列
mdadm: layout defaults to n2
mdadm: layout defaults to n2
mdadm: chunk size defaults to 512K
mdadm: size set to 20954624K
mdadm: Defaulting to version 1.2 metadata
mdadm: array /dev/md0 started.
[root@PC1linuxprobe dev]# pwd
/dev
[root@PC1linuxprobe dev]# find md*
md0
[root@PC1linuxprobe dev]# ll md0
brw-rw----. 1 root disk 9, 0 Nov 8 00:00 md0
4、将RAID10磁盘阵列格式化为ext4格式
[root@PC1linuxprobe dev]# mkfs.ext4 /dev/md0 mke2fs 1.42.9 (28-Dec-2013) Filesystem label= OS type: Linux Block size=4096 (log=2) Fragment size=4096 (log=2) Stride=128 blocks, Stripe width=256 blocks 2621440 inodes, 10477312 blocks 523865 blocks (5.00%) reserved for the super user First data block=0 Maximum filesystem blocks=2157969408 320 block groups 32768 blocks per group, 32768 fragments per group 8192 inodes per group Superblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 4096000, 7962624 Allocating group tables: done Writing inode tables: done Creating journal (32768 blocks): done Writing superblocks and filesystem accounting information: done
5、将/dev/md0磁盘阵列进行挂载
[root@PC1linuxprobe dev]# mkdir /RAID10
[root@PC1linuxprobe dev]# mount /dev/md0 /RAID10
[root@PC1linuxprobe dev]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/rhel-root 18G 2.9G 15G 17% /
devtmpfs 985M 0 985M 0% /dev
tmpfs 994M 140K 994M 1% /dev/shm
tmpfs 994M 8.9M 986M 1% /run
tmpfs 994M 0 994M 0% /sys/fs/cgroup
/dev/sda1 497M 119M 379M 24% /boot
/dev/sr0 3.5G 3.5G 0 100% /run/media/root/RHEL-7.0 Server.x86_64
/dev/md0 40G 49M 38G 1% /RAID10
6、使用mdadm -D 命令查看磁盘阵列的详细信息
[root@PC1linuxprobe dev]# mdadm -D /dev/md0
/dev/md0:
Version : 1.2
Creation Time : Sun Nov 8 00:00:09 2020
Raid Level : raid10
Array Size : 41909248 (39.97 GiB 42.92 GB)
Used Dev Size : 20954624 (19.98 GiB 21.46 GB)
Raid Devices : 4
Total Devices : 4
Persistence : Superblock is persistent
Update Time : Sun Nov 8 10:22:04 2020
State : clean
Active Devices : 4
Working Devices : 4
Failed Devices : 0
Spare Devices : 0
Layout : near=2
Chunk Size : 512K
Name : PC1linuxprobe:0 (local to host PC1linuxprobe)
UUID : 4ef4bd32:95970b62:b488f16b:6627dd99
Events : 17
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
7、 写入开启自动挂载项
[root@PC1linuxprobe dev]# echo -e "/dev/md0\t/RAID10\text4\tdefaults\t0\t0" >> /etc/fstab
[root@PC1linuxprobe dev]# cat /etc/fstab
#
# /etc/fstab
# Created by anaconda on Thu Nov 5 15:23:01 2020
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
/dev/mapper/rhel-root / xfs defaults 1 1
UUID=0ba20ae9-dd51-459f-ac48-7f7e81385eb8 /boot xfs defaults 1 2
/dev/mapper/rhel-swap swap swap defaults 0 0
/dev/md0 /RAID10 ext4 defaults 0 0
8、总结制作RAID10磁盘阵列的步骤
- RAID10磁盘阵列至少需要四块硬盘,准备四块硬盘
- 使用 mdadm命令制作RAID10磁盘阵列,mdadm -Cv /dev/name -a yes -n 4 -l 10 /dev/disk1 /dev/disk2 /dev/disk3 /dev/disk4
- 将/dev/name磁盘阵列格式化ext4文件系统,mkfs.ext4 /dev/name
- 将格式化后的磁盘阵列进行挂载,mkdir /mountpoint ; mount /dev/name /mountpoint,可以使用df -h查看
- 将挂载后的RAID10磁盘阵列写入到开机自动挂载项:echo -e "/dev/name\t/mountpoint\text4\tdefaults\t0\t0" >> /etc/fstab
如何停用RAID10磁盘阵列 ?
1、删除开机自动挂载项(非必须)
[root@PC1linuxprobe dev]# sed '$d' /etc/fstab -i ## 慎用,确保最后一行为开启自启项后使用,意思是非询问删除最后一行
[root@PC1linuxprobe dev]# cat /etc/fstab
#
# /etc/fstab
# Created by anaconda on Thu Nov 5 15:23:01 2020
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
/dev/mapper/rhel-root / xfs defaults 1 1
UUID=0ba20ae9-dd51-459f-ac48-7f7e81385eb8 /boot xfs defaults 1 2
/dev/mapper/rhel-swap swap swap defaults 0 0
2、卸载,删除挂载点
[root@PC1linuxprobe dev]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/rhel-root 18G 2.9G 15G 17% /
devtmpfs 985M 0 985M 0% /dev
tmpfs 994M 140K 994M 1% /dev/shm
tmpfs 994M 8.8M 986M 1% /run
tmpfs 994M 0 994M 0% /sys/fs/cgroup
/dev/sda1 497M 119M 379M 24% /boot
/dev/sr0 3.5G 3.5G 0 100% /run/media/root/RHEL-7.0 Server.x86_64
/dev/md0 40G 49M 38G 1% /RAID10
[root@PC1linuxprobe dev]# umount /RAID10/
[root@PC1linuxprobe dev]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/rhel-root 18G 2.9G 15G 17% /
devtmpfs 985M 0 985M 0% /dev
tmpfs 994M 140K 994M 1% /dev/shm
tmpfs 994M 8.8M 986M 1% /run
tmpfs 994M 0 994M 0% /sys/fs/cgroup
/dev/sda1 497M 119M 379M 24% /boot
/dev/sr0 3.5G 3.5G 0 100% /run/media/root/RHEL-7.0 Server.x86_64
[root@PC1linuxprobe dev]# rm -rf /RAID10/
3、停用/dev/md0磁盘阵列
[root@PC1linuxprobe dev]# pwd
/dev
[root@PC1linuxprobe dev]# find md0
md0
[root@PC1linuxprobe dev]# mdadm -S /dev/md0 ## 停用
mdadm: stopped /dev/md0
[root@PC1linuxprobe dev]# find md0
find: ‘md0’: No such file or directory
4、移除添加的硬盘,重启系统