centos7配置软RAID5

技术文章 10个月前 完美者
1,378 0

标签:阵列   top   命令   标签   width   uil   alt   logic   mail   

1、配置环境介绍
操作平台:VMware workstation
测试环境:centos7 计算机一台,添加一块新的硬盘,创建4个分区。模拟4块新硬盘
2、实践目的
1、配置RAID5
2、模拟硬盘故障,检验RAID5容错能力,并实现故障盘替换
3、RAID阵列上创建分区
3、创建RAID准备工作
1、首先查看硬盘标签类型

[root@adong ~]# fdisk -l /dev/sdc 
Disk /dev/sdb: 20 GiB, 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
Disklabel type: gpt #为GPT类型
Disk identifier: 0x25cc0f39

2、因为硬盘标签类型为GPT,左移我们用gdisk命令创建分区即可

[root@adong ~]# gdisk /dev/sdc
GPT fdisk (gdisk) version 1.0.3
Partition table scan:
  MBR: protective
  BSD: not present
  APM: not present
  GPT: present
Found valid GPT with protective MBR; using GPT.
Command (? for help): n         #新建分区
Partition number (1-128, default 1):        #默认分区编号即可,默认从1开始
First sector (34-41943006, default = 2048) or {+-}size{KMGTP}:      #指定起始扇区大小,默认即可
Last sector (2048-41943006, default = 41943006) or {+-}size{KMGTP}: +5G     #指定分区大小
Current type is ‘Linux filesystem‘
Hex code or GUID (L to show codes, Enter = 8300): fd00      #更改分区类型为LinuxRAID
Changed type of partition to ‘Linux RAID‘

重复上述步骤,建立4个分区,然后如下操作保存退出

Command (? for help): w     #保存分区
Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING
PARTITIONS!!
Do you want to proceed? (Y/N): Y    #上面提示将写入GPT分区数据,这样会覆盖原来的分区,是否继续
OK; writing new GUID partition table (GPT) to /dev/sdc.
The operation has completed successfully.

此时用于模拟4块硬盘的分区就创建好了
3、使用mdadm工具创建RAID,阵列的成员可以使用通配符

[root@adong ~]# mdadm --create /dev/md0 --level=5 --raid-devices=3 --spare-device=1 /dev/sdc[1-4]
mdadm: Defaulting to version 1.2 metadata
mdadm: array /dev/md0 started.

说明:因为做RAID5最少需要3块磁盘,此前我们创建了4个分区模拟4个磁盘,所以创建时我们通过--raid-devices选项指定用于创建raid的磁盘数为3,然后将剩余的一个磁盘通过--spare-device选项设置为备用磁盘。
4、查看RAID配置的详细信息

[root@adong ~]# mdadm --detail /dev/md0 
/dev/md0:
           Version : 1.2
     Creation Time : Sat Dec 12 10:03:04 2020
        Raid Level : raid5
        Array Size : 10475520 (9.99 GiB 10.73 GB)
     Used Dev Size : 5237760 (5.00 GiB 5.36 GB)
      Raid Devices : 3
     Total Devices : 4
       Persistence : Superblock is persistent
       Update Time : Sat Dec 12 10:03:31 2020
             State : clean 
    Active Devices : 3
   Working Devices : 4
    Failed Devices : 0
     Spare Devices : 1
            Layout : left-symmetric
        Chunk Size : 512K
Consistency Policy : resync
              Name : adong.com:0  (local to host adong.com)
              UUID : 597cac50:2c13e44b:f5a87d17:c0f2fc8e
            Events : 18
    Number   Major   Minor   RaidDevice State
       0       8       33        0      active sync   /dev/sdc1
       1       8       34        1      active sync   /dev/sdc2
       4       8       35        2      active sync   /dev/sdc3
       3       8       36        -      spare   /dev/sdc4

通过上述信息,我们可以看到,有3块硬盘处于active激活的状态并sync同步中,一块硬盘处于spare备用状态
5、模拟磁盘故障、查看备用盘的工作情况

[root@adong ~]# mdadm /dev/md0 --fail /dev/sdc2
mdadm: set /dev/sdc2 faulty in /dev/md0

通过--fail选项模拟其中一块磁盘故障

[root@adong ~]# mdadm --detail /dev/md0 
/dev/md0:
           Version : 1.2
     Creation Time : Sat Dec 12 10:03:04 2020
        Raid Level : raid5
        Array Size : 10475520 (9.99 GiB 10.73 GB)
     Used Dev Size : 5237760 (5.00 GiB 5.36 GB)
      Raid Devices : 3
     Total Devices : 4
       Persistence : Superblock is persistent
       Update Time : Sat Dec 12 10:14:34 2020
             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 : 21% complete
              Name : adong.com:0  (local to host adong.com)
              UUID : 597cac50:2c13e44b:f5a87d17:c0f2fc8e
            Events : 23
    Number   Major   Minor   RaidDevice State
       0       8       33        0      active sync   /dev/sdc1
       3       8       36        1      spare rebuilding   /dev/sdc4
       4       8       35        2      active sync   /dev/sdc3
       1       8       34        -      faulty   /dev/sdc2

此时我们发现原来备用状态的/dev/sdc4,此时正在进行备用重建,加入到RAID中,替换故障磁盘
6、故障盘修复或者更换新的物理盘,替换原来的问题磁盘
如果是现实物理环境,将新的物理磁盘更换上去即可,此处我们模拟环境,所以首先要手动移除故障磁盘

[root@adong ~]# mdadm /dev/md0 --remove /dev/sdc2
mdadm: hot removed /dev/sdc2 from /dev/md0

然后将新的磁盘添加上去

[root@adong ~]# mdadm /dev/md0 --add /dev/sdb1
mdadm: added /dev/sdb1

此时我们查看RAID的信息,发现新添加上的磁盘,处于备用状态。一切恢复正常

[root@adong ~]# mdadm --detail /dev/md0 
/dev/md0:
           Version : 1.2
     Creation Time : Sat Dec 12 10:03:04 2020
        Raid Level : raid5
        Array Size : 10475520 (9.99 GiB 10.73 GB)
     Used Dev Size : 5237760 (5.00 GiB 5.36 GB)
      Raid Devices : 3
     Total Devices : 4
       Persistence : Superblock is persistent
       Update Time : Sat Dec 12 10:21:39 2020
             State : clean 
    Active Devices : 3
   Working Devices : 4
    Failed Devices : 0
     Spare Devices : 1
            Layout : left-symmetric
        Chunk Size : 512K
Consistency Policy : resync
              Name : adong.com:0  (local to host adong.com)
              UUID : 597cac50:2c13e44b:f5a87d17:c0f2fc8e
            Events : 39
    Number   Major   Minor   RaidDevice State
       0       8       33        0      active sync   /dev/sdc1
       3       8       36        1      active sync   /dev/sdc4
       4       8       35        2      active sync   /dev/sdc3
       5       8       17        -      spare   /dev/sdb1

注意:更换的磁盘大小一定要和现有RAID中的磁盘大小一样
7、在RAID阵列上创建分区,并格式化文件系统为xfs
阵列磁盘对操作系统而言,一样是一个逻辑磁盘,所以我们可以像操作单个磁盘一样对他进行创建分区和格式化文件系统

[root@adong ~]# gdisk /dev/md0 
GPT fdisk (gdisk) version 1.0.3
Partition table scan:
  MBR: not present
  BSD: not present
  APM: not present
  GPT: not present
Creating new GPT entries.
Command (? for help): n         #新建分区
Partition number (1-128, default 1):    #指定分区编号
First sector (34-20951006, default = 2048) or {+-}size{KMGTP}:      #指定起始扇区
Last sector (2048-20951006, default = 20951006) or {+-}size{KMGTP}: +5G     #设置分区大小
Current type is ‘Linux filesystem‘
Hex code or GUID (L to show codes, Enter = 8300): 
Changed type of partition to ‘Linux filesystem‘
Command (? for help): w     #保存分区
Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING
PARTITIONS!!
Do you want to proceed? (Y/N): Y    #将要写入GPT分区去数据,原来的分区数据将被覆盖,是否继续
OK; writing new GUID partition table (GPT) to /dev/md0.
The operation has completed successfully.

8、查看分区情况,发现生成一个/dev/mdop1的分区

[root@adong ~]# fdisk -l  /dev/md0
Disk /dev/md0: 10 GiB, 10726932480 bytes, 20951040 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 524288 bytes / 1048576 bytes
Disklabel type: gpt
Disk identifier: BD1E493E-652F-4676-AA07-FCC0D601F15C

Device     Start      End  Sectors Size Type
/dev/md0p1  2048 10487807 10485760   5G Linux filesystem

9、针对上述生成的分区记性格式化文件系统xfs

[root@adong ~]# mkfs.xfs /dev/md0p1 
meta-data=/dev/md0p1             isize=512    agcount=8, agsize=163712 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=1, sparse=1, rmapbt=0
         =                       reflink=1
data     =                       bsize=4096   blocks=1309696, imaxpct=25
         =                       sunit=128    swidth=256 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

10、挂载分区到指定目录/mnt

[root@adong ~]# mount /dev/md0p1 /mnt/

11、查看磁盘分区使用情况,可以看到/dev/mdop1/被挂载到了/mnt/使用空间为5G

[root@adong ~]# df -h
Filesystem      Size  Used Avail Use% Mounted on
devtmpfs        383M     0  383M   0% /dev
tmpfs           399M     0  399M   0% /dev/shm
tmpfs           399M   11M  388M   3% /run
tmpfs           399M     0  399M   0% /sys/fs/cgroup
/dev/sda2        23G   12G   11G  53% /
/dev/sda3       6.0G   83M  6.0G   2% /home
/dev/sda1       3.7G  203M  3.3G   6% /boot
tmpfs            80M  4.0K   80M   1% /run/user/0
/dev/md0p1      5.0G   69M  5.0G   2% /mnt      

总结:
额外常用的一些软RAID操作命令
1.停止RAID
mdadm --stop /dev/md0
2、删除RAID
首先停止RAID
然后清除RAID阵列中所有磁盘元数据,这样就彻底删除了,重启系统也不会被自动安装
mdadm --zero-superblock /dev/sdc1
3、监控RAID,如果出现故障,通知管理员
nohup mdadm --monitor --mail=root@localhost.com --delay=180 /dev/md0
nohup:将监控任务放置后台运行
delay选项:每个多久对阵列检查一下

centos7配置软RAID5

标签:阵列   top   命令   标签   width   uil   alt   logic   mail   

原文地址:https://blog.51cto.com/6461704/2563074

版权声明:完美者 发表于 2020-12-17 13:09:44。
转载请注明:centos7配置软RAID5 | 完美导航

暂无评论

暂无评论...