如何在Linux中配置RAID(3)

在本教程中,我们会提及最常见的最重要的RAID类型,所有这些都充分被Linux支持。

RAID 0 (Striping)

RAID 0 (条带化)

This level is achieved by grouping 2 or more hard disks into a single unit with the total size equaling that of all disks used. Practical example: 3 disks, each 80GB in size can be used in a 240GB RAID 0 configuration.

这个级别是通过把2块或更多的硬盘组成一个逻辑卷,逻辑卷的容量大小等于所有磁盘的综合。实例:3块硬盘,每块容量大小是80GB,RAID0配置可以作为240GB使用。

RAID 0 works by breaking data into fragments and writing to all disk simultaneously. This significantly improves the read and write performance. On the other hand, no single disk contains the entire information for any bit of data committed. This means that if one of the disks fails, the entire RAID is rendered inoperable, with unrecoverable loss of data.

RAID0工作原理是通过把数据分解成片段,并行写入所有磁盘。这大大提高了读写性能。另一方面,任何一块磁盘不会包含存储数据的全部信息。这意味着假如其中一块硬盘发生故障了,整个RAID不可操作,并且不可挽回数据损失。

RAID 0 is suitable for non-critical operations that require good performance, like the system partition or the /tmp partition where lots of temporary data is constantly written. It is not suitable for data storage.

RAID0适用于非关键对性能要求高的业务,比如系统分区或/tmp分区,这儿不断地有大量的临时数据写入,它不适合于数据存储。

Note: Image taken from Wikipedia, distributed under GFDL.

注:图片取自维基百科GFDL发布

RAID 1 (Mirroring)

RAID 1(镜像)

This level is achieved by grouping 2 or more hard disks into a single unit with the total size equaling that of the smallest of disks used. This is because RAID 1 keeps every bit of data replicated on each of its devices in the exactly same fashion, create identical clones. Hence the name, mirroring. Practical example: 2 disks, each 80GB in size can be used in a 80GB RAID 1 configuration.

这个级别是通过把2块或更多的硬盘组成一个逻辑卷,容量大小等于所使用磁盘的最小的那块。这是因为RAID1对每块数据复制在它的每个设备上,完全相同,创建了相同的克隆。因此,名称为镜像。实例:2块磁盘,每块容量大小80GB,配置成80GB的RAID1。

On a side note, in mathematical terms, RAID 1 is an AND function, whereas RAID 0 is an OR.

从一个方面说明,在数学术语上,RAID1是“和”函数,而RAID0是“或”函数。

Because of its configuration, RAID 1 reduced write performance, as every chunk of data has to be written n times, on each of the paired devices. The read performance is identical to single disks. Redundancy is improved, as the normal operation of the system can be maintained as long as any one disk is functional.

因为它的配置,RAID1降低了写性能,因为每块数据必须在每对设备上写n次。读性能等同于单一磁盘。冗余得到了改善,因为只要有一块磁盘是可以用的系统就能正常运行。

RAID 1 is suitable for data storage, especially with non-intensive I/O tasks.

RAID1适用于数据存储,尤其是非密集I/O任务。

Note: Image taken from Wikipedia, distributed under GFDL.

注:图片取自维基百科GFDL发布

RAID 5

RAID5

This is a more complex solution, with a minimum of three devices used. Two or more devices are configured in a RAID 0 setup, while the third (or last) device is a parity device. If one of the RAID 0 devices malfunctions, the array will continue operating, using the parity device as a backup. The failure will be transparent to the user, save for the reduced performance.

这是更复杂的解决方法,至少需要3块设备。2块或更多的设备配置成RAID0,第三块或最后一块设备是校验设备。如果RAID0中的一块设备发生故障了,阵列将适用校验设备做备份继续运作。故障对用户是透明的,但会降低性能。

RAID 5 improves the write performance, as well as redundancy and is useful in mission-critical scenarios, where both good throughput and data integrity are important. RAID 5 does induce a slight CPU penalty due to parity calculations.

RAID5改善了写性能以及冗余,对关键任务的情况下是很有用的,良好的吞吐量和数据完整性都很重要的。RAID5由于校验计算稍微增加了CPU的负担。

Note: Image taken from Wikipedia, distributed under GFDL.

注:图片取自维基百科GFDL发布

Linear RAID

线性RAID

This is a less common level, although fully usable. Linear is similar to RAID 0, except that data is written sequentially rather than in parallel. Linear RAID is a simple grouping of several devices into a larger volume, the total size of which is the sum of all members. For instance, three disks the sizes of 40, 60 and 250GB can be grouped into a linear RAID the total size of 350GB.

这是不太常见的级别,虽然完全可用。线性类似于RAID0,除非数据是串行写入而不是并行。线性RAID是几块设备简单地组成更大的逻辑卷,总容量是所有成员的综合。例如,三块磁盘分别是40GB,60GB和250GB,可以组成总大小350GB的线性RAID。

Linear RAID provides no read/write performance, not does it provide redundancy; a loss of any member will render the entire array unusable. It merely increases size. It's very similar to LVM.

线性RAID并不改善读写性能,而是增加了冗余;任何一块的损失会导致整个阵列的不可用。它只是增加了大小。非常类似于逻辑卷管理。

Linear RAID is suitable when large data exceeding the individual size of any disk or partition must be used.

线性RAID适用于大型数据存储,任何单个大小的磁盘或分区都无法使用。

Other levels

其他级别

There are several other levels available. For example, RAID 6 is very similar to RAID 5, except that it has dual parity. Then, there are also nested levels, which combine different level solution in a single set. For instance, RAID 0+1 is a nested set of striped devices in a mirror configuration. This setup requires a minimum of four disks.

还有其他几类可用的级别。比如,RAID6非常类似于RAID5,除了它双奇偶校验之外。然而,也有其他嵌套的级别,是把不同级别的解决方法结合成单一设置。比如,RAID0+1是在条带化设备做镜像配置。这类安装要求至少4块磁盘。

These setups are less common, more complex and more suitable for business rather than home environment, therefore we won't talk about those in this tutorial. Still, it is good to know about them, in case you ever need them.

这些设置不是太常见的,更加复杂并且更加可适用于企业而不是家庭使用,因此我们不在本教程中谈论更多。不过,了解他们是件好事,万一你要用到他们。

Summary

摘要

So, let's review what we've learned here. We have four major RAID levels that interest us, each offering different results. The most important parameters are the I/O performance, redundancy and space efficiency.

所以,我们回顾一下我们这里已经学到的知识。我们有四类感兴趣的主要RAID级别,每种配置结果各不相同。最重要的参数是I/O性能、冗余和空间效率。

A few words on the table below:

下表中的几句话:

# devices: this column defines the minimum number of devices required to create such a setup.

#设备:这一栏目定义了创建这类设置需要的设备的最小数目。

Efficiency: this term denotes how "well" the array uses the available space. For example, if the array uses all available space, then its efficiency is equal to the total number of devices used. For instance, a RAID 0 with four 80GB disks will have a total space of 320GB, in other words, 4 x 80GB - or simply: 4 (n).

效率:这个术语是指阵列如果有效地利用了空间。例如,如果阵列使用了所有可用空间,因而它的效率等于所用设备的总数。例如,由4块80GB磁盘配置成的RAID0的空间总量是320GB,换句话说,4 x 80GB,或者简单地:4(n)。

Attrition: this tells us how many devices in the array can be lost without breaking the functionality of the array and losing data.

损耗:这项告诉我们在不破坏阵列的功能和数据丢失的前提下,我们阵列中的设备会损失多少。

Here's a small table showing the differences between the four levels discussed above:

这儿是小表格,显示谈论的四类级别之间的区别:

Level # devices Efficiency Attrition RAID 0 2 n  0 RAID 1 2 n/2 n-1 RAID 5 3 n-1 1 Linear 2 n 0 RAID notation

级别   #设备    效率      损耗

RAID0   2       n         0

RAID1   2       n/2       n-1

RAID5   3       n-1       1

线性    2       n         0

We also have to talk about how RAID devices are seen and marked by Linux. In fact, compared to hard disk notation, which takes into consideration a lot of parameters like disk type and number, partition type, etc, RAID devices are fairly simple.

我们还必须谈论一下在Linux下如何看待和标记RAID设备。事实上,硬盘注释考虑大量参数比如磁盘类型和数目,分区类型,等等,RAID设备相比较就非常简单。

RAID devices are marked by two letters md and a number. Example: md0, md3, md8. By themselves, the RAID device names tell us nothing about their type. In this regard, the RAID notation is lacking compared to disk/partition notation.

RAID设备标记两个数字md和一个数字。比如:md0,md3,md8。通过自己,RAID设备命名只是告诉我们他们的类型。在这方面,RAID的标记缺少了磁盘/分区的标记。

To be able to get more information about our RAID devices, we need additional tools. We will talk about these tools in greater detail later. For now, here's just a snippet of information.

为了获取更多关于RAID设备的信息,我们需要更多的工具。稍后我们会更详细得讨论这些工具。现在,这只是信息的提示。

/proc/mdstat

/proc/mdstat

/proc is a pseudo-filesystem on modern Linux operating systems. The term pseudo is used here, because /proc does not monitor a data structure on the disk; instead, it monitors the kernel. In other words, /proc is a sort of a windows into kernel, providing live information about the system internals, at any given moment.

/proc是现代Linux操作系统上伪文件系统。这里使���了“伪”术语,因为/proc不监控磁盘上的数据结构;相反,它可以监控内核。换句话说,/proc是windows到内核的一种分类,在任何时刻,提供了系统内部实时信息。

Many parameters about the operating system can be extracted from different files under the /proc tree. For instance, we can check all the running processes and their memory maps, we can check CPU information, mounts, and more. We can also check the status of our RAID devices.

许多有关操作系统参数可以从/proc文件系统下的不同的文件提炼出。比如,我们可以检查所有运行的进程和他们的内存印象图,我们可以检查CPU信息,挂载文件系统,更多。我们也可以检查我们RAID设备的状态。

This is done by printing out the contents of the mdstat file under /proc.

这是通过打印/proc下的mdstat文件内容做到。

cat /proc/mdstat

/cat /proc/mdstat

If there are any RAID devices present, they will be printed out to the screen (STDOUT).

如果目前有任何RAID设备,他们会被打印到屏幕上。

Here's an example:

这儿是例子:

What do we have here? Let's take a look at the first listed device, md1:

我们有什么吗?我们仔细看看第一个列出设备,md1:

Personalities: [raid1]

Personalities: [raid1]

This line tells us which types of RAID arrays are used on the system. In this case, we have a single one.

这行告诉我们是系统上哪类的RAID阵列类型。在这种情况下,我们有单一的个体。

md1: active raid1 sdb2[1] sda2[1]

md1: active raid1 sdb2[1] sda2[1]

md1 is a RAID 1 (mirror) device, spanning sda2 and sdb2 partitions. This device is active and mounted. If it were not used, it would have been listed under unused devices further below.

md1是RAID1(镜像)设备,包括了两个分区sda2和sdb2。这个设备是激活的和已挂载。如果它还没被使用,它会在未使用设备下面列出。

513984 blocks [2/2] [UU]

513984 blocks [2/2] [UU]

The second line gives us some more information about the device. [2/2] [UU] tells us both partitions are used. This may seem a little strange, but it is not. Some RAID configurations can continue functioning even if a number of devices are disabled (failed), either deliberately or due to an error or disk problem. The RAID device would still exist, but parts thereof would no longer be functioning properly.

第二行告诉我们更多相关设备的信息。[2/2][UU]说明两个分区都已被使用。这似乎有些奇怪,但事实并非如此。有些RAID配置可以继续运行直到大量的设备被禁用(故障),无论是故意或是因错误或磁盘问题。RAID设备仍然存在,但部分功能不能正常。

In our case above, we have 2 out of 2 devices working, in which case the [UU] is a redundant bit of information. However, what if we had [1/2] situation? This means one of the partitions has malfunctioned. To know which one, we need to look at the second pair of square brackets, which will tell us the device that still works.

以上例子中,两块设备全部使用,在这种情况下,[UU]是冗余信息。那么,[1/2]的情况是什么样呢?这意味着分区中的一个出现了故障。要知道是哪一个,我们需要看看第二对方括号,这告诉我们设备仍然在工作。

As an exercise, we will deliberately fail one of our devices later, to demonstrate this.

作为练习,稍后我们故意使其中一个设备出现故障来证明这一点。

Using cat /proc/mdstat is the fastest, simplest indication of the health and status of the RAID arrays. If there are no RAID arrays on the system, the output of the command would return output like this:

使用cat /proc/mdstat是RAID阵列最快最简单的状态和健康的指示。如果系统上没有RAID阵列,该命令输出将返回如下:

mdadm

mdadm

This is a very important, powerful Linux software RAID management utility. It has no less than seven modes of operation, which include assemble, build, create, monitor, grow, manage, and misc. mdadm is a command-line utility and requires super-user (root) privileges.

这是非常重要的强大的Linux的RAID软件管理工具。它不超过7种工作模式,包括装配、建立、创建、监视、成长、管理和混杂。mdadm是命令行工具,要求超级用户(root)的权限。

Later on, we will use it to manipulate our RAID arrays.

稍后,我们将用它操作RAID阵列。

For now, here's a quick example:

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wywzpd.html