Configuration RAID 0, RAID 1, RAID 5 (+ practice theory) Detailed 7 CentOS

RAID Introduction

RAIDStands for redundant array of independent disks (Redundant Array of Independent Disks), the basic idea is to combine a plurality of disks, a disk array combination group, so that a substantial increase in performance. Initially to a combination of small low-cost disk to replace large expensive disks, and hope does not make access to data by the loss of a disk failure and develop a certain level of data protection technology.

RAIDCan give full play to the advantages of multiple hard drives, you can upgrade the hard drive speed, increased capacity, enough to provide fault tolerance to ensure data security, easy management advantages, can continue to work in the absence of any hard disk problems, and will not be damage affecting the hard disk.

RAID disk array introduction

RAIDInto a set of links to the hard disk, an array consisting of a single hard disk in order to avoid damage caused by data loss, but also provides a higher than a single disk fault tolerance and availability.

RAID 0 Introduction

Configuration RAID 0, RAID 1, RAID 5 (+ practice theory) Detailed 7 CentOS

RAID 0Commonly known as a striped volume, and Windowsthe function of the system volume with the same region, two or more hard drives it a logical drive, the data segment stored in each hard disk, the reader can be processed in parallel, so that read and write speed is N times of a single hard disk without redundancy, any damage will lead to a data disk unusable.

  • Features:

    • High literacy
    • Unreliable
    • Two or more pieces of the same size disks
    • Capacity is the sum of a plurality of disk capacity
  • ConstructRAID 0

    1、首先,在虚拟机中添加两块硬盘,每块硬盘分别是20G,然后,重启Linux系统,识别添加的硬盘,并将添加的硬盘进行分区管理,修改分区号为fd(Linux raid 自动)。

[root@localhost ~]# cd /dev
[root@localhost dev]# ls
...//省略部分内容...
cdrom            lp2                 sda4      tty16  tty38  tty6     vcs6
char             lp3                 sda5      tty17  tty39  tty60    vcsa
console          mapper              sdb       tty18  tty4   tty61    vcsa1
core             mcelog              sdc       tty19  tty40  tty62    vcsa2
cpu              mem                 sg0       tty2   tty41  tty63    vcsa3
...//省略部分内容...
[root@localhost dev]# fdisk /dev/sdb
欢迎使用 fdisk (util-linux 2.23.2)。
...//省略部分内容...
命令(输入 m 获取帮助):n
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p): p
分区号 (1-4,默认 1):
起始 扇区 (2048-41943039,默认为 2048):
将使用默认值 2048
Last 扇区, +扇区 or +size{K,M,G} (2048-41943039,默认为 41943039):
将使用默认值 41943039
分区 1 已设置为 Linux 类型,大小设为 20 GiB

命令(输入 m 获取帮助):t
已选择分区 1
Hex 代码(输入 L 列出所有代码):fd
已将分区“Linux”的类型更改为“Linux raid autodetect”

命令(输入 m 获取帮助):p

磁盘 /dev/sdb:21.5 GB, 21474836480 字节,41943040 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘标签类型:dos
磁盘标识符:0x1570d5d5

   设备 Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048    41943039    20970496   fd  Linux raid autodetect

//sdc硬盘同样操作...

[root@localhost ~]# fdisk -l

磁盘 /dev/sda:42.9 GB, 42949672960 字节,83886080 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
...//省略部分内容...
磁盘 /dev/sdb:21.5 GB, 21474836480 字节,41943040 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘标签类型:dos
磁盘标识符:0x1570d5d5

   设备 Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048    41943039    20970496   fd  Linux raid autodetect

磁盘 /dev/sdc:21.5 GB, 21474836480 字节,41943040 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘标签类型:dos
磁盘标识符:0xe4b54d43

   设备 Boot      Start         End      Blocks   Id  System
/dev/sdc1            2048    41943039    20970496   fd  Linux raid autodetect

2、查看Linux系统是否安装mdadm软件(制作软RAID工具),我们需要通过mdadm命令来制作RAID磁盘阵列。(若为安装此软件可以通过yum安装)

  • 命令格式:mdadm -C -v [/dev/要创建的RAID的设备名称] -lN -nN 磁盘设备 -xN 磁盘设备

  • Common options

    -C:create

    -v: Displays detailed process

    -l: RAID level

    -n: The number of disks

    -x: Reserved disk (disk backup)

    -D: View created RAID disk array

    -f: Delete a RAID array disks

[root@localhost ~]# rpm -q mdadm
mdadm-4.0-5.el7.x86_64

3、制作RAID 0磁盘阵列,然后查看是否创建成功。(可以用mdadm -D [RAID的设备名称]查看,也可以通过查看配置文件查看cat /proc/mdstat)

[root@localhost ~]# mdadm -C -v /dev/md0 -l0 -n2 /dev/sd[b-c]1   
mdadm: chunk size defaults to 512K                 //将sdb1、sdc1做成RAID 0磁盘阵列
mdadm: Defaulting to version 1.2 metadata
mdadm: array /dev/md0 started.
[root@localhost ~]# mdadm -D /dev/md0              //查看RAID磁盘阵列的详细信息
/dev/md0:
           Version : 1.2
     Creation Time : Sat Aug 24 09:10:19 2019
        Raid Level : raid0
        Array Size : 41908224 (39.97 GiB 42.91 GB)  //容量
      Raid Devices : 2                              //磁盘个数
     Total Devices : 2
       Persistence : Superblock is persistent

       Update Time : Sat Aug 24 09:10:19 2019
             State : clean 
    Active Devices : 2
   Working Devices : 2
    Failed Devices : 0
     Spare Devices : 0

        Chunk Size : 512K

Consistency Policy : none

              Name : localhost.localdomain:0  (local to host localhost.localdomain)
              UUID : 9b56f231:d4687383:83705a03:7d5d606a
            Events : 0

    Number   Major   Minor   RaidDevice State
       0       8       17        0      active sync   /dev/sdb1   //构成RAID的磁盘
       1       8       33        1      active sync   /dev/sdc1
[root@localhost ~]# cat /proc/mdstat         //查看RAID磁盘阵列状态
Personalities : [raid0] 
md0 : active raid0 sdc1[1] sdb1[0]           //输出创建的RAID磁盘阵列信息
      41908224 blocks super 1.2 512k chunks

unused devices: <none>

4、将RAID 0磁盘进行创建文件系统(格式化),再通过挂载,使磁盘可以正常使用。

[root@localhost ~]# mkfs.xfs /dev/md0
meta-data=/dev/md0               isize=512    agcount=16, agsize=654720 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0, sparse=0
data     =                       bsize=4096   blocks=10475520, imaxpct=25
         =                       sunit=128    swidth=256 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal log           bsize=4096   blocks=5120, version=2
         =                       sectsz=512   sunit=8 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
[root@localhost ~]# mkdir /opt/md01
[root@localhost ~]# mount /dev/md0 /opt/md01
[root@localhost ~]# df -h 
(敏感词汇分隔...)
/dev/sda2        20G  4.3G   16G   22% /
devtmpfs        1.9G     0  1.9G    0% /dev
tmpfs           1.9G     0  1.9G    0% /dev/shm
tmpfs           1.9G  9.0M  1.9G    1% /run
tmpfs           1.9G     0  1.9G    0% /sys/fs/cgroup
/dev/sda5        10G   50M   10G    1% /home
/dev/sda1       2.0G  174M  1.9G    9% /boot
tmpfs           378M   12K  378M    1% /run/user/42
tmpfs           378M     0  378M    0% /run/user/0
/dev/md0         40G   33M   40G    1% /opt/md01

RAID 1 Introduction

Configuration RAID 0, RAID 1, RAID 5 (+ practice theory) Detailed 7 CentOS

RAID 1The Windowssame system function j mirrored volume that a minimum of two hard disks, and the data stored on two hard disks are the same, in order to achieve data redundancy. No data check, data is written to the same two or more disks, the write speed is relatively slow, but read faster.

  • Features:

    • High reliability
    • Do not have the scalability
    • 2 of the same size or a plurality of disks
    • Capacity is half the sum of the plurality of disk
  • ConstructRAID 1

    1、首先,在虚拟机中添加3块硬盘,每块硬盘分别是20G,然后,重启Linux系统,识别添加的硬盘,并将添加的硬盘进行分区管理,修改分区号为fd(Linux raid 自动)。(在这里我做三块磁盘是因为在企业中使用RAID时都会多做一块或多块备用磁盘,当在使用的磁盘有1块损坏时自动顶替上去,使磁盘正常运行。)

[root@localhost ~]# fdisk /dev/sdb
欢迎使用 fdisk (util-linux 2.23.2)。

更改将停留在内存中,直到您决定将更改写入磁盘。
使用写入命令前请三思。

Device does not contain a recognized partition table
使用磁盘标识符 0x95ce2aa8 创建新的 DOS 磁盘标签。

命令(输入 m 获取帮助):n
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p): p
分区号 (1-4,默认 1):
起始 扇区 (2048-41943039,默认为 2048):
将使用默认值 2048
Last 扇区, +扇区 or +size{K,M,G} (2048-41943039,默认为 41943039):
将使用默认值 41943039
分区 1 已设置为 Linux 类型,大小设为 20 GiB

命令(输入 m 获取帮助):t
已选择分区 1
Hex 代码(输入 L 列出所有代码):fd
已将分区“Linux”的类型更改为“Linux raid autodetect”

命令(输入 m 获取帮助):p

磁盘 /dev/sdb:21.5 GB, 21474836480 字节,41943040 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘标签类型:dos
磁盘标识符:0x95ce2aa8

   设备 Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048    41943039    20970496   fd  Linux raid autodetect

命令(输入 m 获取帮助):w 
The partition table has been altered!

Calling ioctl() to re-read partition table.
正在同步磁盘。

//sdc、sdd硬盘同样操作...

[root@localhost ~]# fdisk -l

磁盘 /dev/sda:42.9 GB, 42949672960 字节,83886080 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
...//省略部分内容...

磁盘 /dev/sdc:21.5 GB, 21474836480 字节,41943040 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘标签类型:dos
磁盘标识符:0xac9b4564

   设备 Boot      Start         End      Blocks   Id  System
/dev/sdc1            2048    41943039    20970496   fd  Linux raid autodetect

磁盘 /dev/sdd:21.5 GB, 21474836480 字节,41943040 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘标签类型:dos
磁盘标识符:0x7be39280

   设备 Boot      Start         End      Blocks   Id  System
/dev/sdd1            2048    41943039    20970496   fd  Linux raid autodetect

磁盘 /dev/sdb:21.5 GB, 21474836480 字节,41943040 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘标签类型:dos
磁盘标识符:0x95ce2aa8

   设备 Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048    41943039    20970496   fd  Linux raid autodetect

2、通过mdadm命令构建RAID 1磁盘阵列,并构建保存备用盘;然后查看是否构建成功。

[root@localhost ~]# mdadm -C -v /dev/md1 -l1 -n2 /dev/sd[b-c]1 -x1 /dev/sdd1
mdadm: Note: this array has metadata at the start and  //构建RAID 1磁盘阵列,并设置备用盘
    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
mdadm: size set to 20954112K
Continue creating array?                     //询问是否创建,回车
Continue creating array? (y/n) y             //输入Y确认,回车
mdadm: Defaulting to version 1.2 metadata
mdadm: array /dev/md1 started.
[root@localhost ~]# cat /proc/mdstat         //查看RAID状态
Personalities : [raid1] 
md1 : active raid1 sdd1[2](S) sdc1[1] sdb1[0]
      20954112 blocks super 1.2 [2/2] [UU]
      [========>............]  resync = 41.0% (8602240/20954112) finish=0.9min speed=206300K/sec               //构建RAID 1的两块磁盘在进行同步,同步完成后才能正常使用

unused devices: <none>
[root@localhost ~]# cat /proc/mdstat
Personalities : [raid1] 
md1 : active raid1 sdd1[2](S) sdc1[1] sdb1[0]
      20954112 blocks super 1.2 [2/2] [UU]    //同步完成,可以正常使用磁盘

unused devices: <none>
[root@localhost ~]# mdadm -D /dev/md1        //查看RAID详细信息
/dev/md1:
           Version : 1.2
     Creation Time : Sat Aug 24 10:23:31 2019
        Raid Level : raid1
        Array Size : 20954112 (19.98 GiB 21.46 GB)      //容量
     Used Dev Size : 20954112 (19.98 GiB 21.46 GB) 
      Raid Devices : 2                                //使用的磁盘数量
     Total Devices : 3
       Persistence : Superblock is persistent

       Update Time : Sat Aug 24 10:25:16 2019
             State : clean 
    Active Devices : 2
   Working Devices : 3
    Failed Devices : 0
     Spare Devices : 1

Consistency Policy : resync

              Name : localhost.localdomain:1  (local to host localhost.localdomain)
              UUID : 459d9233:201d4c25:73f1b967:3b477186
            Events : 17

    Number   Major   Minor   RaidDevice State
       0       8       17        0      active sync   /dev/sdb1   ////构成RAID的磁盘
       1       8       33        1      active sync   /dev/sdc1

       2       8       49        -      spare   /dev/sdd1           //创建的备用盘

3、将RAID 0磁盘进行创建文件系统(格式化),再通过挂载,使磁盘可以正常使用。

[root@localhost ~]# mkfs.xfs /dev/md1
meta-data=/dev/md1               isize=512    agcount=4, agsize=1309632 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0, sparse=0
data     =                       bsize=4096   blocks=5238528, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal log           bsize=4096   blocks=2560, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
[root@localhost ~]# mkdir /opt/si1
[root@localhost ~]# mount /dev/md1 /opt/si1
[root@localhost ~]# df -h
(敏感词汇分隔...)
/dev/sda2        20G  4.3G   16G   22% /
devtmpfs        1.9G     0  1.9G    0% /dev
tmpfs           1.9G     0  1.9G    0% /dev/shm
tmpfs           1.9G  9.0M  1.9G    1% /run
tmpfs           1.9G     0  1.9G    0% /sys/fs/cgroup
/dev/sda5        10G   50M   10G    1% /home
/dev/sda1       2.0G  174M  1.9G    9% /boot
tmpfs           378M   12K  378M    1% /run/user/42
tmpfs           378M     0  378M    0% /run/user/0
/dev/md1         20G   33M   20G    1% /opt/si1

4、在挂载点中写入文件,并通过mdadm命令模拟撤掉一块磁盘,看备用盘是否会自动顶替,然后查看写入的文件是否能够正常查看。

[root@localhost ~]# touch /opt/si1/siti{1..10}.txt    //在si1中创建txt文件
[root@localhost ~]# ls /opt/si1                       //查看文件
siti10.txt  siti2.txt  siti4.txt  siti6.txt  siti8.txt
siti1.txt   siti3.txt  siti5.txt  siti7.txt  siti9.txt
[root@localhost ~]# mdadm -f /dev/md1 /dev/sdb1      //在RAID中撤掉sdb1磁盘
mdadm: set /dev/sdb1 faulty in /dev/md1
[root@localhost ~]# cat /proc/mdstat               //查看PAID阵列状态
Personalities : [raid1] 
md1 : active raid1 sdd1[2] sdc1[1] sdb1[0](F)
      20954112 blocks super 1.2 [2/1] [_U]
      [========>............]  recovery = 41.0% (8602368/20954112) finish=0.9min speed=206284K/sec                               //开始重新同步磁盘

unused devices: <none>
[root@localhost ~]# mdadm -D /dev/md1             //查看RAID 1阵列的详细信息
/dev/md1:
           Version : 1.2
     Creation Time : Sat Aug 24 10:23:31 2019
        Raid Level : raid1
        Array Size : 20954112 (19.98 GiB 21.46 GB)
     Used Dev Size : 20954112 (19.98 GiB 21.46 GB)
      Raid Devices : 2
     Total Devices : 3
       Persistence : Superblock is persistent

       Update Time : Sat Aug 24 11:12:25 2019
             State : active, degraded, recovering 
    Active Devices : 1
   Working Devices : 2
    Failed Devices : 1
     Spare Devices : 1

Consistency Policy : resync

    Rebuild Status : 86% complete

              Name : localhost.localdomain:1  (local to host localhost.localdomain)
              UUID : 459d9233:201d4c25:73f1b967:3b477186
            Events : 33

    Number   Major   Minor   RaidDevice State
       2       8       49        0      spare rebuilding   /dev/sdd1 //备用盘顶替撤掉的磁盘
       1       8       33        1      active sync   /dev/sdc1

       0       8       17        -      faulty   /dev/sdb1      //sdb1处于闲置状态
[root@localhost ~]# ls /opt/si1                            //查看si1中文件
siti10.txt  siti2.txt  siti4.txt  siti6.txt  siti8.txt    //显示文件,可以正常查看使用
siti1.txt   siti3.txt  siti5.txt  siti7.txt  siti9.txt

RAID 5 Introduction

Configuration RAID 0, RAID 1, RAID 5 (+ practice theory) Detailed 7 CentOS

RAID5A minimum of three hard disks, it is stored in the array data across each drive, and also with a data parity, data bits and check bits for the mutual authentication algorithm, when one of them is lost, RAIDthe controller algorithm can, using the other two data is calculated to restore the lost data.

  • Feature

    • High reading and writing in general, highly reliable
    • At least the same size disk fast 3
    • Capacity of n-1 / n the total disk capacity
  • ConstructRAID 5

    1、首先,在虚拟机中添加4块硬盘,每块硬盘分别是20G,然后,重启Linux系统,识别添加的硬盘,并将添加的硬盘进行分区管理,修改分区号为fd(Linux raid 自动)。(与上面做RAID 1相同,用三块磁盘构建RAID 5,1块做备用盘)。

[root@localhost ~]# fdisk /dev/sdb
欢迎使用 fdisk (util-linux 2.23.2)。

更改将停留在内存中,直到您决定将更改写入磁盘。
使用写入命令前请三思。

Device does not contain a recognized partition table
使用磁盘标识符 0x6247f95d 创建新的 DOS 磁盘标签。

命令(输入 m 获取帮助):n
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p): p
分区号 (1-4,默认 1):
起始 扇区 (2048-41943039,默认为 2048):
将使用默认值 2048
Last 扇区, +扇区 or +size{K,M,G} (2048-41943039,默认为 41943039):
将使用默认值 41943039
分区 1 已设置为 Linux 类型,大小设为 20 GiB

命令(输入 m 获取帮助):t
已选择分区 1
Hex 代码(输入 L 列出所有代码):fd
已将分区“Linux”的类型更改为“Linux raid autodetect”

命令(输入 m 获取帮助):p

磁盘 /dev/sdb:21.5 GB, 21474836480 字节,41943040 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘标签类型:dos
磁盘标识符:0x6247f95d

   设备 Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048    41943039    20970496   fd  Linux raid autodetect

命令(输入 m 获取帮助):w
The partition table has been altered!

Calling ioctl() to re-read partition table.
正在同步磁盘。

//sdc、sdd、sde硬盘同样操作...

[root@localhost ~]# fdisk -l

磁盘 /dev/sda:42.9 GB, 42949672960 字节,83886080 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
...//省略部分内容...

磁盘 /dev/sdb:21.5 GB, 21474836480 字节,41943040 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘标签类型:dos
磁盘标识符:0x88c98a9f

   设备 Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048    41943039    20970496   fd  Linux raid autodetect

磁盘 /dev/sdd:21.5 GB, 21474836480 字节,41943040 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘标签类型:dos
磁盘标识符:0xf265b801

   设备 Boot      Start         End      Blocks   Id  System
/dev/sdd1            2048    41943039    20970496   fd  Linux raid autodetect

磁盘 /dev/sdc:21.5 GB, 21474836480 字节,41943040 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘标签类型:dos
磁盘标识符:0x7922c5a3

   设备 Boot      Start         End      Blocks   Id  System
/dev/sdc1            2048    41943039    20970496   fd  Linux raid autodetect

磁盘 /dev/sde:21.5 GB, 21474836480 字节,41943040 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘标签类型:dos
磁盘标识符:0x54d78d57

   设备 Boot      Start         End      Blocks   Id  System
/dev/sde1            2048    41943039    20970496   fd  Linux raid autodetect

2、通过mdadm命令构建RAID 5磁盘阵列,并构建保存备用盘;然后查看是否构建成功。

[root@localhost ~]# mdadm -C -v /dev/md5 -l5 -n3 /dev/sd[b-d]1 -x1 /dev/sde1
mdadm: layout defaults to left-symmetric         //构建RAID 5磁盘阵列
mdadm: layout defaults to left-symmetric
mdadm: chunk size defaults to 512K
mdadm: size set to 20954112K
mdadm: Defaulting to version 1.2 metadata
mdadm: array /dev/md5 started.
[root@localhost ~]# cat /proc/mdstat            //查看状态
Personalities : [raid6] [raid5] [raid4] 
md5 : active raid5 sdd1[4] sde1[3](S) sdc1[1] sdb1[0]
      41908224 blocks super 1.2 level 5, 512k chunk, algorithm 2 [3/2] [UU_]
      [=======>.............]  recovery = 37.6% (7898112/20954112) finish=1.0min speed=200093K/sec                     //正在同步...

unused devices: <none>
[root@localhost ~]# mdadm -D /dev/md5          //查看详细信息
/dev/md5:
           Version : 1.2
     Creation Time : Sat Aug 24 11:59:51 2019
        Raid Level : raid5
        Array Size : 41908224 (39.97 GiB 42.91 GB)   //容量40G
     Used Dev Size : 20954112 (19.98 GiB 21.46 GB)
      Raid Devices : 3
     Total Devices : 4
       Persistence : Superblock is persistent

       Update Time : Sat Aug 24 12:01:29 2019
             State : clean, degraded, recovering 
    Active Devices : 2
   Working Devices : 4
    Failed Devices : 0
     Spare Devices : 2

            Layout : left-symmetric
        Chunk Size : 512K

Consistency Policy : resync

    Rebuild Status : 99% complete

              Name : localhost.localdomain:5  (local to host localhost.localdomain)
              UUID : 968fa4f5:020f5fec:4c726d63:df4b4b9b
            Events : 16

    Number   Major   Minor   RaidDevice State
       0       8       17        0      active sync   /dev/sdb1      //构建RAID 5的磁盘
       1       8       33        1      active sync   /dev/sdc1
       4       8       49        2      spare rebuilding   /dev/sdd1  //未同步好的磁盘

       3       8       65        -      spare   /dev/sde1            //备用盘
[root@localhost ~]# cat /proc/mdstat                        //常看状态
Personalities : [raid6] [raid5] [raid4] 
md5 : active raid5 sdd1[4] sde1[3](S) sdc1[1] sdb1[0]
      41908224 blocks super 1.2 level 5, 512k chunk, algorithm 2 [3/3] [UUU]
                                                      //同步完成
unused devices: <none>

3、在RAID 5阵列中撤掉sdb1磁盘,看看备用盘是否会顶替sdb1。

[root@localhost ~]# mdadm -f /dev/md5 /dev/sdb1     //从RAID 5中撤掉sdb1磁盘
mdadm: set /dev/sdb1 faulty in /dev/md5
[root@localhost ~]# cat /proc/mdstat             //查看状态
Personalities : [raid6] [raid5] [raid4] 
md5 : active raid5 sdd1[4] sde1[3] sdc1[1] sdb1[0](F)
      41908224 blocks super 1.2 level 5, 512k chunk, algorithm 2 [3/2] [_UU]
      [=>...................]  recovery =  5.7% (1212928/20954112) finish=1.3min speed=242585K/sec               //开始重新同步

unused devices: <none>
[root@localhost ~]# mdadm -D /dev/md5           //查看详细信息
/dev/md5:
           Version : 1.2
     Creation Time : Sat Aug 24 11:59:51 2019
        Raid Level : raid5
        Array Size : 41908224 (39.97 GiB 42.91 GB)
     Used Dev Size : 20954112 (19.98 GiB 21.46 GB)
      Raid Devices : 3
     Total Devices : 4
       Persistence : Superblock is persistent

       Update Time : Sat Aug 24 12:13:10 2019
             State : clean, degraded, recovering 
    Active Devices : 2
   Working Devices : 3
    Failed Devices : 1
     Spare Devices : 1

            Layout : left-symmetric
        Chunk Size : 512K

Consistency Policy : resync

    Rebuild Status : 14% complete

              Name : localhost.localdomain:5  (local to host localhost.localdomain)
              UUID : 968fa4f5:020f5fec:4c726d63:df4b4b9b
            Events : 22

    Number   Major   Minor   RaidDevice State
       3       8       65        0      spare rebuilding   /dev/sde1 //顶替sdb1
       1       8       33        1      active sync   /dev/sdc1
       4       8       49        2      active sync   /dev/sdd1

       0       8       17        -      faulty   /dev/sdb1             //sdb1处于闲置状态

4、将RAID 5阵列进行文件系统创建(格式化),并挂载使用。

[root@localhost ~]# mkfs.xfs /dev/md5
meta-data=/dev/md5               isize=512    agcount=16, agsize=654720 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0, sparse=0
data     =                       bsize=4096   blocks=10475520, imaxpct=25
         =                       sunit=128    swidth=256 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal log           bsize=4096   blocks=5120, version=2
         =                       sectsz=512   sunit=8 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
[root@localhost ~]# mkdir /opt/siti02
[root@localhost ~]# mount /dev/md5 /opt/siti02
[root@localhost ~]# df -h
(敏感词汇分隔...)
/dev/sda2        20G  4.3G   16G   22% /
devtmpfs        1.9G     0  1.9G    0% /dev
tmpfs           1.9G     0  1.9G    0% /dev/shm
tmpfs           1.9G  9.1M  1.9G    1% /run
tmpfs           1.9G     0  1.9G    0% /sys/fs/cgroup
/dev/sda5        10G   50M   10G    1% /home
/dev/sda1       2.0G  174M  1.9G    9% /boot
tmpfs           378M   12K  378M    1% /run/user/42
tmpfs           378M     0  378M    0% /run/user/0
/dev/md5         40G   33M   40G    1% /opt/siti02

note:

Every time I create a RAID disk arrays are re-initialize the virtual machine Linux system, because the system before installing Linux in a virtual machine've taken snapshots can be directly recovered. It can also operate under their own, hoping to help to you! ! !

Guess you like

Origin blog.51cto.com/14473285/2432257