独立冗余磁盘阵列 ----RAID
Posted 还行少年
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了独立冗余磁盘阵列 ----RAID相关的知识,希望对你有一定的参考价值。
RAID(独立冗余磁盘阵列)
把多块独立的物理硬盘按不同方式组合起来形成一个硬盘组(逻辑硬盘),从而提供比单个硬盘更高的存储性能和提供数据备份技术
RAID的作用(为什么要用RAID,RAID的场景)
提高存储性能
实现冗余
目前大中型企业都在使用的技术,RAID+LVM结合使用
常见RAID级别
RAID0:N块硬盘并行组合成一个新的逻辑盘,具有很高的数据传输率,百分百的磁盘利用率,但没有数据冗余
RAID1:N(偶数)块硬盘组合成一组镜像成本最高,只有百分之五十的磁盘利用率,但提供了很高的数据安全性和可用性
RAID5:N(N>=3)块硬盘组成阵列,(N-1)/N磁盘利用率,读性能很高,写性能相对不高,可靠性高,允许坏一块盘
RAID6:N(N>=4)块盘组成阵列,(N-2)/N磁盘利用率,读性能很高,写性能相对较差,可靠性高,允许坏两块盘
RAID1+0:N(偶数,N>=4)块盘两两镜像后,再组合成一个RAID0,性能高,可靠性高
对比项 | RAID 0 | RAID 1 | RAID 5 | RAID 6 | RAID1+0 |
---|---|---|---|---|---|
磁盘数 | >=2 | >=2 | >=3 | >=4 | >=4 |
磁盘利用率 | 100% | 50% | n-1/n | n-2/n | 50% |
校验盘 | 无 | 无 | 1 | 2 | 无 |
容错性 | 无 | 有 | 有 | 有 | 有 |
IO性能 | 高 | 低 | 较高 | 较高 | 中 |
硬RAID
全部通过用硬件来实现RAID功能的就是硬RAID
硬 RAID 就是用专门的RAID控制器(RAID 卡)将硬盘和电脑连接起来,RAID控制器负责将所有的RAID成员磁盘配置成一个虚拟的RAID磁盘卷。对于操作系统而言,他只能识别到由RAID控制器配置后的虚拟磁盘,而无法识别到组成RAID的各个成员盘
软RAID
通过用操作系统来完成RAID功能的就是软RAID
与硬RAID不同的是,软RAID的各个成员盘对于操作系统来说是可见的,但操作系统并不把各个成员盘呈现给用户,而只是把通过软件层配置好的虚拟RAID卷呈现给用户,使用户可以像使用一个普通磁盘一样使用RAID卷
软RAID配置
RAID0配置
1)首先添加两块硬盘
[root@localhost ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 80G 0 disk
├─sda1 8:1 0 1G 0 part /boot
└─sda2 8:2 0 79G 0 part
├─centos-root 253:0 0 75.1G 0 lvm /
└─centos-swap 253:1 0 3.9G 0 lvm [SWAP]
sdb 8:16 0 20G 0 disk
sdc 8:32 0 20G 0 disk
sr0 11:0 1 4.3G 0 rom
[root@localhost ~]#
2)创建RAID0
[root@localhost ~]# mdadm -C -v /dev/md0 -l 0 -n 2 /dev/sdb /dev/sdc
mdadm: chunk size defaults to 512K
mdadm: Defaulting to version 1.2 metadata
mdadm: array /dev/md0 started.
[root@localhost ~]#
3)查看详情
[root@localhost ~]# mdadm -D /dev/md0
/dev/md0:
Version : 1.2
Creation Time : Mon May 10 15:11:09 2021
Raid Level : raid0
Array Size : 41908224 (39.97 GiB 42.91 GB)
Raid Devices : 2
Total Devices : 2
Persistence : Superblock is persistent
Update Time : Mon May 10 15:11:09 2021
State : clean
Active Devices : 2
Working Devices : 2
Failed Devices : 0
Spare Devices : 0
Chunk Size : 512K
Consistency Policy : none
Name : localhost.localdomain:0 (local to host localhost.localdomain)
UUID : 82d7afee:4b9c8bbb:afa847d9:7782d837
Events : 0
Number Major Minor RaidDevice State
0 8 16 0 active sync /dev/sdb
1 8 32 1 active sync /dev/sdc
[root@localhost ~]#
4)将配置写入配置文件,以便后期随时启停
[root@localhost ~]# mdadm -Dsv /dev/md0 > /etc/mdadm.conf
[root@localhost ~]# cat /etc/mdadm.conf
ARRAY /dev/md0 level=raid0 num-devices=2 metadata=1.2 name=localhost.localdomain:0 UUID=82d7afee:4b9c8bbb:afa847d9:7782d837
devices=/dev/sdb,/dev/sdc
[root@localhost ~]#
5)格式化并挂载
[root@localhost ~]# mkdir /raid0
[root@localhost ~]# 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
[root@localhost ~]# mount /dev/md0 /raid0/
[root@localhost ~]# df -h
文件系统 容量 已用 可用 已用% 挂载点
/dev/mapper/centos-root 76G 5.0G 71G 7% /
devtmpfs 1.9G 0 1.9G 0% /dev
tmpfs 1.9G 0 1.9G 0% /dev/shm
tmpfs 1.9G 13M 1.9G 1% /run
tmpfs 1.9G 0 1.9G 0% /sys/fs/cgroup
/dev/sda1 1014M 179M 836M 18% /boot
tmpfs 378M 12K 378M 1% /run/user/42
tmpfs 378M 0 378M 0% /run/user/0
/dev/md0 40G 33M 40G 1% /raid0
[root@localhost ~]#
6)性能对比(实验次数少,数据可能不准确)
[root@localhost raid0]# dd if=/dev/zero of=./test bs=100M count=100
记录了100+0 的读入
记录了100+0 的写出
10485760000字节(10 GB)已复制,12.6503 秒,829 MB/秒
[root@localhost raid0]# cd
[root@localhost ~]# dd if=/dev/zero of=./test1 bs=100M count=100
记录了100+0 的读入
记录了100+0 的写出
10485760000字节(10 GB)已复制,111.381 秒,94.1 MB/秒
RAID1配置
1)创建raid1
[root@localhost ~]# mdadm -C -v /dev/md1 -l 1 -n 2 /dev/sdb /dev/sdc
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
mdadm: size set to 20954112K
Continue creating array? y
mdadm: Defaulting to version 1.2 metadata
mdadm: array /dev/md1 started.
[root@localhost ~]#
2)查看详情
[root@localhost ~]# mdadm -D /dev/md1
/dev/md1:
Version : 1.2
Creation Time : Mon May 10 16:07:08 2021
Raid Level : raid1
Array Size : 20954112 (19.98 GiB 21.46 GB)
Used Dev Size : 20954112 (19.98 GiB 21.46 GB)
Raid Devices : 2
Total Devices : 2
Persistence : Superblock is persistent
Update Time : Mon May 10 16:07:41 2021
State : clean, resyncing
Active Devices : 2
Working Devices : 2
Failed Devices : 0
Spare Devices : 0
Consistency Policy : resync
Resync Status : 91% complete
Name : localhost.localdomain:1 (local to host localhost.localdomain)
UUID : 9b401dd7:e84cb68f:339e77e9:d1ef11bb
Events : 14
Number Major Minor RaidDevice State
0 8 16 0 active sync /dev/sdb
1 8 32 1 active sync /dev/sdc
[root@localhost ~]#
3)将配置写入配置文件,以便后期随时启停
[root@localhost ~]# mdadm -Dsv /dev/md1 > /etc/mdadm.conf
[root@localhost ~]# cat /etc/mdadm.conf
ARRAY /dev/md1 level=raid1 num-devices=2 metadata=1.2 name=localhost.localdomain:1 UUID=9b401dd7:e84cb68f:339e77e9:d1ef11bb
devices=/dev/sdb,/dev/sdc
[root@localhost ~]#
4)格式化并挂载
[root@localhost dev]# mkfs.xfs -f /dev/md1
meta-data=/dev/md1 isize=512 agcount=4, agsize=1309632 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0, sparse=0
data = bsize=4096 blocks=5238528, 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@localhost dev]# mount /dev/md1 /raid1
[root@localhost dev]# df -h
文件系统 容量 已用 可用 已用% 挂载点
/dev/mapper/centos-root 76G 5.0G 71G 7% /
devtmpfs 1.9G 0 1.9G 0% /dev
tmpfs 1.9G 0 1.9G 0% /dev/shm
tmpfs 1.9G 13M 1.9G 1% /run
tmpfs 1.9G 0 1.9G 0% /sys/fs/cgroup
/dev/sda1 1014M 179M 836M 18% /boot
tmpfs 378M 12K 378M 1% /run/user/42
tmpfs 378M 0 378M 0% /run/user/0
/dev/md1 20G 33M 20G 1% /raid1
[root@localhost dev]#
5)验证可靠性
①创建一个1000M文件
[root@localhost raid1]# ll -h
总用量 1000M
-rw-r--r--. 1 root root 1000M 5月 10 16:25 test
[root@localhost raid1]# df -h
文件系统 容量 已用 可用 已用% 挂载点
/dev/mapper/centos-root 76G 5.0G 71G 7% /
devtmpfs 1.9G 0 1.9G 0% /dev
tmpfs 1.9G 0 1.9G 0% /dev/shm
tmpfs 1.9G 13M 1.9G 1% /run
tmpfs 1.9G 0 1.9G 0% /sys/fs/cgroup
/dev/sda1 1014M 179M 836M 18% /boot
tmpfs 378M 12K 378M 1% /run/user/42
tmpfs 378M 0 378M 0% /run/user/0
/dev/md1 20G 1.1G 19G 6% /raid1
[root@localhost raid1]#
②破坏其中一个磁盘
[root@localhost raid1]# mdadm /dev/md1 -f /dev/sdb
mdadm: set /dev/sdb faulty in /dev/md1
[root@localhost raid1]# mdadm -D /dev/md1
/dev/md1:
Version : 1.2
Creation Time : Mon May 10 16:07:08 2021
Raid Level : raid1
Array Size : 20954112 (19.98 GiB 21.46 GB)
Used Dev Size : 20954112 (19.98 GiB 21.46 GB)
Raid Devices : 2
Total Devices : 2
Persistence : Superblock is persistent
Update Time : Mon May 10 16:30:43 2021
State : clean, degraded
Active Devices : 1
Working Devices : 1
Failed Devices : 1
Spare Devices : 0
Consistency Policy : resync
Name : localhost.localdomain:1 (local to host localhost.localdomain)
UUID : 9b401dd7:e84cb68f:339e77e9:d1ef11bb
Events : 19
Number Major Minor RaidDevice State
- 0 0 0 removed
1 8 32 1 active sync /dev/sdc
0 8 16 - faulty /dev/sdb
[root@localhost raid1]#
③移除此磁盘,并添加一块新磁盘
[root@localhost raid1]# mdadm -r /dev/md1 /dev/sdb
mdadm: hot removed /dev/sdb from /dev/md1
[root@localhost raid1]# mdadm -D /dev/md1
/dev/md1:
Version : 1.2
Creation Time : Mon May 10 16:07:08 2021
Raid Level : raid1
Array Size : 20954112 (19.98 GiB 21.46 GB)
Used Dev Size : 20954112 (19.98 GiB 21.46 GB)
Raid Devices : 2
Total Devices : 1
Persistence : Superblock is persistent
Update Time : Mon May 10 16:41:01 2021
State : clean, degraded
Active Devices : 1
Working Devices : 1
Failed Devices : 0
Spare Devices : 0
Consistency Policy : resync
Name : localhost.localdomain:1 (local to host localhost.localdomain)
UUID : 9b401dd7:e84cb68f:339e77e9:d1ef11bb
Events : 20
Number Major Minor RaidDevice State
- 0 0 0 removed
1 8 32 1 active sync /dev/sdc
[root@localhost raid1]#
[root@localhost raid1]# mdadm -a /dev/md1 /dev/sdb
mdadm: added /dev/sdb
[root@localhost raid1]# mdadm -D /dev/md1
/dev/md1:
Version : 1.2
Creation Time : Mon May 10 16:07:08 2021
Raid Level : raid1
Array Size : 20954112 (19.98 GiB 21.46 GB)
Used Dev Size : 20954112 (19.98 GiB 21.46 GB)
Raid Devices : 2
Total Devices : 2
Persistence : Superblock is persistent
Update Time : Mon May 10 16:42:52 2021
State : clean, degraded, recovering
Active Devices : 1
Working Devices : 2
Failed Devices : 0
Spare Devices : 1
Consistency Policy : resync
Rebuild Status : 10% complete
Name : localhost.localdomain:1 (local to host localhost.localdomain)
UUID : 9b401dd7:e84cb68f:339e77e9:d1ef11bb
Events : 23
Number Major Minor RaidDevice State
2 8 16 0 spare rebuilding /dev/sdb
1 8 32 1 active sync /dev/sdc
[root@localhost raid1]#
④实时监控
[root@localhost raid1]# watch -n 0.5 'mdadm -D /dev/md1|tail'
RAID5配置
1)添加三块硬盘
[root@localhost ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 80G 0 disk
├─sda1 8:1 0 1G 0 part /boot
└─sda2 8:2 0 79G 0 part
├─centos-root 253:0 0 75.1G 0 lvm /
└─centos-swap 253:1 0 3.9G 0 lvm [SWAP]
sdb 8:16 0 20G 0 disk
sdc 8:32 0 20G 0 disk
sdd 8:48 0 20G 0 disk
sr0 11:0 1 4.3G 0 rom
[root@localhost ~]#
2)创建RAID5
[root@localhost ~]# mdadm -C -v /dev/md5 -l 5 -n 3 /dev/sdb /dev/sdc /dev/sdd
mdadm: layout defaults to left-symmetric
mdadm: layout defaults to left-symmetric
mdadm: chunk size defaults to 512K
mdadm: size set to 20954112K
mdadm: Defaulting to version 1.2 metadata
mdadm: array /dev/md5 started.
[root@localhost ~]#
3)查看详情
[root@localhost ~]# mdadm -D /dev/md5
/dev/md5:
Version : 1.2
Creation Time : Mon May 10 16:59:27 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 : 3
Persistence : Superblock is persistent
Update Time : Mon May 10 17:00:12 2021
State : clean
Active Devices : 3
Working Devices : 3
Failed Devices : 0
Spare Devices : 0
Layout : left-symmetric
Chunk Size : 512K
Consistency Policy : resync
Name : localhost.localdomain:5 (local to host localhost.localdomain)
UUID : 756e0afb:4b693b4c:9332082d:a1265c05
Events : 18
Number Major Minor RaidDevice State
0 8 16 0 active sync /dev/sdb
1 8 32 1 active sync /dev/sdc
3 8 48 2 active sync /dev/sdd
[root@localhost ~]#
4)格式化并挂载
[root@localhost ~]# mkfs.xfs -f /dev/md5
meta-data=/dev/md5 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
[root@localhost ~]# mount /dev/md5 /raid5
[root@localhost ~]# df -h
文件系统 容量 已用 可用 已用% 挂载点
/dev/mapper/centos-root 76G 5.0G 71G 7% /
devtmpfs 1.9G 0 1.9G 0% /dev
tmpfs 1.9G 0 1.9G 0% /dev/shm
tmpfs 1.9G 13M 1.9G 1% /run
tmpfs 1.9G 0 1.9G 0% /sys/fs/cgroup
/dev/sda1 1014M 179M 836M 18% /boot
tmpfs 378M 12K 378M 1% /run/user/42
tmpfs 378M 0 378M 0% /run/user/0
/dev/md5 40G 33M 40G 1% /raid5
[root@localhost ~]#
5)验证可靠性
①创建三个文件
[root@localhost ~]# cd /raid5
[root@localhost raid5]# touch 1 2 3
[root@localhost raid5]# ll
总用量 0
-rw-r--r--. 1 root root 0 5月 10 17:09 1
-rw-r--r--. 1 root root 0 5月 10 17:09 2
-rw-r--r--. 1 root root 0 5月 10 17:09 3
[root@localhost raid5]#
②破坏其中一个磁盘
[root@localhost raid5]# mdadm /dev/md5 -f /dev/sdb
mdadm: set /dev/sdb faulty in /dev/md5
[root@localhost raid5]# mdadm -D /dev/md5
/dev/md5:
Version : 1.2
Creation Time : Mon May 10 16:59:27 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 : 3
Persistence : Superblock is persistent
Update Time : Mon May 10 17:11:03 2021
State : clean, degraded
Active Devices : 2
Working Devices : 2
Failed Devices : 1
Spare Devices : 0
Layout : left-symmetric
Chunk Size : 512K
Consistency Policy : resync
Name : localhost.localdomain:5 (local to host localhost.localdomain)
UUID : 756e0afb:4b693b4c:9332082d:a1265c05
Events : 22
Number Major Minor RaidDevice State
- 0 0 0 removed
1 8 32 1 active sync /dev/sdc
3 8 48 2 active sync /dev/sdd
0 8 16 - faulty /dev/sdb
[root@localhost raid5]#
③查看文件
[root@localhost raid5]# ll
总用量 0
-rw-r--r--. 1 root root 0 5月 10 17:09 1
-rw-r--r--. 1 root root 0 5月 10 17:09 2
-rw-r--r--. 1 root root 0 5月 10 17:09 3
[root@localhost raid5]#
④移除损坏的磁盘并添加一块新的磁盘,新磁盘会同步
[root@localhost ~]# mdadm -r /dev/md5 /dev/sdb
mdadm: hot removed /dev/sdb from /dev/md5
[root@localhost ~]#
[root@localhost raid5]# mdadm -a /dev/md5 /dev/sdb
mdadm: added /dev/sdb
[root@localhost raid5]# mdadm -D /dev/md5
RAID10配置
1)添加4块硬盘
[root@localhost ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 80G 0 disk
├─sda1 8:1 0 1G 0 part /boot
└─sda2 8:2 0 79G 0 part
├─centos-root 253:0 0 75.1G 0 lvm /
└─centos-swap 253:1 0 3.9G 0 lvm [SWAP]
sdb 8:16 0 20G 0 disk
sdc 8:32 0 20G 0 disk
sdd 8:48 0 20G 0 disk
sde 8:64 0 20G 0 disk
sr0 11:0 1 4.3G 0 rom
[root@localhost ~]#
2)创建RAID10
[root@localhost ~]# mdadm -C -v /dev/md10 -l 10 -n 4 /dev/sd[b-d]
mdadm: You haven't given enough devices (real or missing) to create this array
[root@localhost ~]# mdadm -C -v /dev/md10 -l 10 -n 4 /dev/sd[b-e]
mdadm: layout defaults to n2
mdadm: layout defaults to n2
mdadm: chunk size defaults to 512K
mdadm: size set to 20954112K
mdadm: Defaulting to version 1.2 metadata
mdadm: array /dev/md10 started.
[root@localhost ~]#
3)查看详情
[root@localhost ~]# mdadm -D /dev/md10
/dev/md10:
Version : 1.2
Creation Time : Mon May 10 18:29:05 2021
Raid Level : raid10
Array Size : 41908224 (39.97 GiB 42.91 GB)
Used Dev Size : 20954112 (19.98 GiB 21.46 GB)
Raid Devices : 4
Total Devices : 4
Persistence : Superblock is persistent
Update Time : Mon May 10 18:29:39 2021
State : clean, resyncing
Active Devices : 4
Working Devices : 4
Failed Devices : 0
Spare Devices : 0
Layout : near=2
Chunk Size : 512K
Consistency Policy : resync
Resync Status : 36% complete
Name : localhost.localdomain:10 (local to host localhost.localdomain)
UUID : 2e4a6a9e:8d2a3367:67b6a0a5:aae8ce21
Events : 5
Number Major Minor RaidDevice State
0 8 16 0 active sync set-A /dev/sdb
1 8 32 1 active sync set-B /dev/sdc
2 8 48 2 active sync set-A /dev/sdd
3 8 64 3 active sync set-B /dev/sde
[root@localhost ~]#
4)挂载
[root@localhost ~]# pvcreate /dev/md10 #创建物理卷
[root@localhost ~]# vgcreate vg01 /dev/md10 #创建卷组
[root@localhost ~]# lvcreate -n lv01 -L 10G vg01 #创建逻辑卷
[root@localhost ~]# mkdir /raid10 #创建挂载目录
[root@localhost ~]# mkfs.xfs /dev/vg01/lv01 #格式化逻辑卷
[root@localhost ~]# mount /dev/vg01/lv01 /raid10 #挂载
5)验证可靠性(每组镜像最多损坏一个磁盘)
[root@localhost raid10]# mdadm /dev/md10 -f /dev/sdb
mdadm: set /dev/sdb faulty in /dev/md10
[root@localhost raid10]# mdadm /dev/md10 -f /dev/sdc
mdadm: set device faulty failed for /dev/sdc: Device or resource busy
[root@localhost raid10]# mdadm /dev/md10 -f /dev/sde
mdadm: set /dev/sde faulty in /dev/md10
文件正常
[root@localhost raid10]# ll
总用量 0
-rw-r--r--. 1 root root 0 5月 10 18:44 1
-rw-r--r--. 1 root root 0 5月 10 18:44 2
-rw-r--r--. 1 root root 0 5月 10 18:44 3
[root@localhost raid10]#
以上是关于独立冗余磁盘阵列 ----RAID的主要内容,如果未能解决你的问题,请参考以下文章