侧边栏壁纸
博主头像
一揽芳华 博主等级

行动起来,活在当下

  • 累计撰写 265 篇文章
  • 累计创建 24 个标签
  • 累计收到 4 条评论

目 录CONTENT

文章目录

6.8、RAID独立冗余磁盘阵列技术

芳华是个男孩!
2024-10-14 / 0 评论 / 0 点赞 / 6 阅读 / 0 字
广告 广告

title: 08-Raid阵列
order: 8

icon: lightbulb

RAID是英文Redundant Array of Independent Disks的缩写,中文简称为独立冗余磁盘阵列。简 单的说, RAID是一种把多块独立的硬盘(物理硬盘)按不同的方式组合起来形成一个硬盘组(逻辑硬 盘),从而提供比单个硬盘更高的存储性能和提供数据备份技术。

组成磁盘阵列的不同方式称为RAID级别(RAID Levels)。在用户看起来,组成的磁盘组就像是一 个硬盘,用户可以对它进行分区,格式化等等。总之,对磁盘阵列的操作与单个硬盘一模一样。不同的 是,磁盘阵列的存储速度要比单个硬盘高很多,而且可以提供自动数据备份。数据备份的功能是在用户 数据一旦发生损坏后,利用备份信息可以使损坏数据得以恢复,从而保障了用户数据的安全性。

1、 RAID 0技术

RAID 0 技术把多块物理硬盘设备(至少两块)通过硬件或软件的方式串联在一起,组成一个大的 卷组,并将数据依次写入到各个物理硬盘中。这样一来,在最理想的状态下,硬盘设备的读写性能会提 升数倍,但是若任意一块硬盘发生故障将导致整个系统的数据都受到破坏。通俗来说, RAID 0 技术能 够有效地提升硬盘数据的吞吐速度,但是不具备数据备份和错误修复能力。如图 7-1 所示,数据被分别 写入到不同的硬盘设备中,即 disk1 和 disk2 硬盘设备会分别保存数据资料,最终实现分开写入、读取 的效果。

实例:制作RAID0卷(硬盘数量:两块起步):

(1)首先添加两块物理硬盘,大小自定义(添加过程省略),添加完成之后我们查看一下:

[root@host-172-16-0-115 ~]# lsblk

(2)对vdb进行分区:

[root@host-172-16-0-115 ~]# fdisk /dev/vdb

Welcome to fdisk (util-linux 2.23.2).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Device does not contain a recognized partition table
Building a new DOS disklabel with disk identifier 0x1b78e49f. 9
Command (m for help): n //新建一个分区
Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended
Select (default p): p //分区类型选择主分区
Partition number (1-4, default 1): //分区标号为默认
First sector (2048-20971519, default 2048): //扇区标号为默认
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-20971519, default 20971519): //分区大小默认使用全部
Using default value 20971519
Partition 1 of type Linux and of size 10 GiB is set
Command (m for help): t //进入分区类型
Selected partition [1](#bookmark1)
Hex code (type L to list all codes): fd //将分区类型设置为raid模式
Changed type of partition 'Linux' to 'Linux raid autodetect'
Command (m for help): w //保存并退出
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.

(3)对vdc进行分区:

[root@host-172-16-0-115 ~]# fdisk /dev/vdc

Welcome to fdisk (util-linux 2.23.2).
Changes will remain in memory only, until you decide to write them. Be careful before using the write command.
Device does not contain a recognized partition table
Building a new DOS disklabel with disk identifier 0x660b271d.
Command (m for help): n //新建分区
Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended
Select (default p): p //类型选择主分区
Partition number (1-4, default 1): //默认分区标号
First sector (2048-20971519, default 2048): //默认扇区标号
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-20971519, default 20971519): //默认使用全部大小
Using default value 20971519
Partition 1 of type Linux and of size 10 GiB is set
Command (m for help): t //指定分区类型
Selected partition [1](#bookmark2)
Hex code (type L to list all codes): fd //设置分区类型为raid
```
[root@host-172-16-0-115 ~]# partprobe | lsblk

Changed type of partition 'Linux' to 'Linux raid autodetect'
Command (m for help): w //保存并退出
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.

(4)同步磁盘分区信息到内核,并查看最后分区情况:

[root@host-172-16-0-115 ~]# partprobe | lsblk 1

(5)安装mdadm服务:

[root@host-172-16-0-115 ~]# yum install mdadm -y

(6)创建RAID0

[root@host-172-16-0-115 ~]# mdadm -Cv /dev/md0 -l0 -n2 /dev/vd[b-c]1
-Cv //创建一个raid卡并显示过程
/dev/md0 //创建raid目录
-l0 //指定raid类型为raid0
-n2 //指定使用两块硬盘
/dev/vd[b-c]1 //指定物理硬盘所在路径和磁盘名称以及分区编号

(7)验证raid效果:

[root@host-172-16-0-115 ~]# mdadm -D /dev/md0

(8)对raid卷进行格式化,文件系统采用xfs:

[root@host-172-16-0-115 ~]# mkfs.xfs /dev/md0

(9)挂载raid磁盘卷,这里以挂载到/opt/md0目录为例,并查看磁盘使用情况:

[root@host-172-16-0-115 ~]# mount /dev/md0 /opt/md0/ && lsblk

(10)配置开机自动挂载(先查看md0的UUID号):

[root@host-172-16-0-115 ~]# echo "UUID="7b775304-e80c-4dc5-a738-b7f774466b57"
/opt/md0 xfs defaults 0 0" >> /etc/fstab

2、 RAID 1技术

尽管 RAID 0 技术提升了硬盘设备的读写速度,但是它是将数据依次写入到各个物理硬盘中,也就 是说,它的数据是分开存放的,其中任何一块硬盘发生故障都会损坏整个系统的数据。因此,如果生产 环境对硬盘设备的读写速度没有要求,而是希望增加数据的安全性时,就需要用到 RAID 1 技术了。在 图 7-2 所示的 RAID 1 技术示意图中可以看到,它是把两块以上的硬盘设备进行绑定,在写入数据时,

是将数据同时写入到多块硬盘设备上(可以将其视为数据的镜像或备份)。当其中某一块硬盘发生故障 后, 一般会立即自动以热交换的方式来恢复数据的正常使用。

实例:制作RAID 1卷(硬盘数量:两块起步):

(1)首先添加三块物理硬盘,大小自定义(添加过程省略),添加完成之后我们查看一下:

[root@host-172-16-0-115 ~]# lsblk

说明:为了做后面试验我添加了4块硬盘,做RAID1添加三块硬盘即可,其中两块用来RAID 1 ,剩余一 块用来备用(本例子中vdb和vdc做RAID 1 ,vdd做备用)。

(2)对vdb、vdc、vdd进行分区:

[root@host-172-16-0-115 ~]# fdisk /dev/vdb

Welcome to fdisk (util-linux 2.23.2).
Changes will remain in memory only, until you decide to write them. Be careful before using the write command.
Device does not contain a recognized partition table
Building a new DOS disklabel with disk identifier 0xb7bcc404.
Command (m for help): n //新建分区
Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended
Select (default p): p //分区类型为主分区
Partition number (1-4, default 1): //分区编号默认1
First sector (2048-20971519, default 2048): //分区扇区编号默认 17 Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-20971519, default 20971519): //使用默认全部大小
Using default value 20971519
Partition 1 of type Linux and of size 10 GiB is set
Command (m for help): t //设置此分区类型
Selected partition 1
Hex code (type L to list all codes): fd //设置分区类型为raid
Changed type of partition 'Linux' to 'Linux raid autodetect'
Command (m for help): w //保存并退出
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
[root@host-172-16-0-115 ~]# fdisk /dev/vdc

Welcome to fdisk (util-linux 2.23.2).
Changes will remain in memory only, until you decide to write them. Be careful before using the write command.
Device does not contain a recognized partition table
Building a new DOS disklabel with disk identifier 0x13485edc.
Command (m for help): n //新建分区
Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended
Select (default p): p //分区类型为主分区
Partition number (1-4, default 1): //分区编号默认1
First sector (2048-20971519, default 2048): //分区扇区编号默认
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-20971519, default 20971519): //使用默认全部大小
Using default value 20971519
Partition 1 of type Linux and of size 10 GiB is set
Command (m for help): t //设置此分区类型
Selected partition 1
Hex code (type L to list all codes): fd //设置分区类型为raid
Changed type of partition 'Linux' to 'Linux raid autodetect'
Command (m for help): w //保存并退出
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
[root@host-172-16-0-115 ~]# fdisk /dev/vdd
Welcome to fdisk (util-linux 2.23.2).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Device does not contain a recognized partition table
Building a new DOS disklabel with disk identifier 0x61917aa9. 9
Command (m for help): n //新建分区
Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended
Select (default p): p //分区类型为主分区
Partition number (1-4, default 1): //分区编号默认1
First sector (2048-20971519, default 2048): //分区扇区编号默认 17 Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-20971519, default 20971519): //使用默认全部大小
Using default value 20971519
Partition 1 of type Linux and of size 10 GiB is set
Command (m for help): t //设置此分区类型
Selected partition 1
Hex code (type L to list all codes): fd //设置分区类型为raid
Changed type of partition 'Linux' to 'Linux raid autodetect'
Command (m for help): w //保存并退出
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.

(3)同步磁盘分区信息到系统内核:

[root@host-172-16-0-115 ~]# partprobe

(4)创建RAID 1卷

[root@host-172-16-0-115 ~]# mdadm -Cv /dev/md1 -l1 -n2 /dev/vd[b-c]1 -x1 /dev/vdd1
-Cv //创建并显示详细过程
/dev/md1 //创建raid所在目录
-l1 //指定raid级别
-n2 //指定硬盘数量
/dev/vd[b-c]1 -x1 //具体所需磁盘
/dev/vdd1 //备用所需磁盘

(5)验证操作效果:

[root@host-172-16-0-115 ~]# cat /proc/mdstat

[root@host-172-16-0-115 ~]# mdadm -D /dev/md1

说明:可以不适用备用磁盘,两块做raid1也行。

(6)格式化raid卷,并挂载到/opt目录下:

[root@host-172-16-0-115 ~]# mkdir -p /opt/md1 && mount /dev/md1 /opt/md1

(7)查看整个磁盘大小使用情况:

[root@host-172-16-0-115 ~]# df -h

[root@host-172-16-0-115 ~]# lsblk

(8)配置开机自动挂载(此处省略,查看前文配置)

3、 RAID 5技术

鉴于 RAID 5 技术是因为硬盘设备的成本问题对读写速度和数据的安全性能而有了一定的妥协,但 是大部分企业更在乎的是数据本身的价值而非硬盘价格,因此生产环境中主要使用 RAID 10 技术。顾名 思义, RAID 10 技术是 RAID 1+RAID 0 技术的一个“组合体”。如图 7-4 所示, RAID 10 技术需要至少 4 块硬盘来组建,其中先分别两两制作成 RAID 1 磁盘阵列,以保证数据的安全性;然后再对两个 RAID 1 磁盘阵列实施 RAID 0 技术,进一步提高硬盘设备的读写速度。这样从理论上来讲,只要坏的不是同一 组中的所有硬盘,那么最多可以损坏 50%的硬盘设备而不丢失数据。由于 RAID 10 技术继承了 RAID 0 的高读写速度和 RAID1 的数据安全性,在不考虑成本的情况下 RAID 10 的性能都超过了 RAID 5,因此 当前成 为广泛使用的一种存储技术。

实例:制作raid 5卷(硬盘数量: 3块起步):

(1)首先添加四块物理硬盘,大小自定义(添加过程省略),其中三块作为raid5,剩余一块作为备份使用。添加完成之后我们查看一下(本例中: vdb、vdc、vdd做raid 5 ,vde做备用):

[root@host-172-16-0-115 ~]# lsblk

(2)分别对四块磁盘进行分区,分区类型为主分区,使用默认分区编号和默认扇区编号以及默认全部 大小,指定分区类型为raid,过程略,参照上文raid0和raid1的配置,设置完成后查看效果。

[root@host-172-16-0-115 ~]# lsblk

(3)创建raid5卷(其详细参数参考上文,此处略):

[root@host-172-16-0-115 ~]# mdadm -Cv /dev/md5 -l5 -n3 /dev/vd[b-d]1 -x1 /dev/vde1

(4)查看效果(效果参数解释参考上文配置,此处省略):

[root@host-172-16-0-115 ~]# mdadm -D /dev/md5

(5)格式化raid5卷:

[root@host-172-16-0-115 ~]# mkfs.xfs /dev/md5

(6)将格式化后的raid5卷挂载到/opt/md5目录下,并查看:

[root@host-172-16-0-115 ~]# mount /dev/md5 /opt/md5/ && lsblk

(7)配置开机自动挂载(参考前文配置,此处省略):

4、 RAID 10技术

鉴于 RAID 5 技术是因为硬盘设备的成本问题对读写速度和数据的安全性能而有了一定的妥协,但 是大部分企业更在乎的是数据本身的价值而非硬盘价格,因此生产环境中主要使用 RAID 10 技术。

顾名思义, RAID 10 技术是 RAID 1+RAID 0 技术的一个“组合体”。如图 7-4 所示, RAID 10 技术 需要至少 4 块硬盘来组建,其中先分别两两制作成 RAID 1 磁盘阵列,以保证数据的安全性;然后再对 两个 RAID 1 磁盘阵列实施 RAID 0 技术,进一步提高硬盘设备的读写速度。这样从理论上来讲,只要坏 的不是同一组中的所有硬盘,那么最多可以损坏 50%的硬盘设备而不丢失数据。由于 RAID 10 技术继 承了 RAID 0 的高读写速度和 RAID1 的数据安全性,在不考虑成本的情况下 RAID 10 的性能都超过了

RAID 5,因此当前成 为广泛使用的一种存储技术。

实例:创建raid 10 卷(硬盘数量4块起步):

(1)首先添加六块物理硬盘,大小自定义(添加过程省略),其中vdb和vdc块作为raid,1 ,vdd和 vde做raid1,添加完成之后我们查看一下:

[root@host-172-16-0-115 ~]# lsblk

(2)分别对五块磁盘进行分区,分区类型为主分区,使用默认分区编号和默认扇区编号以及默认全部 大小,指定分区类型为raid,过程略,参照上文raid0和raid1的配置,设置完成后查看效果。

[root@host-172-16-0-115 ~]# lsblk

(3)将vdb和vdc、vdd和vde分别做成raid1:

[root@host-172-16-0-115 ~]# mdadm -Cv /dev/md1 -l1 -n2 /dev/vd[b-c]1 2 [root@host-172-16-0-115 ~]# mdadm -Cv /dev/md2 -l1 -n2 /dev/vd[d-e]1

(4)将md1和md2做成raid0:

[root@host-172-16-0-115 ~]# mdadm -Cv /dev/md10 -l0 -n2 /dev/md1 /dev/md2

(5)查看效果:

[root@host-172-16-0-115 ~]# mdadm -D /dev/md10

(6)格式化raid10卷:

[root@host-172-16-0-115 ~]# mkfs.xfs /dev/md10

(7)挂载到/opt/md10目录下:

[root@host-172-16-0-115 ~]# mount /dev/md10 /opt/md10/

(8)配置开机自动挂载:

 [root@host-172-16-0-115 ~]# blkid | grep /dev/md10

echo "UUID="deb52b4c-d6cd-4703-94e5-129dc1dd29cd" /opt/md10 xfs defaults
0 0" >> /etc/fstab

(9)查看效果:

 [root@host-172-16-0-115 ~]# lsblk

0
广告 广告

评论区