前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >CentOS 6.8 创建 RAID-5

CentOS 6.8 创建 RAID-5

原创
作者头像
用户5630738
修改2020-06-28 10:15:36
8960
修改2020-06-28 10:15:36
举报

1 新建三个分区

[root@centos68 ~]# fdisk /dev/sdb
Command (m for help): p

Disk /dev/sdb: 53.7 GB, 53687091200 bytes
255 heads, 63 sectors/track, 6527 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xb5c926a7

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1        3917    31463271    5  Extended
/dev/sdb5               1         654     5253192   83  Linux
/dev/sdb6             655        1308     5253223+  83  Linux
/dev/sdb7            1309        1962     5253223+  83  Linux

2 将分区类型修改为fd(Linux raid autodetect)

Command (m for help): t
Partition number (1-7): 5
Hex code (type L to list codes): fd
Changed system type of partition 5 to fd (Linux raid autodetect)

Command (m for help): t
Partition number (1-7): 6
Hex code (type L to list codes): fd
Changed system type of partition 6 to fd (Linux raid autodetect)

Command (m for help): t
Partition number (1-7): 7
Hex code (type L to list codes): fd
Changed system type of partition 7 to fd (Linux raid autodetect)

Command (m for help): p

Disk /dev/sdb: 53.7 GB, 53687091200 bytes
255 heads, 63 sectors/track, 6527 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xb5c926a7

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1        3917    31463271    5  Extended
/dev/sdb5               1         654     5253192   fd  Linux raid autodetect
/dev/sdb6             655        1308     5253223+  fd  Linux raid autodetect
/dev/sdb7            1309        1962     5253223+  fd  Linux raid autodetect

保存退出

Command (m for help): w
The partition table has been altered!

强制重读磁盘分区表(多运行几次)

[root@centos68 ~]# partx -a /dev/sdb

3 新建空闲分区

[root@centos68 ~]# fdisk /dev/sdb

Command (m for help): n

Command action
   l   logical (5 or over)
   p   primary partition (1-4)
l
First cylinder (1963-3917, default 1963):
Using default value 1963
Last cylinder, +cylinders or +size{K,M,G} (1963-3917, default 3917): +5G

Command (m for help): t
Partition number (1-8): 8
Hex code (type L to list codes): fd
Changed system type of partition 8 to fd (Linux raid autodetect)

Command (m for help): p

Disk /dev/sdb: 53.7 GB, 53687091200 bytes
255 heads, 63 sectors/track, 6527 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xb5c926a7

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1        3917    31463271    5  Extended
/dev/sdb5               1         654     5253192   fd  Linux raid autodetect
/dev/sdb6             655        1308     5253223+  fd  Linux raid autodetect
/dev/sdb7            1309        1962     5253223+  fd  Linux raid autodetect
/dev/sdb8            1963        2616     5253223+  fd  Linux raid autodetect


Command (m for help): w
The partition table has been altered!

# 强制重读分区表
[root@centos68 ~]# partx -a /dev/sdb

4 创建RAID-5

[root@centos68 ~]# mdadm -C /dev/md0 -a yes -n 3 -x 1 -l 5 /dev/sdb{5,6,7,8}
mdadm: Defaulting to version 1.2 metadata
mdadm: array /dev/md0 started.

查看数据同步过程

[root@centos68 ~]# watch -n1 'cat /proc/mdstat'

查看所有md类型设备的状态

[root@centos68 ~]# cat /proc/mdstat
Personalities : [raid6] [raid5] [raid4]
md0 : active raid5 sdb7[4] sdb8[3](S) sdb6[1] sdb5[0]
      10498048 blocks super 1.2 level 5, 512k chunk, algorithm 2 [3/3] [UUU]

unused devices: <none>

查看RAID详细信息

[root@centos68 ~]# mdadm -D /dev/md0
/dev/md0:
        Version : 1.2
  Creation Time : Thu Jun 25 03:49:10 2020
     Raid Level : raid5
     Array Size : 10498048 (10.01 GiB 10.75 GB)
  Used Dev Size : 5249024 (5.01 GiB 5.38 GB)
   Raid Devices : 3
  Total Devices : 4
    Persistence : Superblock is persistent

    Update Time : Thu Jun 25 03:53:07 2020
          State : clean
 Active Devices : 3
Working Devices : 4
 Failed Devices : 0
  Spare Devices : 1

         Layout : left-symmetric
     Chunk Size : 512K

           Name : centos68:0  (local to host centos68)
           UUID : be5cb284:275497f7:be5982ec:ce03ed15
         Events : 18

    Number   Major   Minor   RaidDevice State
       0       8       21        0      active sync   /dev/sdb5
       1       8       22        1      active sync   /dev/sdb6
       4       8       23        2      active sync   /dev/sdb7

       3       8       24        -      spare   /dev/sdb8

5 格式化分区

[root@centos68 ~]# mke2fs -t ext4 /dev/md0

查看

[root@centos68 ~]# df -lh
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/vg_centos68-lv_root
                       50G  861M   46G   2% /
tmpfs                 931M     0  931M   0% /dev/shm
/dev/sda1             477M   39M  413M   9% /boot
/dev/mapper/vg_centos68-lv_home
                       45G   52M   43G   1% /home
/dev/md0              9.8G   23M  9.3G   1% /data

实现开机自动挂载

[root@centos68 ~]# blkid /dev/md0
/dev/md0: UUID="e2303c17-62a6-4938-aa7a-d5b9c52ab4ea" TYPE="ext4"
# 建议使用UUID进行挂载或者LABEL卷标挂载
[root@centos68 ~]# tail -1 /etc/fstab
UUID=e2303c17-62a6-4938-aa7a-d5b9c52ab4ea       /data   defaults,acl    0 0

6 模拟坏盘

[root@centos68 ~]# mdadm /dev/md0 -f /dev/sdb5
mdadm: set /dev/sdb5 faulty in /dev/md0

查看备用盘同步过程

[root@centos68 ~]# cat /proc/mdstat # 或者使用 watch -n1 'cat /proc/mdstat' 动态观察恢复过程
Personalities : [raid6] [raid5] [raid4]
md0 : active raid5 sdb7[4] sdb8[3] sdb6[1] sdb5[0](F)
      10498048 blocks super 1.2 level 5, 512k chunk, algorithm 2 [3/2] [_UU]
      [=>...................]  recovery =  6.8% (359808/5249024) finish=0.6min speed=119936K/sec

unused devices: <none>

再次查看RAID详细信息

==备用盘sdb8已经顶替坏盘sdb5==

[root@centos68 ~]# mdadm -D /dev/md0
/dev/md0:
        Version : 1.2
  Creation Time : Thu Jun 25 03:49:10 2020
     Raid Level : raid5
     Array Size : 10498048 (10.01 GiB 10.75 GB)
  Used Dev Size : 5249024 (5.01 GiB 5.38 GB)
   Raid Devices : 3
  Total Devices : 4
    Persistence : Superblock is persistent

    Update Time : Thu Jun 25 04:07:21 2020
          State : clean
 Active Devices : 3
Working Devices : 3
 Failed Devices : 1
  Spare Devices : 0

         Layout : left-symmetric
     Chunk Size : 512K

           Name : centos68:0  (local to host centos68)
           UUID : be5cb284:275497f7:be5982ec:ce03ed15
         Events : 37

    Number   Major   Minor   RaidDevice State
       3       8       24        0      active sync   /dev/sdb8
       1       8       22        1      active sync   /dev/sdb6
       4       8       23        2      active sync   /dev/sdb7

       0       8       21        -      faulty   /dev/sdb5

7 模拟坏盘并观察数据是否正常访问

拷贝测试数据到RAID-5挂载点/data

[root@centos68 ~]# cp /etc/passwd /data/
[root@centos68 ~]# ll /data/passwd
-rw-r--r--. 1 root root 887 Jun 25 04:13 /data/passwd
[root@centos68 ~]# cat /etc/passwd

模拟坏盘/dev/sdb8,观察state状态

[root@centos68 ~]# mdadm /dev/md0 -f /dev/sdb8
mdadm: set /dev/sdb8 faulty in /dev/md0
[root@centos68 ~]# mdadm -D /dev/md0
/dev/md0:
        Version : 1.2
  Creation Time : Thu Jun 25 03:49:10 2020
     Raid Level : raid5
     Array Size : 10498048 (10.01 GiB 10.75 GB)
  Used Dev Size : 5249024 (5.01 GiB 5.38 GB)
   Raid Devices : 3
  Total Devices : 4
    Persistence : Superblock is persistent

    Update Time : Thu Jun 25 04:15:23 2020
          State : clean, degraded # 降级运行模式
 Active Devices : 2
Working Devices : 2
 Failed Devices : 2
  Spare Devices : 0

         Layout : left-symmetric # 默认布局左对称
     Chunk Size : 512K

           Name : centos68:0  (local to host centos68)
           UUID : be5cb284:275497f7:be5982ec:ce03ed15
         Events : 39

    Number   Major   Minor   RaidDevice State
       0       0        0        0      removed
       1       8       22        1      active sync   /dev/sdb6
       4       8       23        2      active sync   /dev/sdb7

       0       8       21        -      faulty   /dev/sdb5
       3       8       24        -      faulty   /dev/sdb8

测试数据是否正常访问

[root@centos68 ~]# cd /data
[root@centos68 data]# cat passwd
root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin

8 移除坏盘

[root@centos68 data]# mdadm /dev/md0 -r /dev/sdb5
mdadm: hot removed /dev/sdb5 from /dev/md0
[root@centos68 data]# mdadm /dev/md0 -r /dev/sdb8
mdadm: hot removed /dev/sdb8 from /dev/md0
[root@centos68 data]# mdadm -D /dev/md0
/dev/md0:
        Version : 1.2
  Creation Time : Thu Jun 25 03:49:10 2020
     Raid Level : raid5
     Array Size : 10498048 (10.01 GiB 10.75 GB)
  Used Dev Size : 5249024 (5.01 GiB 5.38 GB)
   Raid Devices : 3
  Total Devices : 2
    Persistence : Superblock is persistent

    Update Time : Thu Jun 25 04:19:05 2020
          State : clean, degraded
 Active Devices : 2
Working Devices : 2
 Failed Devices : 0
  Spare Devices : 0

         Layout : left-symmetric
     Chunk Size : 512K

           Name : centos68:0  (local to host centos68)
           UUID : be5cb284:275497f7:be5982ec:ce03ed15
         Events : 45

    Number   Major   Minor   RaidDevice State
       0       0        0        0      removed
       1       8       22        1      active sync   /dev/sdb6
       4       8       23        2      active sync   /dev/sdb7

9 添加磁盘

[root@centos68 data]# mdadm /dev/md0 -a /dev/sdb5
mdadm: added /dev/sdb5

查看数据同步过程

[root@centos68 data]# watch -n1 'cat /proc/mdstat'

Every 1.0s: cat /proc/mdstat                                   Thu Jun 25 04:23:04 2020

Personalities : [raid6] [raid5] [raid4]
md0 : active raid5 sdb5[3] sdb7[4] sdb6[1]
      10498048 blocks super 1.2 level 5, 512k chunk, algorithm 2 [3/2] [_UU]
      [================>....]  recovery = 82.0% (4309708/5249024) finish=0.1min speed=1
00386K/sec

unused devices: <none>

参考文档:https://cloud.tencent.com/developer/article/1562726

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 1 新建三个分区
  • 2 将分区类型修改为fd(Linux raid autodetect)
  • 3 新建空闲分区
  • 4 创建RAID-5
  • 5 格式化分区
  • 6 模拟坏盘
  • 7 模拟坏盘并观察数据是否正常访问
  • 8 移除坏盘
  • 9 添加磁盘
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档