类型 | 读性能 | 写性能 | 可靠性 | 磁盘利用率 | 成本 |
---|---|---|---|---|---|
RAID0 | 最好 | 最好 | 最低 | 100% | 较低 |
RAID1 | 正常 | 两份数据 | 高 | 50% | 高 |
RAID5 | 近似RAID0 | 多了校验 | 介于RAID0和RAID1之间 | (n-1)/n | 介于RAID0和RAID1之间 |
RAID6 | 近似RAID0 | 多了双重校验 | 大于RAID5 | (n-2)/n | 大于RAID1 |
RAID10 | 等于RAID0 | 等于RAID1 | 高 | 50% | 最高 |
RAID01 | 等于RAID0 | 等于RAID1 | 高 | 50% | 最高 |
软RAID运行于操作系统底层,将SCSI或者IDE控制器提交上来的物理磁盘,虚拟成虚拟磁盘,再提交给管理程序来进行管理。
软RAID有以下特点:
通过用硬件来实现RAID功能的就是硬RAID,独立的RAID卡,主板集成的RAID芯片都是硬RAID。
RAID卡就是用来实现RAID功能的板卡,通常是由I/O处理器、硬盘控制器、硬盘连接器和缓存等一系列零组件构成的。
不同的RAID卡支持的RAID功能不同。支持RAlD0、RAID1、RAID5、RAID10不等。
[root@server1 ~]# fdisk /dev/sdc
[root@server1 ~]# partprobe /dev/sdc
[root@server1 ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 20G 0 disk
├─sda1 8:1 0 1G 0 part /boot
└─sda2 8:2 0 19G 0 part
├─centos-root 253:0 0 17G 0 lvm /
└─centos-swap 253:1 0 2G 0 lvm [SWAP]
sdb 8:16 0 5G 0 disk
└─sdb1 8:17 0 2G 0 part
sdc 8:32 0 20G 0 disk
├─sdc1 8:33 0 2G 0 part
├─sdc2 8:34 0 2G 0 part
├─sdc3 8:35 0 2G 0 part
├─sdc4 8:36 0 1K 0 part
├─sdc5 8:37 0 2G 0 part
├─sdc6 8:38 0 2G 0 part
├─sdc7 8:39 0 2G 0 part
├─sdc8 8:40 0 2G 0 part
├─sdc9 8:41 0 2G 0 part
├─sdc10 8:42 0 2G 0 part
└─sdc11 8:43 0 2G 0 part
sr0 11:0 1 973M 0 rom
[root@server1 ~]# yum install -y mdadm
参数 | 作用 |
---|---|
-a | 检测设备名称 |
-n | 指定设备数量 |
-l | 指定RAID级别 |
-C | 创建 |
-v | 显示过程 |
-f | 模拟设备损坏 |
-r | 移除设备 |
-Q | 查看摘要信息 |
-D | 查看详细信息 |
-S | 停止RAID磁盘阵列 |
-x | 指定热备盘数量 |
创建raid0
[root@server1 ~]# mdadm -C /dev/md0 -l 0 -n 2 /dev/sdc1 /dev/sdc2
mdadm: Defaulting to version 1.2 metadata
mdadm: array /dev/md0 started.
[root@server1 ~]# mdadm -D /dev/md0
/dev/md0:
Version : 1.2
Creation Time : Thu Sep 2 23:25:16 2021
Raid Level : raid0
Array Size : 4188160 (3.99 GiB 4.29 GB)
Raid Devices : 2
Total Devices : 2
Persistence : Superblock is persistent
Update Time : Thu Sep 2 23:25:16 2021
State : clean
Active Devices : 2
Working Devices : 2
Failed Devices : 0
Spare Devices : 0
Chunk Size : 512K
Consistency Policy : none
Name : server1:0 (local to host server1)
UUID : 2e5a48fa:87654810:3460dfd6:1d4951d5
Events : 0
Number Major Minor RaidDevice State
0 8 33 0 active sync /dev/sdc1
1 8 34 1 active sync /dev/sdc2
格式化
[root@server1 ~]# mkfs.xfs /dev/md0
meta-data=/dev/md0 isize=512 agcount=8, agsize=130944 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0, sparse=0
data = bsize=4096 blocks=1047040, imaxpct=25
= sunit=128 swidth=256 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal log bsize=4096 blocks=2560, version=2
= sectsz=512 sunit=8 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
挂载
[root@server1 ~]# mkdir /mnt/mnt_md0
[root@server1 ~]# mount /dev/md0 /mnt/mnt_md0/
测试
#复制终端,用于监测
[root@server1 ~]# yum install -y sysstat
[root@server1 ~]# iostat -m -d /dev/sdc[12] 3
[root@server1 ~]# dd if=/dev/zero of=/mnt/mnt_md0/bigfile bs=1M count=1024
Device: tps MB_read/s MB_wrtn/s MB_read MB_wrtn
sdc1 156.00 0.00 77.84 0 233
sdc2 155.67 0.00 77.83 0 233
Device: tps MB_read/s MB_wrtn/s MB_read MB_wrtn
sdc1 140.33 0.00 70.17 0 210
sdc2 140.33 0.00 70.17 0 210
Device: tps MB_read/s MB_wrtn/s MB_read MB_wrtn
sdc1 45.33 0.00 22.67 0 68
sdc2 45.33 0.00 22.67 0 68
永久保存RAID0信息
[root@server1 ~]# echo "/dev/md0 /mnt/mnt_md0 xfs defaults 0 0" >> /etc/fstab
创建raid1
[root@server1 ~]# mdadm -C /dev/md1 -l 1 -n 2 /dev/sdc3 /dev/sdc5
mdadm: Note: this array has metadata at the start and
may not be suitable as a boot device. If you plan to
store '/boot' on this device please ensure that
your boot-loader understands md/v1.x metadata, or use
--metadata=0.90
Continue creating array? y #输入y,同意即可
mdadm: Defaulting to version 1.2 metadata
mdadm: array /dev/md1 started.
查看状态信息
[root@server1 ~]# cat /proc/mdstat
Personalities : [raid0] [raid1]
md1 : active raid1 sdc5[1] sdc3[0]
2094080 blocks super 1.2 [2/2] [UU]
md0 : active raid0 sdc2[1] sdc1[0]
4188160 blocks super 1.2 512k chunks
unused devices:
[root@server1 ~]# mdadm -D /dev/md1
/dev/md1:
Version : 1.2
Creation Time : Thu Sep 2 23:43:43 2021
Raid Level : raid1
Array Size : 2094080 (2045.00 MiB 2144.34 MB)
Used Dev Size : 2094080 (2045.00 MiB 2144.34 MB)
Raid Devices : 2
Total Devices : 2
Persistence : Superblock is persistent
Update Time : Thu Sep 2 23:43:54 2021
State : clean
Active Devices : 2
Working Devices : 2
Failed Devices : 0
Spare Devices : 0
Consistency Policy : resync
Name : server1:1 (local to host server1)
UUID : bc67728d:e1c60a3c:8d445c5d:67a55444
Events : 17
Number Major Minor RaidDevice State
0 8 35 0 active sync /dev/sdc3
1 8 37 1 active sync /dev/sdc5
格式化
[root@server1 ~]# mkfs.xfs /dev/md1
meta-data=/dev/md1 isize=512 agcount=4, agsize=130880 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0, sparse=0
data = bsize=4096 blocks=523520, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal log bsize=4096 blocks=2560, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
挂载
[root@server1 ~]# mkdir /mnt/mnt_md1
[root@server1 ~]# mount /dev/md1 /mnt/mnt_md1
[root@server1 ~]# df -Th
文件系统 类型 容量 已用 可用 已用% 挂载点
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.9G 16G 11% /
/dev/sda1 xfs 1014M 194M 821M 20% /boot
tmpfs tmpfs 182M 0 182M 0% /run/user/0
/dev/md0 xfs 4.0G 33M 4.0G 1% /mnt/mnt_md0
/dev/md1 xfs 2.0G 33M 2.0G 2% /mnt/mnt_md1
测试(热插拔)
#模拟数据
[root@server1 ~]# touch /mnt/mnt_md1/file{1..5}
#模拟故障
[root@server1 ~]# mdadm /dev/md1 -f /dev/sdc3
mdadm: set /dev/sdc3 faulty in /dev/md1
[root@server1 ~]# cat /proc/mdstat
Personalities : [raid0] [raid1]
md1 : active raid1 sdc5[1] sdc3[0](F) F表示失效
2094080 blocks super 1.2 [2/1] [_U] _表示有一块盘失效
md0 : active raid0 sdc2[1] sdc1[0]
4188160 blocks super 1.2 512k chunks
unused devices:
[root@server1 ~]# mdadm -D /dev/md1
/dev/md1:
Version : 1.2
Creation Time : Thu Sep 2 23:43:43 2021
Raid Level : raid1
Array Size : 2094080 (2045.00 MiB 2144.34 MB)
Used Dev Size : 2094080 (2045.00 MiB 2144.34 MB)
Raid Devices : 2
Total Devices : 2
Persistence : Superblock is persistent
Update Time : Thu Sep 2 23:57:53 2021
State : clean, degraded
Active Devices : 1
Working Devices : 1
Failed Devices : 1
Spare Devices : 0
Consistency Policy : resync
Name : server1:1 (local to host server1)
UUID : bc67728d:e1c60a3c:8d445c5d:67a55444
Events : 19
Number Major Minor RaidDevice State
- 0 0 0 removed
1 8 37 1 active sync /dev/sdc5
0 8 35 - faulty /dev/sdc3
#移除失效盘
[root@server1 ~]# mdadm /dev/md1 -r /dev/sdc3
mdadm: hot removed /dev/sdc3 from /dev/md1
[root@server1 ~]# cat /proc/mdstat
Personalities : [raid0] [raid1]
md1 : active raid1 sdc5[1]
2094080 blocks super 1.2 [2/1] [_U]
md0 : active raid0 sdc2[1] sdc1[0]
4188160 blocks super 1.2 512k chunks
unused devices:
#不影响读写数据
[root@server1 ~]# touch /mnt/mnt_md1/test1
[root@server1 ~]# ls /mnt/mnt_md1
file1 file2 file3 file4 file5 test1
#加入新磁盘(热插)
[root@server1 ~]# mdadm /dev/md1 -a /dev/sdc6
mdadm: added /dev/sdc6
[root@server1 ~]# cat /proc/mdstat
Personalities : [raid0] [raid1]
md1 : active raid1 sdc6[2] sdc5[1]
2094080 blocks super 1.2 [2/2] [UU]
md0 : active raid0 sdc2[1] sdc1[0]
4188160 blocks super 1.2 512k chunks
unused devices:
永久保存RAID1信息
[root@server1 ~]# echo "/dev/md1 /mnt/mnt_md1 xfs defaults 0 0" >> /etc/fstab
创建RAID5(预留一块热备盘)
[root@server1 ~]# mdadm -C /dev/md5 -l 5 -n 3 -x 1 /dev/sdc{7,8,9,10}
mdadm: Defaulting to version 1.2 metadata
mdadm: array /dev/md5 started.
[root@server1 ~]# cat /proc/mdstat
Personalities : [raid0] [raid1] [raid6] [raid5] [raid4]
md5 : active raid5 sdc9[4] sdc10[3](S) sdc8[1] sdc7[0]
4188160 blocks super 1.2 level 5, 512k chunk, algorithm 2 [3/3] [UUU]
md1 : active raid1 sdc6[2] sdc5[1]
2094080 blocks super 1.2 [2/2] [UU]
md0 : active raid0 sdc2[1] sdc1[0]
4188160 blocks super 1.2 512k chunks
unused devices:
[root@server1 ~]# mdadm -D /dev/md5
/dev/md5:
Version : 1.2
Creation Time : Fri Sep 3 00:11:41 2021
Raid Level : raid5
Array Size : 4188160 (3.99 GiB 4.29 GB)
Used Dev Size : 2094080 (2045.00 MiB 2144.34 MB)
Raid Devices : 3
Total Devices : 4
Persistence : Superblock is persistent
Update Time : Fri Sep 3 00:11:54 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 : server1:5 (local to host server1)
UUID : 0536fd77:e916c80b:f7e945cf:a4d4d0f2
Events : 18
Number Major Minor RaidDevice State
0 8 39 0 active sync /dev/sdc7
1 8 40 1 active sync /dev/sdc8
4 8 41 2 active sync /dev/sdc9
3 8 42 - spare /dev/sdc10
格式化
[root@server1 ~]# mkfs.ext4 /dev/md5
挂载
[root@server1 ~]# mount /dev/md5 /mnt/mnt_md5
[root@server1 ~]# df -Th
文件系统 类型 容量 已用 可用 已用% 挂载点
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.9G 16G 11% /
/dev/sda1 xfs 1014M 194M 821M 20% /boot
tmpfs tmpfs 182M 0 182M 0% /run/user/0
/dev/md0 xfs 4.0G 33M 4.0G 1% /mnt/mnt_md0
/dev/md1 xfs 2.0G 33M 2.0G 2% /mnt/mnt_md1
/dev/md5 ext4 3.9G 16M 3.7G 1% /mnt/mnt_md5
测试
#模拟故障
[root@server1 ~]# mdadm /dev/md5 -f /dev/sdc7
mdadm: set /dev/sdc7 faulty in /dev/md5
[root@server1 ~]# cat /proc/mdstat
Personalities : [raid0] [raid1] [raid6] [raid5] [raid4]
md5 : active raid5 sdc9[4] sdc10[3] sdc8[1] sdc7[0](F)
4188160 blocks super 1.2 level 5, 512k chunk, algorithm 2 [3/3] [UUU]
[root@server1 ~]# mdadm -D /dev/md5
/dev/md5:
Version : 1.2
Creation Time : Fri Sep 3 00:11:41 2021
Raid Level : raid5
Array Size : 4188160 (3.99 GiB 4.29 GB)
Used Dev Size : 2094080 (2045.00 MiB 2144.34 MB)
Raid Devices : 3
Total Devices : 4
Persistence : Superblock is persistent
Update Time : Fri Sep 3 00:19:14 2021
State : clean
Active Devices : 3
Working Devices : 3
Failed Devices : 1
Spare Devices : 0
Layout : left-symmetric
Chunk Size : 512K
Consistency Policy : resync
Name : server1:5 (local to host server1)
UUID : 0536fd77:e916c80b:f7e945cf:a4d4d0f2
Events : 37
Number Major Minor RaidDevice State
3 8 42 0 active sync /dev/sdc10
1 8 40 1 active sync /dev/sdc8
4 8 41 2 active sync /dev/sdc9
0 8 39 - faulty /dev/sdc7
#移除失效盘
[root@server1 ~]# mdadm /dev/md5 -r /dev/sdc7
mdadm: hot removed /dev/sdc7 from /dev/md5
[root@server1 ~]# cat /proc/mdstat
Personalities : [raid0] [raid1] [raid6] [raid5] [raid4]
md5 : active raid5 sdc9[4] sdc10[3] sdc8[1]
4188160 blocks super 1.2 level 5, 512k chunk, algorithm 2 [3/3] [UUU]
[root@server1 ~]# cat /proc/mdstat
Personalities : [raid0] [raid1] [raid6] [raid5] [raid4]
md5 : active raid5 sdc9[4] sdc10[3] sdc8[1]
4188160 blocks super 1.2 level 5, 512k chunk, algorithm 2 [3/3] [UUU]
#添加热备盘
[root@server1 ~]# mdadm /dev/md5 -a /dev/sdc3
mdadm: added /dev/sdc3
[root@server1 ~]# cat /proc/mdstat
Personalities : [raid0] [raid1] [raid6] [raid5] [raid4]
md5 : active raid5 sdc3[5](S) sdc9[4] sdc10[3] sdc8[1]
4188160 blocks super 1.2 level 5, 512k chunk, algorithm 2 [3/3] [UUU]
永久保存RAID1信息
[root@server1 ~]# echo "/dev/md5 /mnt/mnt_md5 ext4 defaults 0 0" >> /etc/fstab
停止(以RAID0为例)
[root@server1 ~]# umount /mnt/mnt_md0
[root@server1 ~]# mdadm --stop /dev/md0
mdadm: stopped /dev/md0
启动
[root@server1 ~]# mdadm -A /dev/md0 /dev/sdc[12]
mdadm: /dev/md0 has been started with 2 drives.
#以RAID1为例
解挂
[root@server1 ~]# umount /dev/md1
停止运行
[root@server1 ~]# mdadm --stop /dev/md1
mdadm: stopped /dev/md1
删除/etc/fstab中的相关内容
[root@server1 ~]# vim /etc/fstab
#/dev/md1 /mnt/mnt_md1 ext4 defaults 0 0
删除元数据
[root@server1 ~]# mdadm --zero-superblock /dev/sdc[56]