1.在虚拟机上添加4个磁盘,其中主用盘3个,热备盘1个
[root@centos7 ~]# fdisk -l
Disk /dev/sda: 21.5 GB, 21474836480 bytes, 41943040 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: 0x000b4721
Device Boot Start End Blocks Id System
/dev/sda1 * 2048 2099199 1048576 83 Linux
/dev/sda2 2099200 41943039 19921920 8e Linux LVM
Disk /dev/sdb: 21.5 GB, 21474836480 bytes, 41943040 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: 21.5 GB, 21474836480 bytes, 41943040 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/sdd: 21.5 GB, 21474836480 bytes, 41943040 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/sde: 21.5 GB, 21474836480 bytes, 41943040 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/centos-root: 18.2 GB, 18249416704 bytes, 35643392 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/centos-swap: 2147 MB, 2147483648 bytes, 4194304 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
2.构建磁盘阵列raid5
step1:将添加的/dev/sdb磁盘分出一个大小为5G的分区并格式化为Linux raid autodetect类型用来构建磁盘阵列;磁盘/dev/sdc,/dev/sdd/,/dev/sde也需要进行同样的操作
[root@centos7 ~]# fdisk /dev/sdb
Welcome to fdisk (util-linux 2.23.2).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Device does not contain a recognized partition table
Building a new DOS disklabel with disk identifier 0x876f58d9.
Command (m for help): n
Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended
Select (default p):
Using default response p
Partition number (1-4, default 1):
First sector (2048-41943039, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-41943039, default 41943039): +5G
Partition 1 of type Linux and of size 5 GiB is set
Command (m for help): p
Disk /dev/sdb: 21.5 GB, 21474836480 bytes, 41943040 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: 0x876f58d9
Device Boot Start End Blocks Id System
/dev/sdb1 2048 10487807 5242880 83 Linux
Command (m for help): t
Selected partition 1
Hex code (type L to list all codes): fd
Changed type of partition 'Linux' to 'Linux raid autodetect'
Command (m for help): p
Disk /dev/sdb: 21.5 GB, 21474836480 bytes, 41943040 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: 0x876f58d9
Device Boot Start End Blocks Id System
/dev/sdb1 2048 10487807 5242880 fd Linux raid autodetect
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
step2:创建级别为5的raid设备/dev/md0并查看
[root@centos7 ~]# mdadm -C /dev/md0 -a yes -l 5 -n 3 -x 1 /dev/sdb1 /dev/sdc1 /dev/sdd1 /dev/sde1
mdadm: Defaulting to version 1.2 metadata
mdadm: array /dev/md0 started.
[root@centos7 ~]# mdadm -D /dev/md0
/dev/md0:
Version : 1.2
Creation Time : Fri Aug 16 00:02:55 2019
Raid Level : raid5
Array Size : 10475520 (9.99 GiB 10.73 GB)
Used Dev Size : 5237760 (5.00 GiB 5.36 GB)
Raid Devices : 3
Total Devices : 4
Persistence : Superblock is persistent
Update Time : Fri Aug 16 00:03:10 2019
State : clean
Active Devices : 3
Working Devices : 4
Failed Devices : 0
Spare Devices : 1
Layout : left-symmetric
Chunk Size : 512K
Consistency Policy : resync
Name : centos7:0 (local to host centos7)
UUID : f44c0263:82b6aa04:691d44bd:d8357af3
Events : 18
Number Major Minor RaidDevice State
0 8 17 0 active sync /dev/sdb1
1 8 33 1 active sync /dev/sdc1
4 8 49 2 active sync /dev/sdd1
3 8 65 - spare /dev/sde1
step3:使raid设备每次重启都生效
[root@centos7 ~]# mdadm -D -s > /etc/mdadm.conf
step4:格式化raid设备并挂载使用
[root@centos7 ~]# mkfs -t xfs /dev/md0
meta-data=/dev/md0 isize=512 agcount=16, agsize=163712 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0, sparse=0
data = bsize=4096 blocks=2618880, 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=8 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
[root@centos7 ~]# mount -t xfs /dev/md0 /mnt/
[root@centos7 ~]# df -Th
Filesystem Type Size Used Avail Use% Mounted on
/dev/mapper/centos-root xfs 17G 4.0G 14G 24% /
devtmpfs devtmpfs 974M 0 974M 0% /dev
tmpfs tmpfs 991M 0 991M 0% /dev/shm
tmpfs tmpfs 991M 11M 981M 2% /run
tmpfs tmpfs 991M 0 991M 0% /sys/fs/cgroup
/dev/sda1 xfs 1014M 166M 849M 17% /boot
tmpfs tmpfs 199M 12K 199M 1% /run/user/42
tmpfs tmpfs 199M 0 199M 0% /run/user/0
/dev/md0 xfs 10G 33M 10G 1% /mnt
到这里raid5设备已创建完成
3.测试冗错
step1:首先把/dev/sdc1置为无效状态,查看热备分区/dev/sde1是否自动替换上来
[root@centos7 ~]# mdadm /dev/md0 -f /dev/sdc1
mdadm: set /dev/sdc1 faulty in /dev/md0
[root@centos7 ~]# mdadm -D /dev/md0
/dev/md0:
Version : 1.2
Creation Time : Fri Aug 16 00:02:55 2019
Raid Level : raid5
Array Size : 10475520 (9.99 GiB 10.73 GB)
Used Dev Size : 5237760 (5.00 GiB 5.36 GB)
Raid Devices : 3
Total Devices : 4
Persistence : Superblock is persistent
Update Time : Fri Aug 16 00:12:25 2019
State : clean
Active Devices : 3
Working Devices : 3
Failed Devices : 1
Spare Devices : 0
Layout : left-symmetric
Chunk Size : 512K
Consistency Policy : resync
Name : centos7:0 (local to host centos7)
UUID : f44c0263:82b6aa04:691d44bd:d8357af3
Events : 37
Number Major Minor RaidDevice State
0 8 17 0 active sync /dev/sdb1
3 8 65 1 active sync /dev/sde1
4 8 49 2 active sync /dev/sdd1
1 8 33 - faulty /dev/sdc1
step2:将faulty的分区从raid设备中移除
[root@centos7 ~]# mdadm /dev/md0 -r /dev/sdc1
mdadm: hot removed /dev/sdc1 from /dev/md0
[root@centos7 ~]# mdadm -D /dev/md0
/dev/md0:
Version : 1.2
Creation Time : Fri Aug 16 00:02:55 2019
Raid Level : raid5
Array Size : 10475520 (9.99 GiB 10.73 GB)
Used Dev Size : 5237760 (5.00 GiB 5.36 GB)
Raid Devices : 3
Total Devices : 3
Persistence : Superblock is persistent
Update Time : Fri Aug 16 00:58:35 2019
State : clean
Active Devices : 3
Working Devices : 3
Failed Devices : 0
Spare Devices : 0
Layout : left-symmetric
Chunk Size : 512K
Consistency Policy : resync
Name : centos7:0 (local to host centos7)
UUID : f44c0263:82b6aa04:691d44bd:d8357af3
Events : 38
Number Major Minor RaidDevice State
0 8 17 0 active sync /dev/sdb1
3 8 65 1 active sync /dev/sde1
4 8 49 2 active sync /dev/sdd1
4.添加新的热备分区
step1:在raid设备上新添加一个热备分区,这里我们可以从/dev/sdb上面再划分一个5G大小的分区
[root@centos7 ~]# fdisk /dev/sdb
Welcome to fdisk (util-linux 2.23.2).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Command (m for help): n
Partition type:
p primary (1 primary, 0 extended, 3 free)
e extended
Select (default p):
Using default response p
Partition number (2-4, default 2):
First sector (10487808-41943039, default 10487808):
Using default value 10487808
Last sector, +sectors or +size{K,M,G} (10487808-41943039, default 41943039): +5G
Partition 2 of type Linux and of size 5 GiB is set
Command (m for help): t
Partition number (1,2, default 2):
Hex code (type L to list all codes): fd
Changed type of partition 'Linux' to 'Linux raid autodetect'
Command (m for help): p
Disk /dev/sdb: 21.5 GB, 21474836480 bytes, 41943040 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: 0x876f58d9
Device Boot Start End Blocks Id System
/dev/sdb1 2048 10487807 5242880 fd Linux raid autodetect
/dev/sdb2 10487808 20973567 5242880 fd Linux raid autodetect
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.
step2:将/dev/sdb2加到磁盘设备md0上作为新的热备分区并查看,这里需要先重启一下,识别新的分区
[root@centos7 ~]# reboot
[root@centos7 ~]# mdadm /dev/md0 -a /dev/sdb2
mdadm: added /dev/sdb2
[root@centos7 ~]# mdadm -D /dev/md0
/dev/md0:
Version : 1.2
Creation Time : Fri Aug 16 00:02:55 2019
Raid Level : raid5
Array Size : 10475520 (9.99 GiB 10.73 GB)
Used Dev Size : 5237760 (5.00 GiB 5.36 GB)
Raid Devices : 3
Total Devices : 4
Persistence : Superblock is persistent
Update Time : Fri Aug 16 01:32:38 2019
State : clean
Active Devices : 3
Working Devices : 4
Failed Devices : 0
Spare Devices : 1
Layout : left-symmetric
Chunk Size : 512K
Consistency Policy : resync
Name : centos7:0 (local to host centos7)
UUID : f44c0263:82b6aa04:691d44bd:d8357af3
Events : 41
Number Major Minor RaidDevice State
0 8 17 0 active sync /dev/sdb1
3 8 65 1 active sync /dev/sde1
4 8 49 2 active sync /dev/sdd1
5 8 18 - spare /dev/sdb2
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)