linux RAID10测试
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=256 agcount=16, agsize=163712 blks = sectsz=512 attr=2, projid32bit=1 = crc=0 finobt=0 data = bsize=4096 blocks=2619392, imaxpct=25 = sunit=128 swidth=256 blks naming =version 2 bsize=4096 ascii-ci=0 ftype=0 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 [root@victory dev]# fdisk -l Disk /dev/sdd: 5368 MB, 5368709120 bytes, 10485760 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk /dev/sdb: 5368 MB, 5368709120 bytes, 10485760 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk /dev/sdc: 5368 MB, 5368709120 bytes, 10485760 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk /dev/sda: 5368 MB, 5368709120 bytes, 10485760 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk label type: dos Disk identifier: 0x0006ae1e Device Boot Start End Blocks Id System /dev/sda1 * 2048 616447 307200 83 Linux /dev/sda2 616448 10485759 4934656 8e Linux LVM Disk /dev/sde: 5368 MB, 5368709120 bytes, 10485760 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk /dev/mapper/rhel-root: 3976 MB, 3976200192 bytes, 7766016 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk /dev/mapper/rhel-swap: 1073 MB, 1073741824 bytes, 2097152 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk /dev/md0: 10.7 GB, 10729029632 bytes, 20955136 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 524288 bytes / 1048576 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 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 114M 184M 39% /boot tmpfs 184M 0 184M 0% /run/user/0 /dev/md0 10G 33M 10G 1% /fuckRAID
第4步:查看/dev/md0磁盘阵列设备组详细信息,并把挂载信息写入到配置文件中永久生效:
[root@victory dev]# 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:07:00 2017 State : clean Active Devices : 4 Working Devices : 4 Failed Devices : 0 Spare Devices : 0 Layout : near=2 Chunk Size : 512K Name : victory.rusky.com:0 (local to host victory.rusky.com) UUID : 6829f476:39a119d4:93da652e:83e096e3 Events : 17 Number Major Minor RaidDevice State 0 8 16 0 active sync set-A /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 dev]# vi /etc/fstab # # /etc/fstab # Created by anaconda on Tue Aug 1 04:28:47 2017 # # Accessible filesystems, by reference, are maintained under '/dev/disk' # See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info # /dev/mapper/rhel-root / xfs defaults 0 0 UUID=e7987771-c54c-4b36-8a5c-8e71f129c3fe /boot xfs defaults 0 0 /dev/mapper/rhel-swap swap swap defaults 0 0 /dev/md0 /fuckRAID xfs defaults 0 0
二、模拟损坏磁盘阵列及修复
[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 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:26:04 2017 State : clean, degraded Active Devices : 3 Working Devices : 3 Failed Devices : 1 Spare Devices : 0 Layout : near=2 Chunk Size : 512K Name : victory.rusky.com:0 (local to host victory.rusky.com) UUID : 6829f476:39a119d4:93da652e:83e096e3 Events : 19 Number Major Minor RaidDevice State 0 0 0 0 removed 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 0 8 16 - 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
*******VICTORY LOVES PREPARATION*******