• Linux 磁盘管理--RAID5创建


    准备

    • mdadm
    • 三块新硬盘

    安装mdadm

    • 尝试使用yum install -y mdadm进行安装,可能是我源的问题.竟然报错了
    [root@localhost dev]# yum install -y madadm
    Loaded plugins: fastestmirror
    Loading mirror speeds from cached hostfile
    epel/x86_64/metalink                                                                                  |  10 kB  00:00:00
     * base: mirrors.aliyun.com
     * epel: mirrors.aliyun.com
     * extras: mirrors.aliyun.com
     * updates: mirrors.aliyun.com
    base                                                                                                  | 3.6 kB  00:00:00
    epel                                                                                                  | 4.7 kB  00:00:00
    extras                                                                                                | 2.9 kB  00:00:00
    updates                                                                                               | 2.9 kB  00:00:00
    (1/2): epel/x86_64/updateinfo                                                                         | 1.0 MB  00:00:00
    (2/2): epel/x86_64/primary_db                                                                         | 6.8 MB  00:00:03
    No package madadm available.
    Error: Nothing to do
    
    • 所以只能本地使用rpm包进行安装
      • 挂载镜像
    [root@localhost dev]# mount /dev/cdrom /mnt
    
    • 安装mdadm
    [root@localhost dev]# rpm -ivh mdadm-3.2.6-31.el7.x86_64.rpm
    error: Failed dependencies:
        libreport-filesystem is needed by mdadm-3.2.6-31.el7.x86_64
    
    • 安装libreport-filesystemmdadm
    [root@localhost dev]# rpm -ivh mdadm-3.2.6-31.el7.x86_64.rpm libreport-filesystem-2.1.11-10.el7.centos.x86_64.rpm
    Preparing...                         ################################# [100%]
    Updating / installing...
      1:libreport-filesystem-2.1.11-10.el################################# [50%]
      2:mdadm-3.2.6-31.el7              ################################# [100%]
    

    创建RAID5

    [root@localhost dev]# mdadm -C /dev/md5 -l 5 -n 3 /dev/sd{b,c,d}
    mdadm: largest drive (/dev/sdc) exceeds size (8380416K) by more than 1%
    Continue creating array? y
    mdadm: Defaulting to version 1.2 metadata
    mdadm: array /dev/md5 started.
    

    参数

    参数 注释
    -C 创建RAID
    /dev/md5 第一个RAID设备
    -l 5 RAID5
    -n RAID成员的数量

    格式化并挂载

    格式化为xfs

    [root@localhost dev]# mkfs.xfs /dev/md5
    meta-data=/dev/md5               isize=512    agcount=16, agsize=261760 blks
             =                       sectsz=512   attr=2, projid32bit=1
             =                       crc=1        finobt=0, sparse=0
    data     =                       bsize=4096   blocks=4188160, 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=8 blks, lazy-count=1
    realtime =none                   extsz=4096   blocks=0, rtextents=0
    

    挂载分区

    • 新建md5目录
    [root@localhost /]# mkdir md5
    
    • 挂载分区
    [root@localhost /]# mount /dev/md5 /md5
    

    验证md5是否可用

    • 新建文件
    [root@localhost md5]# touch a{1,2,3} && ll
    total 0
    -rw-r--r-- 1 root root 0 Apr  7 12:39 a1
    -rw-r--r-- 1 root root 0 Apr  7 12:39 a2
    -rw-r--r-- 1 root root 0 Apr  7 12:39 a3
    
    • 卸载md5
    [root@localhost md5]# umount /dev/md5
    
    • 查看md5目录,发现什么都没了
    [root@localhost /]# ll /md5
    total 0
    
    • 重新挂载md5,文件找回,则md5分区正常
    [root@localhost /]# mount /dev/md5 /md5
    [root@localhost /]# ll /md5
    total 0
    -rw-r--r-- 1 root root 0 Apr  7 12:39 a1
    -rw-r--r-- 1 root root 0 Apr  7 12:39 a2
    -rw-r--r-- 1 root root 0 Apr  7 12:39 a3
    

    查看RAID信息

    [root@localhost /]# mdadm -D /dev/md5 //-D查看详细信息
    /dev/md5:
            Version : 1.2
      Creation Time : Tue Apr  7 10:54:01 2020
         Raid Level : raid5
         Array Size : 16760832 (15.98 GiB 17.16 GB)
      Used Dev Size : 8380416 (7.99 GiB 8.58 GB)
       Raid Devices : 3
      Total Devices : 3
        Persistence : Superblock is persistent
    
        Update Time : Tue Apr  7 12:49:32 2020
              State : clean
     Active Devices : 3
    Working Devices : 3
     Failed Devices : 0
      Spare Devices : 0
    
             Layout : left-symmetric
         Chunk Size : 512K
    
               Name : localhost.localdomain:5  (local to host localhost.localdomain)
               UUID : 92c54122:08d15045:5724004d:5971e4d1
             Events : 18
    
        Number   Major   Minor   RaidDevice State
           0       8       16        0      active sync   /dev/sdb
           1       8       32        1      active sync   /dev/sdc
           3       8       48        2      active sync   /dev/sdd
    

    模拟一块磁盘损坏

    先对分区进行卸载

    [root@localhost md5]# umount /dev/md5
    

    模拟磁盘损坏并移除

    [root@localhost ~]# mdadm /dev/md5 -f /dev/sdc -r /dev/sdc
    mdadm: set /dev/sdc faulty in /dev/md5
    mdadm: hot removed /dev/sdc from /dev/md5
    

    查看RAID信息

    [root@localhost ~]# mdadm -D /dev/md5
    /dev/md5:
            Version : 1.2
      Creation Time : Tue Apr  7 10:54:01 2020
         Raid Level : raid5
         Array Size : 16760832 (15.98 GiB 17.16 GB)
      Used Dev Size : 8380416 (7.99 GiB 8.58 GB)
       Raid Devices : 3
      Total Devices : 2
        Persistence : Superblock is persistent
    
        Update Time : Tue Apr  7 12:56:41 2020
              State : clean, degraded
     Active Devices : 2
    Working Devices : 2
     Failed Devices : 0
      Spare Devices : 0
    
             Layout : left-symmetric
         Chunk Size : 512K
    
               Name : localhost.localdomain:5  (local to host localhost.localdomain)
               UUID : 92c54122:08d15045:5724004d:5971e4d1
             Events : 21
    
        Number   Major   Minor   RaidDevice State
           0       8       16        0      active sync   /dev/sdb
           -       0        0        1      removed
           3       8       48        2      active sync   /dev/sdd
    

    重新挂载md5,发现数据依然存在

    [root@localhost ~]# mount /dev/md5 /md5
    [root@localhost ~]# ll /md5
    total 0
    -rw-r--r-- 1 root root 0 Apr  7 12:39 a1
    -rw-r--r-- 1 root root 0 Apr  7 12:39 a2
    -rw-r--r-- 1 root root 0 Apr  7 12:39 a3
    
  • 相关阅读:
    实现一个简易版的react
    浅学virtualDom和diff算法
    148. 排序链表 归并排序 | 快速排序
    OC中的NSDictionary和NSMutableDictionary
    OC中的block
    OC中的category&Extension
    OC中判断方法是否实现
    OC的分组导航标记
    OC中程序的内存分布&类加载
    OC中的@property和@synthesize
  • 原文地址:https://www.cnblogs.com/quail2333/p/12652145.html
Copyright © 2020-2023  润新知