码迷,mamicode.com
首页 > 其他好文 > 详细

1-15-2-RAID1 企业级RAID磁盘阵列的搭建(RAID1、RAID5、RAID10)

时间:2016-08-21 06:20:23      阅读:345      评论:0      收藏:0      [点我收藏+]

标签:

大纲:

1、创建RAID1

2、创建RAID5

3、创建RAID10

===============================

1、创建RAID1

RAID1原理:需要两块或以上磁盘,可添加热备盘。

在写入数据时,会在另一块磁盘中生成该文件的镜像(即同步)。

两块磁盘中的内容完全一致。

故当一块磁盘损坏时,可使用另一块镜像盘中的数据。(当拥有热备盘时,若镜像盘损坏,可由热备盘替代)

磁盘利用率为50%,即两块100G的磁盘构成RAID1只能提供100G的可用空间。

实战:创建RAID1

第一步:给虚拟机添加三块硬盘,并开机检查。

技术分享

[root@localhost ~]# ls /dev/sd*
/dev/sda  /dev/sda1  /dev/sda2  /dev/sdb  /dev/sdc  /dev/sdd
[root@localhost ~]#

效果如图:

技术分享

第二步:分别对三块磁盘分区,并修改其标签

使用相同办法,分别对/dev/sdb、/dev/sdc、/dev/sdd进行分区

[root@localhost ~]# fdisk /dev/sdb
Welcome to fdisk (util-linux 2.23.2).

Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

Device does not contain a recognized partition table
Building a new DOS disklabel with disk identifier 0xeed790f7.

Command (m for help): n
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p):
Using default response p
Partition number (1-4, default 1):
First sector (2048-41943039, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-41943039, default 41943039):
Using default value 41943039
Partition 1 of type Linux and of size 20 GiB is set

Command (m for help): t
Selected partition 1
Hex code (type L to list all codes): fd
Changed type of partition ‘Linux‘ to ‘Linux raid autodetect‘

Command (m for help): p

Disk /dev/sdb: 21.5 GB, 21474836480 bytes, 41943040 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0xeed790f7

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048    41943039    20970496   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@localhost ~]#

效果如图:

技术分享

第三步:创建RAID1磁盘阵列

检查三块磁盘是否被其他磁盘阵列使用

mdadm –E /dev/sd[b-d]1

技术分享

使用分区后的三块磁盘,创建RAID1磁盘阵列

(其中-n指定两块设备,-x指定一个热备盘,-l 指定级别为RAID1 -C创建 -v显示信息 /dev/md1—>指定创建的设备名)

mdadm -Cv /dev/md1 -l 1 -n 2 -x 1 /dev/sd[b-d]1

技术分享

检查:

[root@localhost ~]# ls /dev/md1
/dev/md1
[root@localhost ~]# mdadm -D /dev/md1
/dev/md1:
        Version : 1.2
  Creation Time : Sun Aug 21 01:26:17 2016
     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 : Sun Aug 21 01:28:01 2016
          State : clean
Active Devices : 2
Working Devices : 3
Failed Devices : 0
  Spare Devices : 1

           Name : localhost.localdomain:1  (local to host localhost.localdomain)
           UUID : 9f8c8a03:8036f47c:788bd593:8c0c83cd
         Events : 17

    Number   Major   Minor   RaidDevice State
       0       8       17        0      active sync   /dev/sdb1
       1       8       33        1      active sync   /dev/sdc1

       2       8       49        -      spare   /dev/sdd1
[root@localhost ~]# mdadm -E /dev/md1
mdadm: No md superblock detected on /dev/md1.
[root@localhost ~]# mdadm -E /dev/sd[b-d]1
/dev/sdb1:
          Magic : a92b4efc
        Version : 1.2
    Feature Map : 0x0
     Array UUID : 9f8c8a03:8036f47c:788bd593:8c0c83cd
           Name : localhost.localdomain:1  (local to host localhost.localdomain)
  Creation Time : Sun Aug 21 01:26:17 2016
     Raid Level : raid1
   Raid Devices : 2

Avail Dev Size : 41908224 (19.98 GiB 21.46 GB)
     Array Size : 20954112 (19.98 GiB 21.46 GB)
    Data Offset : 32768 sectors
   Super Offset : 8 sectors
   Unused Space : before=32680 sectors, after=0 sectors
          State : clean
    Device UUID : 483270f1:90ae6527:ab2ceee6:58ee030d

    Update Time : Sun Aug 21 01:28:01 2016
  Bad Block Log : 512 entries available at offset 72 sectors
       Checksum : 5e434c0e - correct
         Events : 17


   Device Role : Active device 0
   Array State : AA (‘A‘ == active, ‘.‘ == missing, ‘R‘ == replacing)
/dev/sdc1:
          Magic : a92b4efc
        Version : 1.2
    Feature Map : 0x0
     Array UUID : 9f8c8a03:8036f47c:788bd593:8c0c83cd
           Name : localhost.localdomain:1  (local to host localhost.localdomain)
  Creation Time : Sun Aug 21 01:26:17 2016
     Raid Level : raid1
   Raid Devices : 2

Avail Dev Size : 41908224 (19.98 GiB 21.46 GB)
     Array Size : 20954112 (19.98 GiB 21.46 GB)
    Data Offset : 32768 sectors
   Super Offset : 8 sectors
   Unused Space : before=32680 sectors, after=0 sectors
          State : clean
    Device UUID : b6a96682:0ca07895:8fafe1f0:c5761864

    Update Time : Sun Aug 21 01:28:01 2016
  Bad Block Log : 512 entries available at offset 72 sectors
       Checksum : be54c04a - correct
         Events : 17


   Device Role : Active device 1
   Array State : AA (‘A‘ == active, ‘.‘ == missing, ‘R‘ == replacing)
/dev/sdd1:
          Magic : a92b4efc
        Version : 1.2
    Feature Map : 0x0
     Array UUID : 9f8c8a03:8036f47c:788bd593:8c0c83cd
           Name : localhost.localdomain:1  (local to host localhost.localdomain)
  Creation Time : Sun Aug 21 01:26:17 2016
     Raid Level : raid1
   Raid Devices : 2

Avail Dev Size : 41908224 (19.98 GiB 21.46 GB)
     Array Size : 20954112 (19.98 GiB 21.46 GB)
    Data Offset : 32768 sectors
   Super Offset : 8 sectors
   Unused Space : before=32680 sectors, after=0 sectors
          State : clean
    Device UUID : 9ee8a186:310bc49c:66788d58:ec4b1d9a

    Update Time : Sun Aug 21 01:28:01 2016
  Bad Block Log : 512 entries available at offset 72 sectors
       Checksum : 678c0856 - correct
         Events : 17


   Device Role : spare
   Array State : AA (‘A‘ == active, ‘.‘ == missing, ‘R‘ == replacing)
[root@localhost ~]#

查看磁盘阵列状态信息:

技术分享

生成配置信息:

[root@localhost ~]# mdadm -Dvs >> /etc/mdadm.conf
[root@localhost ~]# cat !$     # !$  --> 上一条命令最后一个参数

技术分享

第四步:格式化并挂载

[root@localhost ~]# mkfs.xfs /dev/md1

效果如图:

技术分享

[root@localhost ~]# mkdir /disk

[root@localhost ~]# mount /dev/md1 /disk

[root@localhost ~]# df –h | tail –1

效果如图:

技术分享

第五步:设置开机启动

[root@localhost ~]# echo "/dev/md1 /disk xfs defaults 0 0 " >> /etc/fstab
[root@localhost ~]# cat !$

[root@localhost ~]# df | grep /disk
[root@localhost ~]# umount /disk
[root@localhost ~]# mount –a  #测试,umount /disk 模拟重启,mount –a 模拟开机
[root@localhost ~]# df | tail –1 #检查挂载结果

效果如图:
技术分享

注:也可使用   mount –av   查看挂载信息

技术分享

 

第六步:RAID1磁盘故障模拟及修复

模拟RAID磁盘故障:

[root@localhost ~]# mdadm -D /dev/md1 #查看/dev/md1状态
/dev/md1:
        Version : 1.2
  Creation Time : Sun Aug 21 01:26:17 2016
     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 : Sun Aug 21 01:43:47 2016
          State : clean
Active Devices : 2
Working Devices : 3
Failed Devices : 0
  Spare Devices : 1

           Name : localhost.localdomain:1  (local to host localhost.localdomain)
           UUID : 9f8c8a03:8036f47c:788bd593:8c0c83cd
         Events : 17

    Number   Major   Minor   RaidDevice State
       0       8       17        0      active sync   /dev/sdb1
       1       8       33        1      active sync   /dev/sdc1

       2       8       49        -      spare   /dev/sdd1
[root@localhost ~]# mdadm /dev/md1 -f /dev/sdb1   #设置/dev/sdb1损坏
mdadm: set /dev/sdb1 faulty in /dev/md1
[root@localhost ~]# mdadm -D /dev/md1 #查看/dev/md1状态
/dev/md1:
        Version : 1.2
  Creation Time : Sun Aug 21 01:26:17 2016
     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 : Sun Aug 21 01:44:50 2016
          State : clean, degraded, recovering
Active Devices : 1
Working Devices : 2
Failed Devices : 1
  Spare Devices : 1

Rebuild Status : 3% complete

           Name : localhost.localdomain:1  (local to host localhost.localdomain)
           UUID : 9f8c8a03:8036f47c:788bd593:8c0c83cd
         Events : 19

    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
[root@localhost ~]#

模拟RAID磁盘故障:

1、停用RAID1磁盘阵列

2、清除/dev/sdb1超级块标识

3、激活RAID1磁盘阵列

4、添加/dev/sdb1到磁盘阵列中

详情如下:

[root@localhost ~]# mdadm /dev/md1 --zero-superblock /dev/sdb1 
mdadm: No action given for /dev/md1 in --misc mode
       Action options must come before device names
[root@localhost ~]# mdadm --zero-superblock /dev/sdb1 #磁盘阵列挂载并且激活状态下,去除标志是不会成功的
mdadm: Couldn‘t open /dev/sdb1 for write - not zeroing
[root@localhost ~]# mdadm -S /dev/md1   #停用RAID1磁盘阵列
mdadm: Cannot get exclusive access to /dev/md1:Perhaps a running process, mounted filesystem or active volume group?
[root@localhost ~]# df |grep disk
/dev/md1               20943872   32932  20910940   1% /disk
[root@localhost ~]# umount /disk
[root@localhost ~]# mdadm -S /dev/md1  #停用RAID1磁盘阵列
mdadm: stopped /dev/md1
[root@localhost ~]# mdadm --zero-superblock /dev/sdb1  #清除/dev/sdb1超级块标识
[root@localhost ~]# mdadm -As /dev/md1      #激活RAID1磁盘阵列
mdadm: /dev/md1 has been started with 2 drives.
[root@localhost ~]# mdadm -D /dev/md1
/dev/md1:
        Version : 1.2
  Creation Time : Sun Aug 21 01:26:17 2016
     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 : 2
    Persistence : Superblock is persistent

    Update Time : Sun Aug 21 01:49:16 2016
          State : clean
Active Devices : 2
Working Devices : 2
Failed Devices : 0
  Spare Devices : 0

           Name : localhost.localdomain:1  (local to host localhost.localdomain)
           UUID : 9f8c8a03:8036f47c:788bd593:8c0c83cd
         Events : 36

    Number   Major   Minor   RaidDevice State
       2       8       49        0      active sync   /dev/sdd1
       1       8       33        1      active sync   /dev/sdc1

技术分享
[root@localhost ~]# mdadm /dev/md1 -a /dev/sdb1 #添加/dev/sdb1到磁盘阵列中
mdadm: added /dev/sdb1
[root@localhost ~]# mdadm -D /dev/md1
/dev/md1:
        Version : 1.2
  Creation Time : Sun Aug 21 01:26:17 2016
     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 : Sun Aug 21 01:50:15 2016
          State : clean
Active Devices : 2
Working Devices : 3
Failed Devices : 0
  Spare Devices : 1

           Name : localhost.localdomain:1  (local to host localhost.localdomain)
           UUID : 9f8c8a03:8036f47c:788bd593:8c0c83cd
         Events : 37

    Number   Major   Minor   RaidDevice State
       2       8       49        0      active sync   /dev/sdd1
       1       8       33        1      active sync   /dev/sdc1

       3       8       17        -      spare   /dev/sdb1

技术分享
[root@localhost ~]# mdadm -Dvs >> /etc/mdadm.conf  #重新生成配置信息,在磁盘阵列信息发生改变后,要重新生成配置信息
[root@localhost ~]# cat !$
cat /etc/mdadm.conf
ARRAY /dev/md1 level=raid1 num-devices=2 metadata=1.2 spares=1 name=localhost.localdomain:1 UUID=9f8c8a03:8036f47c:788bd593:8c0c83cd
   devices=/dev/sdb1,/dev/sdc1,/dev/sdd1
ARRAY /dev/md1 level=raid1 num-devices=2 metadata=1.2 spares=1 name=localhost.localdomain:1 UUID=9f8c8a03:8036f47c:788bd593:8c0c83cd
   devices=/dev/sdb1,/dev/sdc1,/dev/sdd1
[root@localhost ~]#

技术分享

1-15-2-RAID1 企业级RAID磁盘阵列的搭建(RAID1、RAID5、RAID10)

标签:

原文地址:http://www.cnblogs.com/xiaogan/p/5791750.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!