RAID0和RAID5的创建和模拟RAID5工作原理
RAID0和RAID5创建过程和模拟RAID5工作原理
概述:
raid0:raid0是raid磁盘阵列中的最低等级,原理是通过将数据分割后向两个磁盘中同时写入数据而加快写入速度,磁盘损坏后数据容易丢失。
raid1:raid1称为磁盘镜像,原理是把一个磁盘的数据镜像到另一个磁盘上,也就是说数据在写入一块磁盘的同时,会在另一块闲置的磁盘上生成镜像文件,磁盘的可用性仅为总磁盘容量的一半。提供了数据的安全性但是降低了磁盘的可用性。
raid5:raid5(分布式奇偶校验的独立磁盘结构),最少使用三块磁盘,将数据分割后写入磁盘,并且在每个磁盘上都存在奇偶校验码,当一块磁盘出现问题,可以在更换磁盘后,利用其他磁盘的校验码恢复数据。
RAID0实验
#使用两块硬盘制作RAID0磁盘列阵
[root@centos7 ~]# mdadm -Cv /dev/md0 -l 0 -n 2 /dev/sd[b,c]
mdadm: chunk size defaults to 512K
mdadm: Defaulting to version 1.2 metadata
mdadm: array /dev/md0 started.
#格式化磁盘列阵
[root@centos7 ~]# mkfs.xfs /dev/md0
meta-data=/dev/md0 isize=512 agcount=16, agsize=654720 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0, sparse=0
data = bsize=4096 blocks=10475520, imaxpct=25
= sunit=128 swidth=256 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal log bsize=4096 blocks=5120, version=2
= sectsz=512 sunit=8 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
#创建挂载目录raid0
[root@centos7 ~]# mkdir /mnt/raid0
[root@centos7 ~]# mount /dev/md0 /mnt/raid0/
[root@centos7 ~]# df -Th
Filesystem Type Size Used Avail Use% Mounted on
devtmpfs devtmpfs 899M 0 899M 0% /dev
tmpfs tmpfs 910M 0 910M 0% /dev/shm
tmpfs tmpfs 910M 9.6M 901M 2% /run
tmpfs tmpfs 910M 0 910M 0% /sys/fs/cgroup
/dev/mapper/centos-root xfs 17G 1.6G 16G 9% /
/dev/sda1 xfs 1014M 194M 821M 20% /boot
tmpfs tmpfs 182M 0 182M 0% /run/user/0
/dev/md0 xfs 40G 33M 40G 1% /mnt/raid0
#查看RAID0信息并配置开机自动挂载
[root@centos7 ~]# echo "UUID=c8c19587-719d-44be-b5f3-cfebf946b049 /raid0 xfs defaults 0 0">>/
etc/fstab
[root@centos7 ~]# cat /etc/fstab
#
# /etc/fstab
# Created by anaconda on Fri Mar 26 17:01:57 2021
#
# 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/centos-root / xfs defaults 0 0
UUID=312ce7b8-226c-4f10-9f5f-3746c22e0380 /boot xfs defaults,uquota 0 0
/dev/mapper/centos-swap swap swap defaults 0 0
UUID=c8c19587-719d-44be-b5f3-cfebf946b049 /raid0 xfs defaults 0 0
#raid0磁盘列阵创建完成
RAID5实验
#添加4块硬盘,使用3个硬盘做磁盘列阵,1个硬盘做备份盘
[root@centos7 ~]# mdadm -Cv /dev/md5 -a yes -l 5 -n 3 /dev/sd[b,c,d] --spare-devices=1 /dev/sde
#查看磁盘挂载情况
[root@centos7 ~]# df -Th
Filesystem Type Size Used Avail Use% Mounted on
devtmpfs devtmpfs 899M 0 899M 0% /dev
tmpfs tmpfs 910M 0 910M 0% /dev/shm
tmpfs tmpfs 910M 9.6M 901M 2% /run
tmpfs tmpfs 910M 0 910M 0% /sys/fs/cgroup
/dev/mapper/centos-root xfs 17G 1.6G 16G 9% /
/dev/sda1 xfs 1014M 194M 821M 20% /boot
tmpfs tmpfs 182M 0 182M 0% /run/user/0
/dev/md5 xfs 40G 33M 40G 1% /mnt/raid5
#配置开机自动挂载
[root@centos7 ~]# echo "UUID=c8c19587-719d-44be-b5f3-cfebf946b049 /raid5 xfs defaults 0 0">> /etc/fstab
[root@centos7 ~]# cat /etc/fstab
#
# /etc/fstab
# Created by anaconda on Fri Mar 26 17:01:57 2021
#
# 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/centos-root / xfs defaults 0 0
UUID=312ce7b8-226c-4f10-9f5f-3746c22e0380 /boot xfs defaults,uquota 0 0
/dev/mapper/centos-swap swap swap defaults 0 0
UUID=c8c19587-719d-44be-b5f3-cfebf946b049 /raid5 xfs defaults 0 0
#测试备份盘的工作,模拟磁盘损坏
[root@centos7 ~]# mdadm -D /dev/md5
/dev/md5:
Version : 1.2
Creation Time : Mon Apr 5 20:38:12 2021
Raid Level : raid5
Array Size : 41908224 (39.97 GiB 42.91 GB)
Used Dev Size : 20954112 (19.98 GiB 21.46 GB)
Raid Devices : 3
Total Devices : 4
Persistence : Superblock is persistent
Update Time : Mon Apr 5 20:44:13 2021
State : clean
Active Devices : 3
Working Devices : 4
Failed Devices : 0
Spare Devices : 1
Layout : left-symmetric
Chunk Size : 512K
Consistency Policy : resync
Name : centos7:5 (local to host centos7)
UUID : 34c23472:a07b39ef:f9e5aceb:9cb85199
Events : 18
Number Major Minor RaidDevice State
0 8 16 0 active sync /dev/sdb
1 8 32 1 active sync /dev/sdc
4 8 48 2 active sync /dev/sdd
3 8 64 - spare /dev/sde
[root@centos7 ~]# mdadm -f /dev/md5 /dev/sdd
mdadm: set /dev/sdd faulty in /dev/md5
[root@centos7 ~]# mdadm -D /dev/md5
/dev/md5:
Version : 1.2
Creation Time : Mon Apr 5 20:38:12 2021
Raid Level : raid5
Array Size : 41908224 (39.97 GiB 42.91 GB)
Used Dev Size : 20954112 (19.98 GiB 21.46 GB)
Raid Devices : 3
Total Devices : 4
Persistence : Superblock is persistent
Update Time : Mon Apr 5 20:51:14 2021
State : clean, degraded, recovering
Active Devices : 2
Working Devices : 3
Failed Devices : 1
Spare Devices : 1
Layout : left-symmetric
Chunk Size : 512K
Consistency Policy : resync
Rebuild Status : 7% complete
Name : centos7:5 (local to host centos7)
UUID : 34c23472:a07b39ef:f9e5aceb:9cb85199
Events : 21
Number Major Minor RaidDevice State
0 8 16 0 active sync /dev/sdb
1 8 32 1 active sync /dev/sdc
3 8 64 2 spare rebuilding /dev/sde
4 8 48 - faulty /dev/sdd
#模拟完成
本文来自博客园,作者:knsec,转载请注明原文链接:https://www.cnblogs.com/knsec-cnblogs/p/16582269.html