mdadm命令用于管理系统软件RAID硬盘阵列,格式为:"mdadm [模式] <RAID设备名称> [选项] [成员设备名称]"。

mdadm命令能够在Linux系统中创建和管理软件RAID磁盘阵列组,对于其中的理论知识和操作过程是与生产环境保持一致的~mdadm命令的常用参数包括有:

参数作用
-a检测设备名称
-n指定设备数量
-l指定raid级别
-C创建
-v显示过程
-f模拟设备损坏
-r移除设备
-Q查看摘要信息
-D查看详细信息
-S停止阵列

一、创建平盘阵列并挂载使用

第1步:使用mdadm命令创建RAID10,名称为"/dev/md0"。

[root@victory dev]# mdadm -Cv /dev/md0 -a yes -n 4 -l 10 /dev/sdb /dev/sdc /dev/sdd /dev/sde
mdadm: layout defaults to n2
mdadm: layout defaults to n2
mdadm: chunk size defaults to 512K
mdadm: size set to 5238784K
mdadm: Defaulting to version 1.2 metadata
mdadm: array /dev/md0 started.

第2步:把制作好的RAID磁盘阵列组格式化为xfs格式:

[root@victory dev]# mkfs.xfs /dev/md0
meta-data=/dev/md0 isize= agcount=, agsize= blks
= sectsz= attr=, projid32bit=
= crc= finobt=
data = bsize= blocks=, imaxpct=
= sunit= swidth= blks
naming =version bsize= ascii-ci= ftype=
log =internal log bsize= blocks=, version=
= sectsz= sunit= blks, lazy-count=
realtime =none extsz= blocks=, rtextents=
[root@victory dev]# fdisk -l Disk /dev/sdd: MB, bytes, sectors
Units = sectors of * = bytes
Sector size (logical/physical): bytes / bytes
I/O size (minimum/optimal): bytes / bytes Disk /dev/sdb: MB, bytes, sectors
Units = sectors of * = bytes
Sector size (logical/physical): bytes / bytes
I/O size (minimum/optimal): bytes / bytes Disk /dev/sdc: MB, bytes, sectors
Units = sectors of * = bytes
Sector size (logical/physical): bytes / bytes
I/O size (minimum/optimal): bytes / bytes Disk /dev/sda: MB, bytes, sectors
Units = sectors of * = bytes
Sector size (logical/physical): bytes / bytes
I/O size (minimum/optimal): bytes / bytes
Disk label type: dos
Disk identifier: 0x0006ae1e Device Boot Start End Blocks Id System
/dev/sda1 * Linux
/dev/sda2 8e Linux LVM Disk /dev/sde: MB, bytes, sectors
Units = sectors of * = bytes
Sector size (logical/physical): bytes / bytes
I/O size (minimum/optimal): bytes / bytes Disk /dev/mapper/rhel-root: MB, bytes, sectors
Units = sectors of * = bytes
Sector size (logical/physical): bytes / bytes
I/O size (minimum/optimal): bytes / bytes Disk /dev/mapper/rhel-swap: MB, bytes, sectors
Units = sectors of * = bytes
Sector size (logical/physical): bytes / bytes
I/O size (minimum/optimal): bytes / bytes Disk /dev/md0: 10.7 GB, bytes, sectors
Units = sectors of * = bytes
Sector size (logical/physical): bytes / bytes
I/O size (minimum/optimal): bytes / bytes

第3步:创建挂载点然后把存储设备进行挂载操作,挂载成功后可看到可用空间为10G:

[root@victory dev]# mkdir /fuckRAID
[root@victory dev]# mount /dev/md0 /fuckRAID/
[root@victory dev]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/rhel-root .7G 896M .9G % /
devtmpfs 910M 910M % /dev
tmpfs 920M 920M % /dev/shm
tmpfs 920M 8.4M 912M % /run
tmpfs 920M 920M % /sys/fs/cgroup
/dev/sda1 297M 114M 184M % /boot
tmpfs 184M 184M % /run/user/
/dev/md0 10G 33M 10G % /fuckRAID

第4步:查看/dev/md0磁盘阵列设备组详细信息,并把挂载信息写入到配置文件中永久生效:

[root@victory dev]# mdadm -D /dev/md0
/dev/md0:
Version : 1.2
Creation Time : Tue Aug ::
Raid Level : raid10
Array Size : (9.99 GiB 10.73 GB)
Used Dev Size : (5.00 GiB 5.36 GB)
Raid Devices :
Total Devices :
Persistence : Superblock is persistent Update Time : Tue Aug ::
State : clean
Active Devices :
Working Devices :
Failed Devices :
Spare Devices : Layout : near=
Chunk Size : 512K Name : victory.rusky.com: (local to host victory.rusky.com)
UUID : 6829f476:39a119d4:93da652e:83e096e3
Events : Number Major Minor RaidDevice State
active sync set-A /dev/sdb
active sync set-B /dev/sdc
active sync set-A /dev/sdd
active sync set-B /dev/sde
[root@victory dev]# vi /etc/fstab #
# /etc/fstab
# Created by anaconda on Tue Aug ::
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(), findfs(), mount() and/or blkid() for more info
#
/dev/mapper/rhel-root / xfs defaults
UUID=e7987771-c54c-4b36-8a5c-8e71f129c3fe /boot xfs defaults
/dev/mapper/rhel-swap swap swap defaults
/dev/md0 /fuckRAID xfs defaults

二、模拟损坏磁盘阵列及修复

[root@victory dev]# mdadm /dev/md0 -f /dev/sdb
mdadm: set /dev/sdb faulty in /dev/md0
[root@victory dev]# mdadm -D /dev/md0
/dev/md0:
Version : 1.2
Creation Time : Tue Aug ::
Raid Level : raid10
Array Size : (9.99 GiB 10.73 GB)
Used Dev Size : (5.00 GiB 5.36 GB)
Raid Devices :
Total Devices :
Persistence : Superblock is persistent Update Time : Tue Aug ::
State : clean, degraded
Active Devices :
Working Devices :
Failed Devices :
Spare Devices : Layout : near=
Chunk Size : 512K Name : victory.rusky.com: (local to host victory.rusky.com)
UUID : 6829f476:39a119d4:93da652e:83e096e3
Events : Number Major Minor RaidDevice State
removed
active sync set-B /dev/sdc
active sync set-A /dev/sdd
active sync set-B /dev/sde - faulty /dev/sdb
[root@victory dev]#
[root@victory ~]# umount /fuckRAID/
[root@victory ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/rhel-root 3.7G 896M 2.9G 24% /
devtmpfs 910M 0 910M 0% /dev
tmpfs 920M 0 920M 0% /dev/shm
tmpfs 920M 8.4M 912M 1% /run
tmpfs 920M 0 920M 0% /sys/fs/cgroup
/dev/sda1 297M 129M 168M 44% /boot
tmpfs 184M 0 184M 0% /run/user/0
[root@victory ~]# mdadm /dev/md0 -a /dev/sdb
mdadm: added /dev/sdb
[root@victory ~]# mdadm -D /dev/md0
/dev/md0:
Version : 1.2
Creation Time : Tue Aug 1 21:59:41 2017
Raid Level : raid10
Array Size : 10477568 (9.99 GiB 10.73 GB)
Used Dev Size : 5238784 (5.00 GiB 5.36 GB)
Raid Devices : 4
Total Devices : 4
Persistence : Superblock is persistent Update Time : Tue Aug 1 22:35:18 2017
State : clean, degraded, recovering
Active Devices : 3
Working Devices : 4
Failed Devices : 0
Spare Devices : 1 Layout : near=2
Chunk Size : 512K Rebuild Status : 80% complete Name : victory.rusky.com:0 (local to host victory.rusky.com)
UUID : 6829f476:39a119d4:93da652e:83e096e3
Events : 47 Number Major Minor RaidDevice State
4 8 16 0 spare rebuilding /dev/sdb
1 8 32 1 active sync set-B /dev/sdc
2 8 48 2 active sync set-A /dev/sdd
3 8 64 3 active sync set-B /dev/sde
[root@victory ~]# mount -a

  

05-20 10:02