创建软RAID

通过mdadm工具创建软RAID5
在虚拟机上新加一块磁盘,

1、创建分区(sdb1.2.3.4.5,sdb4为扩展分区,sdb5为逻辑分区)

[root@centos6 ~]# fdisk /dev/sdb
Device contains neither a valid DOS partition table, nor   Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier   0xfa8dcf95.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won't be recoverable.

Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)

WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
     switch off the mode (command 'c') and change display units to
     sectors (command 'u').

Command (m for help): p

Disk /dev/sdb: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 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: 0xfa8dcf95

 Device Boot      Start         End      Blocks   Id  System

Command (m for help): n
Command action
 e   extended
 p   primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-2610, default 1):
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-2610, default 2610): +100M

Command (m for help): n
Command action
e   extended
p   primary partition (1-4)
p
Partition number (1-4): 2
First cylinder (15-2610, default 15):
Using default value 15
Last cylinder, +cylinders or +size{K,M,G} (15-2610, default 2610): +200M

Command (m for help): n
Command action
e   extended
p   primary partition (1-4)
p
Partition number (1-4): 3
First cylinder (41-2610, default 41):
Using default value 41
Last cylinder, +cylinders or +size{K,M,G} (41-2610, default 2610): +300M

Command (m for help): n
Command action
e   extended
p   primary partition (1-4)
e
Selected partition 4
First cylinder (80-2610, default 80):
Using default value 80
Last cylinder, +cylinders or +size{K,M,G} (80-2610, default 2610):
Using default value 2610

Command (m for help): n
First cylinder (80-2610, default 80):
Using default value 80
Last cylinder, +cylinders or +size{K,M,G} (80-2610, default 2610): +100M

Command (m for help): p

Disk /dev/sdb: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 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: 0xfa8dcf95

 Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1          14      112423+  83  Linux
/dev/sdb2              15          40      208845   83  Linux
/dev/sdb3              41          79      313267+  83  Linux
/dev/sdb4              80        2610    20330257+   5  Extended
/dev/sdb5              80          93      112423+  83  Linux

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

Calling ioctl() to re-read partition table.
Syncing disks.

更新新创建的分区

[root@centos6 ~]# partx -a /dev/sdb
BLKPG: Device or resource busy
error adding partition 1
BLKPG: Device or resource busy
error adding partition 2
BLKPG: Device or resource busy
error adding partition 3
BLKPG: Device or resource busy
error adding partition 4
BLKPG: Device or resource busy
error adding partition 5
[root@centos6 ~]# partx -a /dev/sdb
BLKPG: Device or resource busy
error adding partition 1
BLKPG: Device or resource busy
error adding partition 2
BLKPG: Device or resource busy
error adding partition 3
BLKPG: Device or resource busy
error adding partition 4
BLKPG: Device or resource busy
error adding partition 5

2、创建RAID5
设定/dev/sdb5作为备用磁盘,其余作为活动磁盘

[root@centos6 ~]# mdadm --create /dev/md0 --level=5 --raid-devices=3 --spare-devices=1 /dev/sdb{1,2,3,5}
mdadm: largest drive (/dev/sdb3) exceeds size (111104K) by more than 1%
Continue creating array?
Continue creating array? (y/n) y
mdadm: Defaulting to version 1.2 metadata
mdadm: array /dev/md0 started.
[root@centos6 ~]# mdadm --detail /dev/md0
/dev/md0:
    Version : 1.2
  Creation Time : Fri Apr  3 18:39:06 2020
 Raid Level : raid5
 Array Size : 222208 (217.00 MiB 227.54 MB)
 Used Dev Size : 111104 (108.50 MiB 113.77 MB)
Raid Devices : 3
 Total Devices : 4
Persistence : Superblock is persistent

Update Time : Fri Apr  3 18:39:08 2020
      State : clean
 Active Devices : 3
Working Devices : 4
 Failed Devices : 0
 Spare Devices : 1

     Layout : left-symmetric
 Chunk Size : 512K

       Name : centos6.8:0  (local to host centos6.8)
       UUID : ee8b3bf8:01aa6adb:fbfe5a75:559f98d7
     Events : 18

Number   Major   Minor   RaidDevice State
   0       8       17        0      active sync   /dev/sdb1
   1       8       18        1      active sync   /dev/sdb2
   4       8       19        2      active sync   /dev/sdb3

   3       8       21        -      spare   /dev/sdb5

3、创建RAID的配置文件
RAID的配置文件名为"mdadm.conf",默认是不存在的,所以需要手工创建。生成的“mdadm.conf”文件的内容并不符合所规定的格式,即他不生效,手动修改格式如下。

DEVICE /dev/sdb1 /dev/sdb2 /dev/sdb3 /dev/sdb5
ARRAY /dev/md0 level=raid5 num-devices=3 UUID : ee8b3bf8:01aa6adb:fbfe5a75:559f98d7

~
~
~
~
~
~
~
~
~

"/etc/mdadm.conf" 3L, 132C

若没有创建RAID的配置文件,那么在系统每次启动后,需要手工手动加载RAID才能使用,命令如下:(由于我已启动,因此显示正忙)
[root@centos6 ~]# mdadm --assemble /dev/md0 /dev/sdb1 /dev/sdb2 /dev/sdb3 /dev/sdb5
mdadm: only give one device per ARRAY line: /dev/md0 and UUID
mdadm: only give one device per ARRAY line: /dev/md0 and :
mdadm: only give one device per ARRAY line: /dev/md0 and ee8b3bf8:01aa6adb:fbfe5a75:559f98d7
mdadm: ARRAY line /dev/md0 has no identity information.
mdadm: /dev/sdb1 is busy - skipping
mdadm: /dev/sdb2 is busy - skipping
mdadm: /dev/sdb3 is busy - skipping
mdadm: /dev/sdb5 is busy - skipping

4、创建文件系统
规定一个/dev/md0目录下创建文件系统,创完文件系统后,挂载就可使用了。

[root@centos6 ~]# mkfs.ext4 /dev/md0
mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS type: Linux
Block size=1024 (log=0)
Fragment size=1024 (log=0)
Stride=512 blocks, Stripe width=1024 blocks
55552 inodes, 222208 blocks
11110 blocks (5.00%) reserved for the super user
First data block=1
Maximum filesystem blocks=67371008
28 block groups
8192 blocks per group, 8192 fragments per group
1984 inodes per group
Superblock backups stored on blocks:
    8193, 24577, 40961, 57345, 73729, 204801, 221185

Writing inode tables: done
Creating journal (4096 blocks): done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 34 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.
[root@centos6 ~]# cat /proc/mdstat
Personalities : [raid6] [raid5] [raid4]
md0 : active raid5 sdb3[4] sdb5[3](S) sdb2[1] sdb1[0]
  222208 blocks super 1.2 level 5, 512k chunk, algorithm 2 [3/3] [UUU]

unused devices: <none>

5、模拟故障磁盘
若软RAID检测到某个磁盘有故障时,会自动标记该磁盘为故障磁盘,并停止对故障磁盘的读写操作,标记命令如下(这里指定sdb3为故障磁盘)当一个设备出现故障或标记故障,相应的设备方括号后将被标记为(F)

[root@centos6 ~]# mdadm /dev/md0 --fail /dev/sdb3
mdadm: only give one device per ARRAY line: /dev/md0 and UUID
mdadm: only give one device per ARRAY line: /dev/md0 and :
mdadm: only give one device per ARRAY line: /dev/md0 and ee8b3bf8:01aa6adb:fbfe5a75:559f98d7
mdadm: ARRAY line /dev/md0 has no identity information.
mdadm: set /dev/sdb3 faulty in /dev/md0
[root@centos6 ~]# cat /proc/mdstat
Personalities : [raid6] [raid5] [raid4]
md0 : active raid5 sdb3[4](F) sdb5[3] sdb2[1] sdb1[0]
  222208 blocks super 1.2 level 5, 512k chunk, algorithm 2 [3/3] [UUU]

unused devices: <none>
[root@centos6 ~]# cat /proc/mdstat
Personalities : [raid6] [raid5] [raid4]
md0 : active raid5 sdb3[4](F) sdb5[3] sdb2[1] sdb1[0]
  222208 blocks super 1.2 level 5, 512k chunk, algorithm 2 [3/3] [UUU]

unused devices: <none>

6、移除故障磁盘

[root@centos6 ~]# mdadm /dev/md0 --remove /dev/sdb3
mdadm: only give one device per ARRAY line: /dev/md0 and UUID
mdadm: only give one device per ARRAY line: /dev/md0 and :
mdadm: only give one device per ARRAY line: /dev/md0 and ee8b3bf8:01aa6adb:fbfe5a75:559f98d7
mdadm: ARRAY line /dev/md0 has no identity information.
mdadm: hot removed /dev/sdb3 from /dev/md0

7、添加新磁盘

[root@centos6 ~]# mdadm /dev/md0 --add /dev/sdb3
mdadm: only give one device per ARRAY line: /dev/md0 and UUID
mdadm: only give one device per ARRAY line: /dev/md0 and :
mdadm: only give one device per ARRAY line: /dev/md0 and ee8b3bf8:01aa6adb:fbfe5a75:559f98d7
mdadm: ARRAY line /dev/md0 has no identity information.
mdadm: added /dev/sdb3
[root@centos6 ~]# mdadm --detail /dev/md0
mdadm: only give one device per ARRAY line: /dev/md0 and UUID
mdadm: only give one device per ARRAY line: /dev/md0 and :
mdadm: only give one device per ARRAY line: /dev/md0 and ee8b3bf8:01aa6adb:fbfe5a75:559f98d7
mdadm: ARRAY line /dev/md0 has no identity information.
/dev/md0:
    Version : 1.2
  Creation Time : Fri Apr  3 18:39:06 2020
 Raid Level : raid5
   Array Size : 222208 (217.00 MiB 227.54 MB)
 Used Dev Size : 111104 (108.50 MiB 113.77 MB)
 Raid Devices : 3
Total Devices : 4
Persistence : Superblock is persistent

Update Time : Fri Apr  3 19:20:27 2020
      State : clean
Active Devices : 3
Working Devices : 4
Failed Devices : 0
Spare Devices : 1

     Layout : left-symmetric
 Chunk Size : 512K

       Name : centos6.8:0  (local to host centos6.8)
       UUID : ee8b3bf8:01aa6adb:fbfe5a75:559f98d7
     Events : 39

Number   Major   Minor   RaidDevice State
   0       8       17        0      active sync   /dev/sdb1
   1       8       18        1      active sync   /dev/sdb2
   3       8       21        2      active sync   /dev/sdb5

   4       8       19        -      spare   /dev/sdb3
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值