常见RAID介绍

RAID简介

独立硬盘冗余阵列(RAID, Redundant Array of Independent Disks),旧称廉价磁盘冗余阵列(Redundant Array of Inexpensive Disks),简称磁盘阵列。主要目的是把多块硬盘组合起来提高数据处理能力、容错功能等

根据实现方式分为硬件和软件两种 
 硬件RAID:通过RAID卡或主板集成的RAID控制器来支持实现RAID功能 
 软件RAID:通过软件模拟实现RAID功能 
:软件RAID不建议在生产环境使用,作为学习了解RAID的一种方式。


常见RAID级别

  • RAID 0

RAID 0亦称为条带卷。它将两块以上的硬盘并联起来,成为一个大容量的硬盘。数据会分割成多个数据块(chunk)平均分散存储到硬盘上,因此读写能力提升,但不具备冗余和容错功能,一块硬盘损坏,所有数据丢失。

常见RAID介绍

  • RAID 1

RAID 1亦称为镜像卷。它由两块或多块硬盘相互组成镜像。比如两块硬盘组RAID 1 数据会在两块硬盘都保存一份,使得硬盘读性能提升但写性能略有下降,具备冗余和容错功能。

常见RAID介绍

  • RAID 4

RAID 4是由3块或3块以上硬盘组成,其中一块硬盘作为校验盘存储校验码,使其具备容错能力允许损坏一块硬盘,其可通过异或运算还原数据。在读写操作时校验盘相比其它盘的负载压力大,更易损坏。

常见RAID介绍

  • RAID 5

RAID 5可以理解为RAID 4的升级版,相比于RAID 4其将校验码分散存储在各个盘上,使得负载均衡,整体性能提升,并且提供了一块硬盘的冗余。

常见RAID介绍

  • RAID 6

相比于RAID 5增加一个校验系统,提供了两块硬盘的冗余。根据其设计硬盘数至少4块.

850px-RAID_6.svg.png-41.6kB

混合类型

  • RAID 10

RAID 10是将所有硬盘先组成N组RAID 1,然后再组成RAID 0。最高可支持半数硬盘损坏而不丢失数据。

常见RAID介绍

  • RAID 01

RAID 10是将所有硬盘先组成N组RAID 0,然后再组成RAID 1。当有一块硬盘损坏,其同组RAID 0的其它硬盘都会停止工作。运气不好可能损坏两块硬盘就导致所有数据丢失。

常见RAID介绍

  • RAID 50

RAID 5与RAID 0的组合,先作RAID 5,再作RAID 0。至少需要6块硬盘,最多只能坏一块硬盘。

常见RAID介绍

  • JBOD(Just a Bunch Of Disks)

主要功能是将多块硬盘的空间合并成一个大的连续空间使用。

常见RAID介绍

:以上图片转自维基百科

总结和对比

RAID级别 读取性能 写入性能 可用空间 最大容错 极端情况 最少硬盘
单一硬盘(参考) 1 1 1 0 1 1
RAID 0 N N N*min(S1…Sn) 0 1 2
RAID 1 N 略有下降 1*min(S1…Sn) N-1 N 2
RAID 4 提高 提高 (N-1)*min(S1…Sn) 1 2 3
RAID 5 N-1 N-1 (N-1)*min(S1…Sn) 1 2 3
RAID 6 N-2 N-2 (N-2)*min(S1…Sn) 2 3 4
RAID 10 N M M*min(S1…SN) N-M N/M 4
RAID 01 N N/M N*min(S1…SN)/M N*(M-1) M 4
JBOD 1 1 容量之和 0 1 2

注: 
N表示硬盘数 
min(S1…Sn)表示最小硬盘容量 
RAID 10中M表示RAID 1的组数,RAID 01中M表示RAID 0的组数 
极端情况表示最少几块硬盘损坏就会导致数据丢失


CentOS 6上的软件RAID的实现

在CentOS 6中使用mdadm工具与内核中的md(multi devices)模块通信完成创建管理软RAID

  • mdadm简介

命令的语法格式:mdadm [mode] <raiddevice> [options] <component-devices> 
支持的RAID级别:LINEAR, RAID0, RAID1, RAID4, RAID5, RAID6, RAID10

模式: 
创建模式:-C 
装配模式:-A 
监控模式:-F 
管理模式:-f,-r,-a 
: /dev/md# 
: 任意块设备

-C:创建模式 
-n #:使用#个块设备来创建此RAID 
-l #:指明要创建的RAID的级别 
-a {yes|no}:自动创建目标RAID设备的设备文件 
-c CHUNK_SIZE:指明块大小 
-x #:指明空闲盘的个数

-D:显示raid的详细信息 
mdadm -D /dev/md#

管理模式: 
-f:标记指定磁盘为损坏 
-a:添加磁盘 
-r:移除磁盘

观察md的状态:cat /proc/mdstat 
停止md设备:mdadm -S /dev/md#

软件RAID实现过程

实验目标:创建一个可用空间为10G的RAID 1设备,要求其chunk大小为128k,文件系统为ext4,有一个空闲盘,开机可自动挂载至/backup目录

  • 系统环境

操作系统:CentOS 6.7
磁盘信息:
Disk /dev/sda: 128.8 GB, 128849018880 bytes
255 heads, 63 sectors/track, 15665 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00013624

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          64      512000   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2              64       15666   125316096   8e  Linux LVM

Disk /dev/sdb: 35.4 GB, 35433480192 bytes
255 heads, 63 sectors/track, 4307 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

:为了简便实验操作将对sdb进行分区,在此基础上创建RAID。

  • 磁盘分区

[root@centos6 ~]# fdisk /dev/sdb
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0x3610f0c2.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won't be recoverable.

Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)

WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
         switch off the mode (command 'c') and change display units to
         sectors (command 'u').

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-4307, default 1): 
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-4307, default 4307): +10G

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 2
First cylinder (1307-4307, default 1307): 
Using default value 1307
Last cylinder, +cylinders or +size{K,M,G} (1307-4307, default 4307): +10G

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 3
First cylinder (2613-4307, default 2613): 
Using default value 2613
Last cylinder, +cylinders or +size{K,M,G} (2613-4307, default 4307): +10G

Command (m for help): t  
Partition number (1-4): 1
Hex code (type L to list codes): fd  #避免问题发生软RAID一定要调整分区类型为Linux raid auto(即id为fd)
Changed system type of partition 1 to fd (Linux raid autodetect)

Command (m for help): t
Partition number (1-4): 2
Hex code (type L to list codes): fd
Changed system type of partition 2 to fd (Linux raid autodetect)

Command (m for help): t
Partition number (1-4): 3
Hex code (type L to list codes): fd
Changed system type of partition 3 to fd (Linux raid autodetect)

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.

通知内核重读分区表

[root@centos6 ~]# partx -a /dev/sdb
BLKPG: Device or resource busy
error adding partition 1
BLKPG: Device or resource busy
error adding partition 2
BLKPG: Device or resource busy
error adding partition 3
  • RAID设备创建

使用mdadm工具创建RAID 1,chunk为128k,有一个空闲盘

[root@centos6 ~]# mdadm -C /dev/md0 -a yes -n 2 -x 1 -c 128 -l 1 /dev/sdb{1,2,3}
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
Continue creating array? y
mdadm: Defaulting to version 1.2 metadata
mdadm: array /dev/md0 started.

查看md的状态

[root@centos6 ~]# cat /proc/mdstat  #同步中
Personalities : [raid1] 
md0 : active raid1 sdb3[2](S) sdb2[1] sdb1[0]
      10482176 blocks super 1.2 [2/2] [UU]
      [===>.................]  resync = 18.9% (1989376/10482176) finish=0.6min speed=221041K/sec
      
unused devices: <none>
[root@centos6 ~]# cat /proc/mdstat  #同步完成
Personalities : [raid1] 
md0 : active raid1 sdb3[2](S) sdb2[1] sdb1[0]
      10482176 blocks super 1.2 [2/2] [UU]
      
unused devices: <none>

查看创建的RAID设备的详细信息

[root@centos6 ~]# mdadm -D /dev/md0
/dev/md0:
        Version : 1.2
  Creation Time : Mon Apr 11 20:17:28 2016
     Raid Level : raid1
     Array Size : 10482176 (10.00 GiB 10.73 GB)
  Used Dev Size : 10482176 (10.00 GiB 10.73 GB)
   Raid Devices : 2
  Total Devices : 3
    Persistence : Superblock is persistent

    Update Time : Mon Apr 11 20:18:20 2016
          State : clean 
 Active Devices : 2
Working Devices : 3
 Failed Devices : 0
  Spare Devices : 1

           Name : centos6.7:0  (local to host centos6.7)
           UUID : 5a709c74:6b893df0:83f19941:565699f7
         Events : 17

    Number   Major   Minor   RaidDevice State
       0       8       17        0      active sync   /dev/sdb1
       1       8       18        1      active sync   /dev/sdb2

       2       8       19        -      spare   /dev/sdb3

RAID设备格式化,文件系统为ext4

[root@centos6 ~]# mke2fs -t ext4 /dev/md0
mke2fs 1.41.12 (17-May-2010)
文件系统标签=
操作系统:Linux
块大小=4096 (log=2)
分块大小=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
655360 inodes, 2620544 blocks
131027 blocks (5.00%) reserved for the super user
第一个数据块=0
Maximum filesystem blocks=2684354560
80 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks: 
	32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632

正在写入inode表: 完成                            
Creating journal (32768 blocks): 完成
Writing superblocks and filesystem accounting information: 完成

This filesystem will be automatically checked every 31 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.
  • 挂载RAID设备

将RAID设备设置开机可自动挂载至/backup目录

[root@centos6 ~]# mkdir /backup  #创建/backup目录
[root@centos6 ~]# blkid /dev/md0 #查询设备的UUID,推荐使用UUID格式挂载
/dev/md0: UUID="f57b163a-0bc3-4b21-a388-a1586d84e943" TYPE="ext4" 
[root@centos6 ~]# vim /etc/fstab
#
# /etc/fstab
# Created by anaconda on Fri Mar  4 11:09:09 2016
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
/dev/mapper/vg_centos6-lv_root /                       ext4    defaults        1 1
UUID=3efc9d2d-ff60-4491-84c4-e1beb6701b83 /boot                   ext4    defaults        1 2
/dev/mapper/vg_centos6-lv_home /home                   ext4    defaults        1 2
/dev/mapper/vg_centos6-lv_swap swap                    swap    defaults        0 0
tmpfs                   /dev/shm                tmpfs   defaults        0 0
devpts                  /dev/pts                devpts  gid=5,mode=620  0 0
sysfs                   /sys                    sysfs   defaults        0 0
proc                    /proc                   proc    defaults        0 0
UUID=f57b163a-0bc3-4b21-a388-a1586d84e943 /backup ext4 defaults 0 0
[root@centos6 ~]# mount -a      #挂载支持自动挂载的设备
[root@centos6 ~]# df            #查看是否挂载成功
Filesystem           1K-blocks    Used Available Use% Mounted on
/dev/mapper/vg_centos6-lv_root
                      51475068 4071360  44782268   9% /
tmpfs                   502384       0    502384   0% /dev/shm
/dev/sda1               487652   37084    424968   9% /boot
/dev/mapper/vg_centos6-lv_home
                      69608928   54412  66011888   1% /home
/dev/md0              10186552   23028   9639416   1% /backup     #表明挂载成功
  • 测试

[root@centos6 backup]# ls /backup
lost+found
[root@centos6 backup]#cp /etc/fstab /backup
[root@centos6 ~]# ls /backup
fstab  lost+found
[root@centos6 ~]# mdadm /dev/md0 -f /dev/sdb1  #模拟一块硬盘损坏
mdadm: set /dev/sdb1 faulty in /dev/md0
[root@centos6 ~]# mdadm -D /dev/md0  #查看设备信息
/dev/md0:
        Version : 1.2
  Creation Time : Mon Apr 11 20:17:28 2016
     Raid Level : raid1
     Array Size : 10482176 (10.00 GiB 10.73 GB)
  Used Dev Size : 10482176 (10.00 GiB 10.73 GB)
   Raid Devices : 2
  Total Devices : 3
    Persistence : Superblock is persistent

    Update Time : Mon Apr 11 21:03:48 2016
          State : clean, degraded, recovering  #处于降级恢复模式
 Active Devices : 1
Working Devices : 2
 Failed Devices : 1
  Spare Devices : 1

 Rebuild Status : 43% complete

           Name : centos6.7:0  (local to host centos6.7)
           UUID : 5a709c74:6b893df0:83f19941:565699f7
         Events : 26

    Number   Major   Minor   RaidDevice State
       2       8       19        0      spare rebuilding   /dev/sdb3  #空闲盘替代损坏硬盘,数据重建中
       1       8       18        1      active sync   /dev/sdb2

       0       8       17        -      faulty   /dev/sdb1   #提示该硬盘损坏
[root@centos6 ~]# mdadm /dev/md0 -f /dev/sdb2  #模拟再出现硬盘损坏
mdadm: set /dev/sdb2 faulty in /dev/md0
[root@centos6 ~]# mdadm -D /dev/md0 
/dev/md0:
        Version : 1.2
  Creation Time : Mon Apr 11 20:17:28 2016
     Raid Level : raid1
     Array Size : 10482176 (10.00 GiB 10.73 GB)
  Used Dev Size : 10482176 (10.00 GiB 10.73 GB)
   Raid Devices : 2
  Total Devices : 3
    Persistence : Superblock is persistent

    Update Time : Mon Apr 11 21:10:20 2016
          State : clean, degraded    #处于降级模式
 Active Devices : 1
Working Devices : 1
 Failed Devices : 2
  Spare Devices : 0

           Name : centos6.7:0  (local to host centos6.7)
           UUID : 5a709c74:6b893df0:83f19941:565699f7
         Events : 38

    Number   Major   Minor   RaidDevice State
       2       8       19        0      active sync   /dev/sdb3
       2       0        0        2      removed    #此处硬盘缺失

       0       8       17        -      faulty   /dev/sdb1
       1       8       18        -      faulty   /dev/sdb2
[root@centos6 ~]# cat /backup/fstab    #数据可正常访问

#
# /etc/fstab
# Created by anaconda on Fri Mar  4 11:09:09 2016
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
/dev/mapper/vg_centos6-lv_root /                       ext4    defaults        1 1
UUID=3efc9d2d-ff60-4491-84c4-e1beb6701b83 /boot                   ext4    defaults        1 2
/dev/mapper/vg_centos6-lv_home /home                   ext4    defaults        1 2
/dev/mapper/vg_centos6-lv_swap swap                    swap    defaults        0 0
tmpfs                   /dev/shm                tmpfs   defaults        0 0
devpts                  /dev/pts                devpts  gid=5,mode=620  0 0
sysfs                   /sys                    sysfs   defaults        0 0
proc                    /proc                   proc    defaults        0 0
UUID=f57b163a-0bc3-4b21-a388-a1586d84e943 /backup ext4 defaults 0 0

原创文章,作者:Net18-海滨,如若转载,请注明出处:http://www.178linux.com/14676

(0)
上一篇 2016-04-12 16:00
下一篇 2016-04-12 19:00

相关推荐

  • 文件系统挂载

    挂载: 将额外文件系统与根文件系统某现存的目录建立起关联关系,进而使得此目录做为其它文件访问入口的行为 卸载: 为解除此关联关系的过程 把设备关联挂载点:mount Point mount 卸载时:可使用设备,也可以使用挂载点 umount mount   umount命令都是临时生效,机器重启后失效 挂载点下原有文件在挂载完成…

    Linux干货 2017-04-30
  • 实验删除分区表

    首先我们先对分区表做个备份 dd if=/dev/sda of=/app/mbr bs=1 count=512 把备份考到另一台设备上,不拷贝的话这台设备开不了机无法使用备份的文件 清除分区表 接下来需要在客户端操作 使用光盘救援模式启动 启用网络 选网卡 自动获取ip后默认下一步 接下来就是把刚刚拷到另一台设备上的文件拷贝回来   注:这是在光盘的根目录下…

    2017-12-05
  • 马哥教育网络班22期+第13周课程练习

    1、建立samba共享,共享目录为/data,要求:(描述完整的过程)   1)共享名为shared,工作组为magedu;   2)添加组develop,添加用户gentoo,centos和ubuntu,其中gentoo和centos以develop为附加组,ubuntu不属于develop组;密码均为用户名; &n…

    Linux干货 2016-12-05
  • linux文件查找和压缩

    locate          非实查找,查找是根据全系统文件数据库进行的,                  #updatedb, 手动生成数据库,  locate查找速度快 find : &nbs…

    Linux干货 2017-03-04
  • 课堂练习之 “;” 用法

    作业:如何实现前一条命令执行成功,才会执行后面一条命令,以及前一条命令执行失败才会执行后一条命令。 首先,多条命令一起执行的方法有几种。   1.用;隔开,不会判断前一条命令是否执行成功或失败。   2.用&&隔开,前面命令执行成功后,才会执行后面的命令。     3.用||或|隔开,前面命令执行失败后…

    2017-07-15
  • N26_第三周

    1、列出当前系统上所有已经登录的用户的用户名。同一个用户多次登录,只显示一次 [root@node1 ~]# who |cut -d ‘ ‘ -f 1 | sort-u root zhh   2、取出最后登录到当前系统的用户的相关信息 [root@node1 ~]# id `last | head -1 | cut -d&#…

    Linux干货 2017-05-26