Linux创建RAID5实战

Linux创建RAID5

  1. RAID5最少由三个硬盘组成,它将数据分散存储于阵列中的每个硬盘,并且还伴有一个数据校验位,数据位与校验位通过算法能相互验证
  2. RAID5最多能允许一个硬盘损坏,有容错性
  3. RAID5相对于其它的组合方式,在容错与成本方面有一个平衡,一般的磁盘阵列,最常使用的就是RAID5这种方式

创建RAID5,并格式化,挂载使用

  1. 添加4块虚拟硬盘,并全部分区,分区ID为fd
[root@localhost ~]# lsblk 
NAME          MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda             8:0    0   10G  0 disk 
sdb             8:16   0   10G  0 disk 
sdc             8:32   0   10G  0 disk 
sdd             8:48   0   10G  0 disk 
sr0            11:0    1  7.3G  0 rom  
nvme0n1       259:0    0   80G  0 disk 
├─nvme0n1p1   259:1    0    1G  0 part /boot
└─nvme0n1p2   259:2    0   79G  0 part 
  ├─rhel-root 253:0    0   50G  0 lvm  /
  ├─rhel-swap 253:1    0    2G  0 lvm  [SWAP]
  └─rhel-home 253:2    0   27G  0 lvm  /home
  • 查看已经分区的四块硬盘
[root@localhost ~]# fdisk -l | grep raid
/dev/sda1        2048 20971519 20969472  10G fd Linux raid autodetect
/dev/sdc1        2048 20971519 20969472  10G fd Linux raid autodetect
/dev/sdb1        2048 20971519 20969472  10G fd Linux raid autodetect
/dev/sdd1        2048 20971519 20969472  10G fd Linux raid autodetect
  1. 创建RAID5,并添加1个热备份盘
[root@localhost ~]# mdadm -C -v /dev/md5 -l5 -n3 /dev/sd{a,b,c}1 -x1 /dev/sdd
mdadm: layout defaults to left-symmetric
mdadm: layout defaults to left-symmetric
mdadm: chunk size defaults to 512K
mdadm: partition table exists on /dev/sdd
mdadm: partition table exists on /dev/sdd but will be lost or
       meaningless after creating array
mdadm: size set to 10475520K
Continue creating array? y
mdadm: Defaulting to version 1.2 metadata
mdadm: array /dev/md5 started.
  1. 查看 raidstat 状态
[root@localhost ~]# cat /proc/mdstat 
Personalities : [raid6] [raid5] [raid4] 
md5 : active raid5 sdc1[4] sdd[3](S) sdb1[1] sda1[0]
      20951040 blocks super 1.2 level 5, 512k chunk, algorithm 2 [3/2] [UU_]
      [==================>..]  recovery = 91.0% (9533852/10475520) finish=0.0min speed=202150K/sec
      
unused devices: <none>
//再次查看
[root@localhost ~]# cat /proc/mdstat 
Personalities : [raid6] [raid5] [raid4] 
md5 : active raid5 sdc1[4] sdd[3](S) sdb1[1] sda1[0]
      20951040 blocks super 1.2 level 5, 512k chunk, algorithm 2 [3/3] [UUU]
      
unused devices: <none>
  1. 查看 RAID5 的详细信息
[root@localhost ~]# mdadm -D /dev/md5 
/dev/md5:
           Version : 1.2
     Creation Time : Wed Dec 16 14:08:53 2020
        Raid Level : raid5
        Array Size : 20951040 (19.98 GiB 21.45 GB)
     Used Dev Size : 10475520 (9.99 GiB 10.73 GB)
      Raid Devices : 3
     Total Devices : 4
       Persistence : Superblock is persistent

       Update Time : Wed Dec 16 14:09:46 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 : localhost:5  (local to host localhost)
              UUID : 4b8e1fdf:7389efbb:77633231:48a89857
            Events : 18

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

       3       8       48        -      spare   /dev/sdd
  1. 格式化 /dev/md5 ,格式化类型为xfs
[root@localhost ~]# mkfs.xfs /dev/md5 
meta-data=/dev/md5               isize=512    agcount=16, agsize=327296 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=1, sparse=1, rmapbt=0
         =                       reflink=1
data     =                       bsize=4096   blocks=5236736, 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
[root@localhost ~]# blkid /dev/md5 
/dev/md5: UUID="d1a0805f-5685-4af8-9935-9abb1dae7636" TYPE="xfs"
  1. 挂载 /dev/md5 ,挂载点为 /radi5
[root@localhost ~]# mkdir /raid5
[root@localhost ~]# mount /dev/md5 /raid5
[root@localhost ~]# df -h
Filesystem             Size  Used Avail Use% Mounted on
devtmpfs               887M     0  887M   0% /dev
tmpfs                  904M     0  904M   0% /dev/shm
tmpfs                  904M  8.7M  895M   1% /run
tmpfs                  904M     0  904M   0% /sys/fs/cgroup
/dev/mapper/rhel-root   50G  4.5G   46G   9% /
/dev/mapper/rhel-home   27G  225M   27G   1% /home
/dev/nvme0n1p1        1014M  173M  842M  18% /boot
tmpfs                  181M     0  181M   0% /run/user/0
/dev/md5                20G  176M   20G   1% /raid5

版权声明:本文为itwangqiang原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://www.cnblogs.com/itwangqiang/p/14143602.html