如何在Linux中配置RAID级别5

时间:2020-03-21 11:44:00  来源:igfitidea点击:

尽管了解RAID的概念是非常必要的,但不建议包括配置方法和针对特定基于供应商的RAID控制器的说明。
因为来自不同的不同控制器使用各自的专有方法来配置硬件RAID。

在本文中,我们将讨论在Linux中配置RAID 5的完整步骤及其命令。

在Raid级别5中,数据跨多个磁盘进行条带化。
但是主要优点是,我们可以借助奇偶校验在RAID 5中获得冗余。
硬件突袭中的奇偶校验是在硬件异或者门的帮助下计算的。
由于计算不同磁盘上数据条带的奇偶校验所涉及的开销,在奇偶校验的情况下,RAID级别的写入会稍微慢一些。

因此,让我们逐步完成在Linux中配置RAID级别5的步骤。

  • 创建新分区/dev/sda11,/dev/sda12和/dev/sda13
  • 将分区类型更改为RAID类型。
  • 保存更改并使用partprobe更新表。
  • 通过使用mdadm命令,使用/dev/sda11,/dev/sda12和/dev/sda13创建raid5设备。
  • 格式化RAID分区。
  • 查看更新的突袭信息。

请注意:我没有使用三个不同的硬盘,而是使用了三个不同的分区,只是为了展示如何在此处配置软件RAID 5.
但是,如果我们想在Real Life中使用或者实现RAID,则需要三个不同的硬盘驱动器。

而且,更多的驱动器=更低的冗余度,因此我们可以使用更多的硬盘来降低冗余度。
很快我将写一篇文章如何使用raid 5,在那篇文章中,我将使用三个不同的硬盘驱动器,其实现方式将与生产环境相同。

在上面显示的图中,我们可以看到奇偶校验分布在多个磁盘上。
因此,即使一个磁盘发生故障,也可以借助其他磁盘的奇偶校验来重新计算该磁盘中的数据。

因此,让我们通过创建分区来开始本教程(在软件RAID级别5中,它将充当物理磁盘)

[root@localhost ~]# fdisk /dev/sda
The number of cylinders for this disk is set to 19457.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
   (e.g., DOS FDISK, OS/2 FDISK)
Command (m for help): n
First cylinder (18934-19457, default 18934):
Using default value 18934
Last cylinder or +size or +sizeM or +sizeK (18934-19457, default 19457): +100M
Command (m for help): n
First cylinder (18947-19457, default 18947):
Using default value 18947
Last cylinder or +size or +sizeM or +sizeK (18947-19457, default 19457): +100M
Command (m for help): n
First cylinder (18960-19457, default 18960):  
Using default value 18960
Last cylinder or +size or +sizeM or +sizeK (18960-19457, default 19457): +100M
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table.
The new table will be used at the next reboot.
Syncing disks.
[root@localhost ~]#

创建分区后,我们需要做的下一件事是通知linux系统,这些分区将用于突袭。
可以通过将分区类型更改为RAID来实现。

将分区类型更改为RAID类型:

[root@localhost ~]# fdisk /dev/sda
The number of cylinders for this disk is set to 19457.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
   (e.g., DOS FDISK, OS/2 FDISK)
Command (m for help): t
Partition number (1-13): 13
Hex code (type L to list codes): fd
Changed system type of partition 13 to fd (Linux raid autodetect)
Command (m for help): t
Partition number (1-13): 12
Hex code (type L to list codes): fd
Changed system type of partition 12 to fd (Linux raid autodetect)
Command (m for help): t
Partition number (1-13): 11
Hex code (type L to list codes): fd
Changed system type of partition 11 to fd (Linux raid autodetect)
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table.
The new table will be used at the next reboot.
Syncing disks.
[root@localhost ~]# partprobe

创建RAID 5设备:

[root@localhost ~]# mdadm --create /dev/md5 --level=5 --raid-devices=3 /dev/sda11 /dev/sda12 /dev/sda13
mdadm: array /dev/md5 started.

详细查看RAID设备信息:

[root@localhost ~]# mdadm --detail /dev/md5
/dev/md5:
        Version : 0.90
  Creation Time : Tue Apr  9 17:22:18 2013
     Raid Level : raid5
     Array Size : 208640 (203.78 MiB 213.65 MB)
  Used Dev Size : 104320 (101.89 MiB 106.82 MB)
   Raid Devices : 3
  Total Devices : 3
Preferred Minor : 5
    Persistence : Superblock is persistent
    Update Time : Tue Apr  9 17:22:31 2013
          State : clean
 Active Devices : 3
Working Devices : 3
 Failed Devices : 0
  Spare Devices : 0
         Layout : left-symmetric
     Chunk Size : 64K
           UUID : d4e4533d:3b19751a:82304262:55747e53
         Events : 0.2
    Number   Major   Minor   RaidDevice State
       0       8       11        0      active sync   /dev/sda11
       1       8       12        1      active sync   /dev/sda12
       2       8       13        2      active sync   /dev/sda13

[root@localhost ~]# cat /proc/mdstat
Personalities : [raid0] [raid1] [raid6] [raid5] [raid4]
md5 : active raid5 sda13[2] sda12[1] sda11[0]
      208640 blocks level 5, 64k chunk, algorithm 2 [3/3] [UUU]

md1 : active raid1 sda10[2](F) sda9[3](F) sda8[0]
      104320 blocks [2/1] [U_]

md0 : active raid0 sda7[1] sda6[0]
      208640 blocks 64k chunks

使用ext3日记记录方法格式化raid设备:

[root@localhost ~]# mke2fs -j /dev/md5

安装RAID文件系统:

[root@localhost ~]# mkdir /raid5
[root@localhost ~]# mount /dev/md5 /raid5

永久安装:

要使挂载即使在重新启动后仍然存在,请在/etc/fstab文件中输入。

/dev/md5               /raid5                   ext3    defaults        0 0

从RAID设备中删除分区/dev/sda13:

[root@localhost ~]# mdadm /dev/md5 --fail /dev/sda13
mdadm: set /dev/sda13 faulty in /dev/md5

[root@localhost ~]# mdadm --detail /dev/md5
/dev/md5:
        Version : 0.90
  Creation Time : Tue Apr  9 17:22:18 2013
     Raid Level : raid5
     Array Size : 208640 (203.78 MiB 213.65 MB)
  Used Dev Size : 104320 (101.89 MiB 106.82 MB)
   Raid Devices : 3
  Total Devices : 3
Preferred Minor : 5
    Persistence : Superblock is persistent
    Update Time : Wed Apr 10 08:53:03 2013
          State : clean, degraded
 Active Devices : 2
Working Devices : 2
 Failed Devices : 1
  Spare Devices : 0
         Layout : left-symmetric
     Chunk Size : 64K
           UUID : d4e4533d:3b19751a:82304262:55747e53
         Events : 0.4
    Number   Major   Minor   RaidDevice State
       0       8       11        0      active sync   /dev/sda11
       1       8       12        1      active sync   /dev/sda12
       2       0        0        2      removed
       3       8       13        -      faulty spare   /dev/sda13

现在我们可以看到/dev/sda13的备用磁盘错误。

如何将分区添加到RAID?

[root@localhost ~]# mdadm /dev/md5 --add /dev/sda14
mdadm: added /dev/sda14

上面的命令会将/dev/sda14分区添加到raid5中,例如:/dev/raid5.

如何查看或者检查是否添加了新分区?

[root@localhost ~]# mdadm --detail /dev/md5
    Number   Major   Minor   RaidDevice State
       0       8       11        0      active sync   /dev/sda11
       1       8       12        1      active sync   /dev/sda12
       2       8       14        2      active sync   /dev/sda14
       3       8       13        -      faulty spare   /dev/sda13

现在,我们可以清楚地看到/dev/sda14已成功添加到raid5中,它显示为活动状态。

要详细了解RAID设备的情况,可以使用此命令。

[root@localhost ~]# dmesg | grep -w md
md: md driver 0.90.3 MAX_MD_DEVS=256, MD_SB_DISKS=27
md: bitmap version 4.39
md: Autodetecting RAID arrays.
md: autorun ...
md: considering sda14 ...
md:  adding sda14 ...
md:  adding sda13 ...
md:  adding sda12 ...

要获取有关特定RAID设备的信息,可以使用此命令。

[root@localhost ~]# dmesg | grep -w md5
md: created md5
md5: WARNING: sda12 appears to be on the same physical disk as sda11. True
md5: WARNING: sda13 appears to be on the same physical disk as sda12. True
md5: WARNING: sda14 appears to be on the same physical disk as sda13. True
raid5: allocated 3163kB for md5
raid5: raid level 5 set md5 active with 2 out of 3 devices, algorithm 2
EXT3 FS on md5, internal journal

如果我们在计算机中配置了多个Raid,并且想了解有关所有Raid的详细信息,则可以使用以下命令。

[root@localhost ~]# mdadm --examine --scan
ARRAY /dev/md0 level=raid0 num-devices=2 UUID=db877de6:0a0be5f2:c22d99c7:e07fda85
ARRAY /dev/md1 level=raid1 num-devices=2 UUID=034c85f3:60ce1191:3b61e8dc:55851162
ARRAY /dev/md5 level=raid5 num-devices=3 UUID=d4e4533d:3b19751a:82304262:55747e5

上面的命令向我们显示了计算机中配置的所有RAID以及每个RAID使用的磁盘设备数量,还显示了分区的UUID

了解RAID 5的优势:

  • RAID 5的读取数据事务处理速率非常快。
  • RAID-5具有更改设备数量的能力。
  • 它还能够更改单个设备的大小。
  • RAID5也可以更改块大小。
  • 它还能够更改布局。
  • 由于所涉及的奇偶校验,WRITE数据事务处理速率有点慢。
  • 我们可以在不浪费任何磁盘的情况下获得冗余。
  • 我们还可以将2驱动器RAID5转换为RAID1,将3或者更多驱动器RAID5转换为RAID6.
  • 如果我们有4驱动器,则可以轻松地将4驱动器RAID5转换为6驱动器RAID6.

还可以看一下RAID 5的缺点:

  • RAID 5由于其配置和奇偶校验而有些复杂
  • 重建需要花费时间,因为突袭中涉及的奇偶校验计算。
  • 如果假设一个磁盘发生故障,则该磁盘中的数据将在其他磁盘数据以及其他磁盘奇偶校验的帮助下进行计算,这会导致读取变慢。

简要了解软件LINUX RAID解决方案:

RAID-0支持条带化。

RAID-1支持MIRRORING。

RAID-4和RAID-5具有奇偶校验支持。

“热备用”一词是什么意思?

如果其他磁盘发生故障,备用磁盘将被使用的过程称为“热备用”。

RAID中的热插拔是什么意思?

当可以在运行的阵列中更改磁盘时,使用热交换术语。