Linux中的软件RAID 0配置

时间:2020-03-21 11:47:15  来源:igfitidea点击:

RAID是用于数据性能和冗余的一种广泛使用的技术。
根据需求和功能,它们分为不同的级别。
为需求选择级别始终取决于我们要在磁盘上执行的操作类型。

我们已经写了一篇文章,介绍了不同RAID级别如何工作的差异和内部细节。
RAID的完全相同的工作模型完全由硬件控制器完成,也可以由软件管理(但是硬件RAID的效率和性能始终更好)。

在本文中,我们将逐步介绍在Linux上配置软件RAID级别0的步骤。

RAID0引入时只考虑性能。
实际上,它根本不提供冗余。
RAID 0中的数据被剥离到多个磁盘上,以加快访问速度。

因此,让我们开始配置我们的软件团队0。

  • RAID 2配置需要两个硬盘
  • 可以使用不同大小的磁盘驱动器或者分区,
    但是最小磁盘/分区的大小将限制所有磁盘上的可用空间量
  • 通过将读写分布到多个磁盘,可以提高读写性能。
  • 它可以同时在多个磁盘(/dev/sda6和/dev/sda7)上剥离数据。
  • 其性能着称
  • RAID 0不适合用于数据存储,因为它没有为我们提供容错功能或者任何类型的数据安全性。
  • 如果任何磁盘故障RAID无法使用,因为没有数据重复。

如上所述,我们需要最少两个硬盘用于RAID 0配置。
大小可能会有所不同,但具有上述条件。
由于我们将在同一硬盘上对其进行配置,因此可以通过创建两个分区来对其进行测试。
因此,让我们在/dev/sda6和/dev/sda7处创建两个分区。

注意:除了整个表演都是由软件而不是RAID控制器来运行之外,软件RAID与硬件RAID完全相同。

首先让我们看一下分区表。

[root@localhost ~]# fdisk -l
Disk /dev/sda: 160.0 GB, 160041885696 bytes
255 heads, 63 sectors/track, 19457 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          13      102400    7  HPFS/NTFS
Partition 1 does not end on cylinder boundary.
/dev/sda2              13        3825    30617600    7  HPFS/NTFS
/dev/sda3            3825       11474    61440000    7  HPFS/NTFS
/dev/sda4           11475       19457    64123447+   5  Extended
/dev/sda5           11475       18868    59392273+  83  Linux

分区上方的表清楚地表明,它只有一个Linux分区/dev/sda5.

因此,现在我们必须再创建两个分区来创建RAID。

创建分区/dev/sda6和/dev/sda7并将其类型更改为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): n
First cylinder (18869-19457, default 18869):
Using default value 18869
Last cylinder or +size or +sizeM or +sizeK (18869-19457, default 19457): +100M
Command (m for help): n
First cylinder (18882-19457, default 18882):
Using default value 18882
Last cylinder or +size or +sizeM or +sizeK (18882-19457, default 19457): +100M
Command (m for help): t
Partition number (1-7): 7
Hex code (type L to list codes): fd
Changed system type of partition 7 to fd (Linux raid autodetect)
Command (m for help): t
Partition number (1-7): 6
Hex code (type L to list codes): fd
Changed system type of partition 6 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.

在上面显示的示例中,我创建了两个分区,两个分区的大小均为100M。
这两个分区将充当将进行raid 0配置的物理磁盘。

更改fdisk中的分区类型可以通过在fdisk提示符中键入“ t”来完成,这将询问我们要更改其类型的分区号(在我的情况下为6和7)。

“ fd”类型代表“ Linux raid”

现在,借助partprobe命令来更新分区表信息。

[root@localhost ~]# partprobe
[root@localhost ~]# fdisk -l
Disk /dev/sda: 160.0 GB, 160041885696 bytes
255 heads, 63 sectors/track, 19457 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          13      102400    7  HPFS/NTFS
Partition 1 does not end on cylinder boundary.
/dev/sda2              13        3825    30617600    7  HPFS/NTFS
/dev/sda3            3825       11474    61440000    7  HPFS/NTFS
/dev/sda4           11475       19457    64123447+   5  Extended
/dev/sda5           11475       18868    59392273+  83  Linux
/dev/sda6           18869       18881      104391   fd  Linux raid autodetect
/dev/sda7           18882       18894      104391   fd  Linux raid autodetect

因此,现在我们可以看到创建了两个RAID类型的分区/dev/sda6和/dev/sda7.

使用mdadm命令创建软件RAID 0

[root@localhost ~]# mdadm --create /dev/md0 --level=0 --raid-devices=2 /dev/sda6 /dev/sda7

mdadm命令的命令行选项非常简单。

--level指定RAID等级

--raid-devices完全指定了使用的硬盘数量及其名称。

使用该命令,我们的raid 0设备已准备就绪。

如何查看软件RAID设备的详细信息

[root@localhost ~]# mdadm --detail /dev/md0
/dev/md0:
        Version : 0.90
  Creation Time : Tue Apr  9 14:13:53 2013
     Raid Level : raid0
     Array Size : 208640 (203.78 MiB 213.65 MB)
   Raid Devices : 2
  Total Devices : 2
Preferred Minor : 0
    Persistence : Superblock is persistent
    Update Time : Tue Apr  9 14:13:53 2013
          State : clean
 Active Devices : 2
Working Devices : 2
 Failed Devices : 0
  Spare Devices : 0
     Chunk Size : 64K
           UUID : db877de6:0a0be5f2:c22d99c7:e07fda85
         Events : 0.1
    Number   Major   Minor   RaidDevice State
       0       8        6        0      active sync   /dev/sda6
       1       8        7        1      active sync   /dev/sda7
[root@localhost ~]# cat /proc/mdstat
Personalities : [raid0]
md0 : active raid0 sda7[1] sda6[0]
      208640 blocks 64k chunks

unused devices: <none>

上面制作的md0设备与虚拟磁盘相同。
现在,为了对其进行读取和写入数据,我们需要使用我们希望的文件系统对其进行格式化。
让我们使用mke2fs命令用ext3文件系统格式化raid 0分区。

[root@localhost ~]# mke2fs -j /dev/md0
mke2fs 1.39 (29-May-2006)
Filesystem label=
OS type: Linux
Block size=1024 (log=0)
Fragment size=1024 (log=0)
52208 inodes, 208640 blocks
10432 blocks (5.00%) reserved for the super user
First data block=1
Maximum filesystem blocks=67371008
26 block groups
8192 blocks per group, 8192 fragments per group
2008 inodes per group
Superblock backups stored on blocks:
        8193, 24577, 40961, 57345, 73729, 204801
Writing inode tables: done                            
Creating journal (4096 blocks): done
Writing superblocks and filesystem accounting information: done
This filesystem will be automatically checked every 28 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.

将RAID设备分区安装到安装点

创建目录/raid0并在其上挂载raid文件系统/dev/md0。

[root@localhost ~]# mkdir /raid0
[root@localhost ~]# mount /dev/md0 /raid0
[root@localhost ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda5              55G   18G   35G  34% /
tmpfs                 502M     0  502M   0% /dev/shm
/dev/sda3              59G   31G   28G  53% /root/Desktop/win7
/dev/md0              198M  5.8M  182M   4% /raid0

我们可以清楚地看到,我们对100mb进行了两个分区,/dev/md0显示198M(约200M),这表明RAID 0使用了100%的磁盘大小。

root@localhost ~]# cat /proc/mdstat
Personalities : [raid0]
md0 : active raid0 sda7[1] sda6[0]
      208640 blocks 64k chunks

unused devices: <none>

因此,raid 0被创建并安装在/raid0上。

注意:当硬盘发生故障时,RAID 0将不会提供数据冗余。

/dev/sda6和/dev/sda7都不包含完整的数据,因此如果其中任何一个失败都会导致数据丢失。

了解RAID 0的优势:

  • 每当我们谈论RAID0时,我们都会发现读写性能都很棒。
  • 关于RAID0的另一点好处是,没有由奇偶校验控件引起的开销。
  • RAID 0最好的部分是RAID 0技术的实施非常容易。
  • 使用RAID 0的另一个好处是可以充分利用存储容量,因此没有磁盘开销。
  • 由于它提供条带化,因此将减少总负荷。
  • 在RAID 0中,我们可以一次将不同的数据段同时读/写到多个磁盘。

还知道RAID 0的缺点:

  • 使用RAID 0时,请熟悉“备份”无可替代的事实。
  • RAID 0最糟糕的事情是它不能在关键任务系统上使用。
  • 它不是容错的,因此一个磁盘故障会导致数据完全丢失,这将是一场灾难。

注意:请注意,本文中我使用了具有不同分区的单个硬盘来显示软件RAID0的配置,而在现实生活中,我们使用两个不同的硬盘。