软raid5创建及管理

linux mdadm raid5

使用软raid工具做raid5,要求三块磁盘(各2G分区)加一块备用磁盘(2G分区)

1、创建4个分区各2G大小(加上fd)
raid不要单独格式化,将来做raid建议使用干净的硬盘来做raid
[root@CentOS74 ~]#lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 100G 0 disk
├─sda1 8:1 0 1G 0 part /boot
├─sda2 8:2 0 30G 0 part /
├─sda3 8:3 0 3.9G 0 part [SWAP]
├─sda4 8:4 0 1K 0 part
├─sda5 8:5 0 20G 0 part /data
└─sda6 8:6 0 1G 0 part
sdb 8:16 0 100G 0 disk
└─sdb1 8:17 0 2G 0 part
sdc 8:32 0 200G 0 disk
└─sdc1 8:33 0 2G 0 part
sdd 8:48 0 60G 0 disk
└─sdd1 8:49 0 2G 0 part
sde 8:64 0 10G 0 disk
└─sde1 8:65 0 2G 0 part
sr0 11:0 1 5.8G 0 rom /run/media/root/CDROM
sr1 11:1 1 8.1G 0 rom /run/media/root/CentOS 7 x86_64
[root@CentOS74 ~]#

2、mdadm -C /dev/md0 -a yes -l5 -c 32 -n 3 -x1 /dev/sd{b,c,d,e}1
-C:指定raid设备名字 例如:/dev/md0
-a yes:自动回答yes
-c 32:指定chunk大小为32
-n 3:指定三个数据盘
-x 1:指定一个备份盘
sd{b,c,d,e}1:系统会默认sdb1,sdc1,sdd1作为数据磁盘,sde1做备份磁盘

[root@CentOS74 ~]#mdadm -C /dev/md0 -a yes -l5 -c 32 -n 3 -x1 /dev/sd{b,c,d,e}1
mdadm: /dev/sdb1 appears to contain an ext2fs file system
size=1048576K mtime=Thu Jan 1 08:00:00 1970
Continue creating array?
Continue creating array? (y/n) y
mdadm: Defaulting to version 1.2 metadata
mdadm: array /dev/md0 started.
[root@CentOS74 ~]#
[root@CentOS74 ~]#ll /dev/md0
brw-rw—- 1 root disk 9, 0 Apr 27 21:56 /dev/md0
[root@CentOS74 ~]#mdadm -D /dev/md0
/dev/md0:
Version : 1.2
Creation Time : Fri Apr 27 21:56:56 2018
Raid Level : raid5
Array Size : 4190208 (4.00 GiB 4.29 GB)
Used Dev Size : 2095104 (2046.00 MiB 2145.39 MB)
Raid Devices : 3
Total Devices : 4
Persistence : Superblock is persistent

Update Time : Fri Apr 27 21:57:07 2018
State : clean
Active Devices : 3
Working Devices : 4
Failed Devices : 0
Spare Devices : 1

Layout : left-symmetric (校验位的位置 左对齐/右对齐)
Chunk Size : 32K

Consistency Policy : resync

Name : CentOS74.magedu.com:0 (local to host CentOS74.magedu.com)
UUID : 14e29c45:499e2f43:d8fdb615:acad8c79
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
[root@CentOS74 ~]#

3、文件系统格式化磁盘
[root@CentOS74 ~]#blkid
/dev/sda2: UUID=”ca6c9524-a86e-405b-9d44-e2904b53ad66″ TYPE=”xfs”
/dev/sda1: UUID=”00a9ac3c-f07d-4199-ad38-a62a4e7369dd” TYPE=”xfs”
/dev/sda3: UUID=”2fad29e9-dedb-4b8b-bc44-b163034c9fa5″ TYPE=”swap”
/dev/sr0: UUID=”2017-06-17-02-34-50-00″ LABEL=”CDROM” TYPE=”iso9660″
/dev/sr1: UUID=”2017-09-06-10-53-42-00″ LABEL=”CentOS 7 x86_64″ TYPE=”iso9660″ PTTYPE=”dos”
/dev/sda5: UUID=”9166277f-3e31-43b9-b772-c15058e70859″ TYPE=”xfs”
/dev/sdb1: UUID=”14e29c45-499e-2f43-d8fd-b615acad8c79″ UUID_SUB=”86d25747-bb91-01d7-46e5-fee335621a79″ LABEL=”CentOS74.magedu.com:0″ TYPE=”linux_raid_member”
/dev/sdc1: UUID=”14e29c45-499e-2f43-d8fd-b615acad8c79″ UUID_SUB=”0edf6bc7-d409-e708-f638-d776a2539208″ LABEL=”CentOS74.magedu.com:0″ TYPE=”linux_raid_member”
/dev/sdd1: UUID=”14e29c45-499e-2f43-d8fd-b615acad8c79″ UUID_SUB=”2d7e893c-0487-ea7d-78cb-522f5f05bb68″ LABEL=”CentOS74.magedu.com:0″ TYPE=”linux_raid_member”
/dev/sde1: UUID=”14e29c45-499e-2f43-d8fd-b615acad8c79″ UUID_SUB=”6c220829-151e-bf6e-3011-81fc30eacdde” LABEL=”CentOS74.magedu.com:0″ TYPE=”linux_raid_member”
[root@CentOS74 ~]#blkid /dev/md0
[root@CentOS74 ~]#ll /dev/md0
brw-rw—- 1 root disk 9, 0 Apr 27 21:56 /dev/md0
[root@CentOS74 ~]#mkfs.ext4 /dev/md0 -L raid5
mke2fs 1.42.9 (28-Dec-2013)
Filesystem label=raid5
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=8 blocks, Stripe width=16 blocks
262144 inodes, 1047552 blocks
52377 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=1073741824
32 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736

Allocating group tables: done
Writing inode tables: done
Creating journal (16384 blocks): done
Writing superblocks and filesystem accounting information: done

[root@CentOS74 ~]#blkid
/dev/sda2: UUID=”ca6c9524-a86e-405b-9d44-e2904b53ad66″ TYPE=”xfs”
/dev/sda1: UUID=”00a9ac3c-f07d-4199-ad38-a62a4e7369dd” TYPE=”xfs”
/dev/sda3: UUID=”2fad29e9-dedb-4b8b-bc44-b163034c9fa5″ TYPE=”swap”
/dev/sr0: UUID=”2017-06-17-02-34-50-00″ LABEL=”CDROM” TYPE=”iso9660″
/dev/sr1: UUID=”2017-09-06-10-53-42-00″ LABEL=”CentOS 7 x86_64″ TYPE=”iso9660″ PTTYPE=”dos”
/dev/sda5: UUID=”9166277f-3e31-43b9-b772-c15058e70859″ TYPE=”xfs”
/dev/sdb1: UUID=”14e29c45-499e-2f43-d8fd-b615acad8c79″ UUID_SUB=”86d25747-bb91-01d7-46e5-fee335621a79″ LABEL=”CentOS74.magedu.com:0″ TYPE=”linux_raid_member”
/dev/sdc1: UUID=”14e29c45-499e-2f43-d8fd-b615acad8c79″ UUID_SUB=”0edf6bc7-d409-e708-f638-d776a2539208″ LABEL=”CentOS74.magedu.com:0″ TYPE=”linux_raid_member”
/dev/sdd1: UUID=”14e29c45-499e-2f43-d8fd-b615acad8c79″ UUID_SUB=”2d7e893c-0487-ea7d-78cb-522f5f05bb68″ LABEL=”CentOS74.magedu.com:0″ TYPE=”linux_raid_member”
/dev/sde1: UUID=”14e29c45-499e-2f43-d8fd-b615acad8c79″ UUID_SUB=”6c220829-151e-bf6e-3011-81fc30eacdde” LABEL=”CentOS74.magedu.com:0″ TYPE=”linux_raid_member”
/dev/md0: LABEL=”raid5″ UUID=”01091958-8ca7-4cf9-90f6-b7d13bdd9c9d” TYPE=”ext4″
[root@CentOS74 ~]#blkid /dev/md0
/dev/md0: LABEL=”raid5″ UUID=”01091958-8ca7-4cf9-90f6-b7d13bdd9c9d” TYPE=”ext4″
[root@CentOS74 ~]#

4、挂载

[root@CentOS74 ~]#cat /etc/fstab | grep /data/raid5
UUID=01091958-8ca7-4cf9-90f6-b7d13bdd9c9d /data/raid5 ext4 defaults 0 0
[root@CentOS74 ~]#
[root@CentOS74 ~]#ll /etc/mdadm.conf
ls: cannot access /etc/mdadm.conf: No such file or directory
[root@CentOS74 ~]#mdadm -Ds /dev/md0
ARRAY /dev/md0 metadata=1.2 spares=1 name=CentOS74.magedu.com:0 UUID=14e29c45:499e2f43:d8fdb615:acad8c79
[root@CentOS74 ~]#mdadm -Ds /dev/md0 > /etc/mdadm.conf
[root@CentOS74 ~]#mount -a
[root@CentOS74 ~]#cd /data/raid5/
[root@CentOS74 raid5]#ll
total 16
drwx—— 2 root root 16384 Apr 27 22:08 lost+found
[root@CentOS74 raid5]#touch f1
[root@CentOS74 raid5]#ll
total 16
-rw-r–r– 1 root root 0 Apr 27 22:15 f1
drwx—— 2 root root 16384 Apr 27 22:08 lost+found
[root@CentOS74 raid5]#

5、测试raid读写速度
测试写速度
[root@CentOS74 raid5]#dd if=/dev/zero of=f1 bs=1k count=1024000 conv=fdatasync
1024000+0 records in
1024000+0 records out
1048576000 bytes (1.0 GB) copied, 9.54323 s, 110 MB/s
[root@CentOS74 raid5]#

测试写速度
[root@CentOS74 raid5]#dd if=/data/raid5/f1 of=/dev/null
2048000+0 records in
2048000+0 records out
1048576000 bytes (1.0 GB) copied, 2.93293 s, 358 MB/s
[root@CentOS74 raid5]#

6、停用raid5设备
a、取消挂载
b、停止设备

备注:如果停用raid设备,/dev/md0设备号也会取消
[root@CentOS74 ~]#umount /data/raid5/
[root@CentOS74 ~]#mdadm -S /dev/md0
mdadm: stopped /dev/md0
[root@CentOS74 ~]#ll /dev/md0
ls: cannot access /dev/md0: No such file or directory
[root@CentOS74 ~]#
[root@CentOS74 ~]#mdadm -D /dev/md0
mdadm: cannot open /dev/md0: No such file or directory
[root@CentOS74 ~]#

7、激活raid5设备
[root@CentOS74 ~]#mdadm -A /dev/md0
mdadm: /dev/md0 has been started with 3 drives and 1 spare.
[root@CentOS74 ~]#ll /dev/md0
brw-rw—- 1 root disk 9, 0 Apr 28 19:39 /dev/md0
[root@CentOS74 ~]#mdadm -D /dev/md0
/dev/md0:
Version : 1.2
Creation Time : Fri Apr 27 21:56:56 2018
Raid Level : raid5
Array Size : 4190208 (4.00 GiB 4.29 GB)
Used Dev Size : 2095104 (2046.00 MiB 2145.39 MB)
Raid Devices : 3
Total Devices : 4
Persistence : Superblock is persistent

Update Time : Sat Apr 28 19:39:22 2018
State : clean
Active Devices : 3
Working Devices : 4
Failed Devices : 0
Spare Devices : 1

Layout : left-symmetric
Chunk Size : 32K

Consistency Policy : resync

Name : CentOS74.magedu.com:0 (local to host CentOS74.magedu.com)
UUID : 14e29c45:499e2f43:d8fdb615:acad8c79
Events : 21

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
[root@CentOS74 ~]#

8、测试备用硬盘的自动启用
如果存储数据的一块硬盘损坏,备用硬盘会不会自动启动(test)
使用mdadm /dev/md0 -f /dev/sdd1命令模拟/dev/sdd1硬盘损坏。
[root@CentOS74 ~]#df | grep /dev/md0
/dev/md0 4058816 1040384 2792540 28% /data/raid5
[root@CentOS74 ~]#mdadm -D /dev/md0
/dev/md0:
Version : 1.2
Creation Time : Fri Apr 27 21:56:56 2018
Raid Level : raid5
Array Size : 4190208 (4.00 GiB 4.29 GB)
Used Dev Size : 2095104 (2046.00 MiB 2145.39 MB)
Raid Devices : 3
Total Devices : 4
Persistence : Superblock is persistent

Update Time : Sat Apr 28 19:43:10 2018
State : clean
Active Devices : 3
Working Devices : 4
Failed Devices : 0
Spare Devices : 1

Layout : left-symmetric
Chunk Size : 32K

Consistency Policy : resync

Name : CentOS74.magedu.com:0 (local to host CentOS74.magedu.com)
UUID : 14e29c45:499e2f43:d8fdb615:acad8c79
Events : 21

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
[root@CentOS74 ~]#mdadm /dev/md0 -f /dev/sdd1
mdadm: set /dev/sdd1 faulty in /dev/md0
[root@CentOS74 ~]#mdadm -D /dev/md0
/dev/md0:
Version : 1.2
Creation Time : Fri Apr 27 21:56:56 2018
Raid Level : raid5
Array Size : 4190208 (4.00 GiB 4.29 GB)
Used Dev Size : 2095104 (2046.00 MiB 2145.39 MB)
Raid Devices : 3
Total Devices : 4
Persistence : Superblock is persistent

Update Time : Sat Apr 28 19:46:30 2018
State : clean, degraded, recovering
Active Devices : 2
Working Devices : 3
Failed Devices : 1
Spare Devices : 1

Layout : left-symmetric
Chunk Size : 32K

Consistency Policy : resync

Rebuild Status : 54% complete #备用硬盘启动,数据正在同步或者恢复

Name : CentOS74.magedu.com:0 (local to host CentOS74.magedu.com)
UUID : 14e29c45:499e2f43:d8fdb615:acad8c79
Events : 31

Number Major Minor RaidDevice State
0 8 17 0 active sync /dev/sdb1
1 8 33 1 active sync /dev/sdc1
3 8 65 2 spare rebuilding /dev/sde1

4 8 49 – faulty /dev/sdd1
[root@CentOS74 ~]#mdadm -D /dev/md0
/dev/md0:
Version : 1.2
Creation Time : Fri Apr 27 21:56:56 2018
Raid Level : raid5
Array Size : 4190208 (4.00 GiB 4.29 GB)
Used Dev Size : 2095104 (2046.00 MiB 2145.39 MB)
Raid Devices : 3
Total Devices : 4
Persistence : Superblock is persistent

Update Time : Sat Apr 28 19:46:35 2018
State : clean
Active Devices : 3
Working Devices : 3
Failed Devices : 1
Spare Devices : 0

Layout : left-symmetric
Chunk Size : 32K

Consistency Policy : resync

Name : CentOS74.magedu.com:0 (local to host CentOS74.magedu.com)
UUID : 14e29c45:499e2f43:d8fdb615:acad8c79
Events : 40

Number Major Minor RaidDevice State
0 8 17 0 active sync /dev/sdb1
1 8 33 1 active sync /dev/sdc1
3 8 65 2 active sync /dev/sde1 #数据同不完成

4 8 49 – faulty /dev/sdd1
[root@CentOS74 ~]#df | grep /dev/md0
/dev/md0 4058816 1040384 2792540 28% /data/raid5
[root@CentOS74 ~]#cat /data/raid5/f2 #raid下的数据访问OK
test
test1
[root@CentOS74 ~]#

9、将坏硬盘从raid设备中移除
[root@CentOS74 ~]#mdadm -D /dev/md0
/dev/md0:
Version : 1.2
Creation Time : Fri Apr 27 21:56:56 2018
Raid Level : raid5
Array Size : 4190208 (4.00 GiB 4.29 GB)
Used Dev Size : 2095104 (2046.00 MiB 2145.39 MB)
Raid Devices : 3
Total Devices : 4
Persistence : Superblock is persistent

Update Time : Sat Apr 28 19:46:35 2018
State : clean
Active Devices : 3
Working Devices : 3
Failed Devices : 1
Spare Devices : 0

Layout : left-symmetric
Chunk Size : 32K

Consistency Policy : resync

Name : CentOS74.magedu.com:0 (local to host CentOS74.magedu.com)
UUID : 14e29c45:499e2f43:d8fdb615:acad8c79
Events : 40

Number Major Minor RaidDevice State
0 8 17 0 active sync /dev/sdb1
1 8 33 1 active sync /dev/sdc1
3 8 65 2 active sync /dev/sde1

4 8 49 – faulty /dev/sdd1
[root@CentOS74 ~]#mdadm /dev/md0 -r /dev/sdd1 #坏设备被热移除,从raid设备中
mdadm: hot removed /dev/sdd1 from /dev/md0
[root@CentOS74 ~]#mdadm -D /dev/md0
/dev/md0:
Version : 1.2
Creation Time : Fri Apr 27 21:56:56 2018
Raid Level : raid5
Array Size : 4190208 (4.00 GiB 4.29 GB)
Used Dev Size : 2095104 (2046.00 MiB 2145.39 MB)
Raid Devices : 3
Total Devices : 3
Persistence : Superblock is persistent

Update Time : Sat Apr 28 19:52:12 2018
State : clean
Active Devices : 3
Working Devices : 3
Failed Devices : 0
Spare Devices : 0

Layout : left-symmetric
Chunk Size : 32K

Consistency Policy : resync

Name : CentOS74.magedu.com:0 (local to host CentOS74.magedu.com)
UUID : 14e29c45:499e2f43:d8fdb615:acad8c79
Events : 41

Number Major Minor RaidDevice State
0 8 17 0 active sync /dev/sdb1
1 8 33 1 active sync /dev/sdc1
3 8 65 2 active sync /dev/sde1
[root@CentOS74 ~]#

虽然/dev/sdd1被从raid设备中移除,但是/dev/sdd1中还是保存着raid信息
[root@CentOS74 ~]#blkid | grep /dev/sdd1
/dev/sdd1: UUID=”14e29c45-499e-2f43-d8fd-b615acad8c79″ UUID_SUB=”2d7e893c-0487-ea7d-78cb-522f5f05bb68″ LABEL=”CentOS74.magedu.com:0″ TYPE=”linux_raid_member”
[root@CentOS74 ~]#

10、再次将/dev/sdd1设备添加到raid设备中,但是/dev/sdd1将会成为raid设备的备用硬盘
[root@CentOS74 ~]#mdadm -D /dev/md0
/dev/md0:
Version : 1.2
Creation Time : Fri Apr 27 21:56:56 2018
Raid Level : raid5
Array Size : 4190208 (4.00 GiB 4.29 GB)
Used Dev Size : 2095104 (2046.00 MiB 2145.39 MB)
Raid Devices : 3
Total Devices : 3
Persistence : Superblock is persistent

Update Time : Sat Apr 28 19:52:12 2018
State : clean
Active Devices : 3
Working Devices : 3
Failed Devices : 0
Spare Devices : 0

Layout : left-symmetric
Chunk Size : 32K

Consistency Policy : resync

Name : CentOS74.magedu.com:0 (local to host CentOS74.magedu.com)
UUID : 14e29c45:499e2f43:d8fdb615:acad8c79
Events : 41

Number Major Minor RaidDevice State
0 8 17 0 active sync /dev/sdb1
1 8 33 1 active sync /dev/sdc1
3 8 65 2 active sync /dev/sde1
[root@CentOS74 ~]#mdadm /dev/md0 -a /dev/sdd1
mdadm: added /dev/sdd1
[root@CentOS74 ~]#mdadm -D /dev/md0
/dev/md0:
Version : 1.2
Creation Time : Fri Apr 27 21:56:56 2018
Raid Level : raid5
Array Size : 4190208 (4.00 GiB 4.29 GB)
Used Dev Size : 2095104 (2046.00 MiB 2145.39 MB)
Raid Devices : 3
Total Devices : 4
Persistence : Superblock is persistent

Update Time : Sat Apr 28 19:59:04 2018
State : clean
Active Devices : 3
Working Devices : 4
Failed Devices : 0
Spare Devices : 1

Layout : left-symmetric
Chunk Size : 32K

Consistency Policy : resync

Name : CentOS74.magedu.com:0 (local to host CentOS74.magedu.com)
UUID : 14e29c45:499e2f43:d8fdb615:acad8c79
Events : 42

Number Major Minor RaidDevice State
0 8 17 0 active sync /dev/sdb1
1 8 33 1 active sync /dev/sdc1
3 8 65 2 active sync /dev/sde1

4 8 49 – spare /dev/sdd1
[root@CentOS74 ~]#

11、测试raid5的容错性
创建测试条件,将备用硬盘和存储数据的一块硬盘模拟物理损坏,查看数据是否还可以访问
模拟物理硬盘损坏(/dev/sdd,/dev/sde物理移除)

raid5设备仍然可以使用,挂载数据,访问正常(数据是通过其他两块盘反算过来的),但是raid5(state)进行了降级使用

理论上raid5设备的读写速度会变差,测试读写速度可以使用dd命令

Linux运维心得:
如果raid5数据存储盘损坏,raid设备出现降级(degraded )使用,需要尽快更换硬盘修复,如果修复不及时,再次坏一块硬盘,raid5的数据将受到很大破坏。

[root@CentOS74 ~]#df | grep /dev/md0
/dev/md0 4058816 1040384 2792540 28% /data/raid5
[root@CentOS74 ~]#cat /data/raid5/f2
test
test1
[root@CentOS74 ~]#mdadm -D /dev/md0
/dev/md0:
Version : 1.2
Creation Time : Fri Apr 27 21:56:56 2018
Raid Level : raid5
Array Size : 4190208 (4.00 GiB 4.29 GB)
Used Dev Size : 2095104 (2046.00 MiB 2145.39 MB)
Raid Devices : 3
Total Devices : 2
Persistence : Superblock is persistent

Update Time : Sat Apr 28 20:12:48 2018
State : clean, degraded
Active Devices : 2
Working Devices : 2
Failed Devices : 0
Spare Devices : 0

Layout : left-symmetric
Chunk Size : 32K

Consistency Policy : resync

Name : CentOS74.magedu.com:0 (local to host CentOS74.magedu.com)
UUID : 14e29c45:499e2f43:d8fdb615:acad8c79
Events : 48

Number Major Minor RaidDevice State
0 8 17 0 active sync /dev/sdb1
1 8 33 1 active sync /dev/sdc1
– 0 0 2 removed
[root@CentOS74 ~]#

12、模拟更换硬盘
1、准备新的硬盘
2、使用mdadm /dev/md0 -a /dev/sda1命令加入/dev/sda1

[root@CentOS74 ~]#mdadm -D /dev/md0
/dev/md0:
Version : 1.2
Creation Time : Fri Apr 27 21:56:56 2018
Raid Level : raid5
Array Size : 4190208 (4.00 GiB 4.29 GB)
Used Dev Size : 2095104 (2046.00 MiB 2145.39 MB)
Raid Devices : 3
Total Devices : 2
Persistence : Superblock is persistent

Update Time : Sat Apr 28 20:13:18 2018
State : clean, degraded
Active Devices : 2
Working Devices : 2
Failed Devices : 0
Spare Devices : 0

Layout : left-symmetric
Chunk Size : 32K

Consistency Policy : resync

Name : CentOS74.magedu.com:0 (local to host CentOS74.magedu.com)
UUID : 14e29c45:499e2f43:d8fdb615:acad8c79
Events : 50

Number Major Minor RaidDevice State
0 8 17 0 active sync /dev/sdb1
1 8 33 1 active sync /dev/sdc1
– 0 0 2 removed
[root@CentOS74 ~]#

[root@CentOS74 ~]#fdisk /dev/sda
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
All primary partitions are in use
Adding logical partition 7
First sector (117252096-209715199, default 117252096):
Using default value 117252096
Last sector, +sectors or +size{K,M,G} (117252096-209715199, default 209715199): +2G
Partition 7 of type Linux and of size 2 GiB is set

Command (m for help): p

Disk /dev/sda: 107.4 GB, 107374182400 bytes, 209715200 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: 0x00019a2b

Device Boot Start End Blocks Id System
/dev/sda1 * 2048 2099199 1048576 83 Linux
/dev/sda2 2099200 65013759 31457280 83 Linux
/dev/sda3 65013760 73205759 4096000 82 Linux swap / Solaris
/dev/sda4 73205760 209715199 68254720 5 Extended
/dev/sda5 73207808 115150847 20971520 83 Linux
/dev/sda6 115152896 117250047 1048576 83 Linux
/dev/sda7 117252096 121446399 2097152 83 Linux

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.
[root@CentOS74 ~]#partprobe
Warning: Unable to open /dev/sr0 read-write (Read-only file system). /dev/sr0 has been opened read-only.
Warning: Unable to open /dev/sr1 read-write (Read-only file system). /dev/sr1 has been opened read-only.
[root@CentOS74 ~]#lsblk /dev/sda
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 100G 0 disk
├─sda1 8:1 0 1G 0 part /boot
├─sda2 8:2 0 30G 0 part /
├─sda3 8:3 0 3.9G 0 part [SWAP]
├─sda4 8:4 0 512B 0 part
├─sda5 8:5 0 20G 0 part /data
├─sda6 8:6 0 1G 0 part
└─sda7 8:7 0 2G 0 part
[root@CentOS74 ~]#

[root@CentOS74 ~]#mdadm /dev/md0 -a /dev/sda7 #添加设备
mdadm: added /dev/sda7
[root@CentOS74 ~]#mdadm -D /dev/md0
/dev/md0:
Version : 1.2
Creation Time : Fri Apr 27 21:56:56 2018
Raid Level : raid5
Array Size : 4190208 (4.00 GiB 4.29 GB)
Used Dev Size : 2095104 (2046.00 MiB 2145.39 MB)
Raid Devices : 3
Total Devices : 3
Persistence : Superblock is persistent

Update Time : Sat Apr 28 20:33:42 2018
State : clean, degraded, recovering
Active Devices : 2
Working Devices : 3
Failed Devices : 0
Spare Devices : 1

Layout : left-symmetric
Chunk Size : 32K

Consistency Policy : resync

Rebuild Status : 49% complete #数据同步

Name : CentOS74.magedu.com:0 (local to host CentOS74.magedu.com)
UUID : 14e29c45:499e2f43:d8fdb615:acad8c79
Events : 60

Number Major Minor RaidDevice State
0 8 17 0 active sync /dev/sdb1
1 8 33 1 active sync /dev/sdc1
3 8 7 2 spare rebuilding /dev/sda7
[root@CentOS74 ~]#
[root@CentOS74 ~]#mdadm -D /dev/md0
/dev/md0:
Version : 1.2
Creation Time : Fri Apr 27 21:56:56 2018
Raid Level : raid5
Array Size : 4190208 (4.00 GiB 4.29 GB)
Used Dev Size : 2095104 (2046.00 MiB 2145.39 MB)
Raid Devices : 3
Total Devices : 3
Persistence : Superblock is persistent

Update Time : Sat Apr 28 20:33:50 2018
State : clean #raid设备恢复正常
Active Devices : 3
Working Devices : 3
Failed Devices : 0
Spare Devices : 0

Layout : left-symmetric
Chunk Size : 32K

Consistency Policy : resync

Name : CentOS74.magedu.com:0 (local to host CentOS74.magedu.com)
UUID : 14e29c45:499e2f43:d8fdb615:acad8c79
Events : 69

Number Major Minor RaidDevice State
0 8 17 0 active sync /dev/sdb1
1 8 33 1 active sync /dev/sdc1
3 8 7 2 active sync /dev/sda7
[root@CentOS74 ~]#

13、扩展raid5,给raid5扩展容量,设备添加到raid5,需要对raid设备进行文件系统同步(ext#:resize2fs /dev/md0 (raid设备);xfs:xfs_growfs /data/raid5/ (raid挂载点) ),如果不进行文件系统
同步,新添加的空间系统不会使用
[root@CentOS74 ~]#lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 100G 0 disk
├─sda1 8:1 0 1G 0 part /boot
├─sda2 8:2 0 30G 0 part /
├─sda3 8:3 0 3.9G 0 part [SWAP]
├─sda4 8:4 0 512B 0 part
├─sda5 8:5 0 20G 0 part /data
├─sda6 8:6 0 1G 0 part
└─sda7 8:7 0 2G 0 part
└─md0 9:0 0 4G 0 raid5 /data/raid5
sdb 8:16 0 100G 0 disk
└─sdb1 8:17 0 2G 0 part
└─md0 9:0 0 4G 0 raid5 /data/raid5
sdc 8:32 0 200G 0 disk
└─sdc1 8:33 0 2G 0 part
└─md0 9:0 0 4G 0 raid5 /data/raid5
sr0 11:0 1 5.8G 0 rom /run/media/root/CDROM
sr1 11:1 1 8.1G 0 rom /run/media/root/CentOS 7 x86_64
[root@CentOS74 ~]#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 (4196352-209715199, default 4196352):
Using default value 4196352
Last sector, +sectors or +size{K,M,G} (4196352-209715199, default 209715199): +2G
Partition 2 of type Linux and of size 2 GiB is set

Command (m for help): p

Disk /dev/sdb: 107.4 GB, 107374182400 bytes, 209715200 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: 0x8b164cab

Device Boot Start End Blocks Id System
/dev/sdb1 2048 4196351 2097152 fd Linux raid autodetect
/dev/sdb2 4196352 8390655 2097152 83 Linux

Command (m for help): t
Partition number (1,2, default 2): 2
Hex code (type L to list all codes): L

0 Empty 24 NEC DOS 81 Minix / old Lin bf Solaris
1 FAT12 27 Hidden NTFS Win 82 Linux swap / So c1 DRDOS/sec (FAT-
2 XENIX root 39 Plan 9 83 Linux c4 DRDOS/sec (FAT-
3 XENIX usr 3c PartitionMagic 84 OS/2 hidden C: c6 DRDOS/sec (FAT-
4 FAT16 <32M 40 Venix 80286 85 Linux extended c7 Syrinx
5 Extended 41 PPC PReP Boot 86 NTFS volume set da Non-FS data
6 FAT16 42 SFS 87 NTFS volume set db CP/M / CTOS / .
7 HPFS/NTFS/exFAT 4d QNX4.x 88 Linux plaintext de Dell Utility
8 AIX 4e QNX4.x 2nd part 8e Linux LVM df BootIt
9 AIX bootable 4f QNX4.x 3rd part 93 Amoeba e1 DOS access
a OS/2 Boot Manag 50 OnTrack DM 94 Amoeba BBT e3 DOS R/O
b W95 FAT32 51 OnTrack DM6 Aux 9f BSD/OS e4 SpeedStor
c W95 FAT32 (LBA) 52 CP/M a0 IBM Thinkpad hi eb BeOS fs
e W95 FAT16 (LBA) 53 OnTrack DM6 Aux a5 FreeBSD ee GPT
f W95 Ext’d (LBA) 54 OnTrackDM6 a6 OpenBSD ef EFI (FAT-12/16/
10 OPUS 55 EZ-Drive a7 NeXTSTEP f0 Linux/PA-RISC b
11 Hidden FAT12 56 Golden Bow a8 Darwin UFS f1 SpeedStor
12 Compaq diagnost 5c Priam Edisk a9 NetBSD f4 SpeedStor
14 Hidden FAT16 <3 61 SpeedStor ab Darwin boot f2 DOS secondary 16 Hidden FAT16 63 GNU HURD or Sys af HFS / HFS+ fb VMware VMFS 17 Hidden HPFS/NTF 64 Novell Netware b7 BSDI fs fc VMware VMKCORE 18 AST SmartSleep 65 Novell Netware b8 BSDI swap fd Linux raid auto 1b Hidden W95 FAT3 70 DiskSecure Mult bb Boot Wizard hid fe LANstep 1c Hidden W95 FAT3 75 PC/IX be Solaris boot ff BBT 1e Hidden W95 FAT1 80 Old Minix 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: 107.4 GB, 107374182400 bytes, 209715200 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: 0x8b164cab Device Boot Start End Blocks Id System /dev/sdb1 2048 4196351 2097152 fd Linux raid autodetect /dev/sdb2 4196352 8390655 2097152 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. [root@CentOS74 ~]#partprobe Warning: Unable to open /dev/sr0 read-write (Read-only file system). /dev/sr0 has been opened read-only. Warning: Unable to open /dev/sr1 read-write (Read-only file system). /dev/sr1 has been opened read-only. [root@CentOS74 ~]#mdadm -G /dev/md0 -n4 -a /dev/sdb2 mdadm: added /dev/sdb2 [root@CentOS74 ~]#mdadm -D /dev/md0 /dev/md0: Version : 1.2 Creation Time : Fri Apr 27 21:56:56 2018 Raid Level : raid5 Array Size : 4190208 (4.00 GiB 4.29 GB) Used Dev Size : 2095104 (2046.00 MiB 2145.39 MB) Raid Devices : 4 Total Devices : 4 Persistence : Superblock is persistent Update Time : Sat Apr 28 20:50:27 2018 State : clean, reshaping Active Devices : 4 Working Devices : 4 Failed Devices : 0 Spare Devices : 0 Layout : left-symmetric Chunk Size : 32K Consistency Policy : resync Reshape Status : 44% complete Delta Devices : 1, (3->4)

Name : CentOS74.magedu.com:0 (local to host CentOS74.magedu.com)
UUID : 14e29c45:499e2f43:d8fdb615:acad8c79
Events : 98

Number Major Minor RaidDevice State
0 8 17 0 active sync /dev/sdb1
1 8 33 1 active sync /dev/sdc1
3 8 7 2 active sync /dev/sda7
4 8 18 3 active sync /dev/sdb2
[root@CentOS74 ~]#
[root@CentOS74 ~]#df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda2 30G 5.2G 25G 18% /
devtmpfs 898M 0 898M 0% /dev
tmpfs 912M 0 912M 0% /dev/shm
tmpfs 912M 9.1M 903M 1% /run
tmpfs 912M 0 912M 0% /sys/fs/cgroup
/dev/sda5 20G 171M 20G 1% /data
/dev/sda1 1014M 175M 840M 18% /boot
/dev/md0 3.9G 1016M 2.7G 28% /data/raid5
tmpfs 183M 28K 183M 1% /run/user/0
/dev/sr1 8.1G 8.1G 0 100% /run/media/root/CentOS 7 x86_64
/dev/sr0 5.8G 5.8G 0 100% /run/media/root/CDROM
[root@CentOS74 ~]#
[root@CentOS74 ~]#resize2fs /dev/md0
resize2fs 1.42.9 (28-Dec-2013)
Filesystem at /dev/md0 is mounted on /data/raid5; on-line resizing required
old_desc_blocks = 1, new_desc_blocks = 1
The filesystem on /dev/md0 is now 1571328 blocks long.

[root@CentOS74 ~]#df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda2 30G 5.2G 25G 18% /
devtmpfs 898M 0 898M 0% /dev
tmpfs 912M 0 912M 0% /dev/shm
tmpfs 912M 9.1M 903M 1% /run
tmpfs 912M 0 912M 0% /sys/fs/cgroup
/dev/sda5 20G 171M 20G 1% /data
/dev/sda1 1014M 175M 840M 18% /boot
/dev/md0 5.9G 1016M 4.6G 18% /data/raid5
tmpfs 183M 28K 183M 1% /run/user/0
/dev/sr1 8.1G 8.1G 0 100% /run/media/root/CentOS 7 x86_64
/dev/sr0 5.8G 5.8G 0 100% /run/media/root/CDROM
[root@CentOS74 ~]#

14、删除raid5
1、取消挂载(如果有用户正在使用raid5,可以使用fuser -v /dev/md0查看设备,使用fuser -km /dev/md0强行踢出使用的用户)
2、删掉/etc/fstab配置文件中raid设备的配置信息和/etc/mdadm.conf配置文件
3、查看raid设备信息, 停止raid设备,
4、清除硬盘上的raid信息,删掉硬盘分区

[root@CentOS74 ~]#umount /dev/md0
[root@CentOS74 ~]#df | grep /dev/md0
[root@CentOS74 ~]#

[root@CentOS74 ~]#cat /etc/fstab | grep /data/raid5/
[root@CentOS74 ~]#
[root@CentOS74 ~]#rm -rf /etc/mdadm.conf
[root@CentOS74 ~]#

[root@CentOS74 ~]#mdadm -D /dev/md0
/dev/md0:
Version : 1.2
Creation Time : Fri Apr 27 21:56:56 2018
Raid Level : raid5
Array Size : 6285312 (5.99 GiB 6.44 GB)
Used Dev Size : 2095104 (2046.00 MiB 2145.39 MB)
Raid Devices : 4
Total Devices : 4
Persistence : Superblock is persistent

Update Time : Sat Apr 28 21:12:36 2018
State : clean
Active Devices : 4
Working Devices : 4
Failed Devices : 0
Spare Devices : 0

Layout : left-symmetric
Chunk Size : 32K

Consistency Policy : resync

Name : CentOS74.magedu.com:0 (local to host CentOS74.magedu.com)
UUID : 14e29c45:499e2f43:d8fdb615:acad8c79
Events : 102

Number Major Minor RaidDevice State
0 8 17 0 active sync /dev/sdb1
1 8 33 1 active sync /dev/sdc1
3 8 7 2 active sync /dev/sda7
4 8 18 3 active sync /dev/sdb2
[root@CentOS74 ~]#mdadm -S /dev/md0
mdadm: stopped /dev/md0
[root@CentOS74 ~]#ls /dev/md0
ls: cannot access /dev/md0: No such file or directory
[root@CentOS74 ~]#mdadm -D /dev/md0
mdadm: cannot open /dev/md0: No such file or directory
[root@CentOS74 ~]#mdadm –zero-superblock /dev/sdb1
[root@CentOS74 ~]#mdadm –zero-superblock /dev/sdb2
[root@CentOS74 ~]#mdadm –zero-superblock /dev/sdc1
[root@CentOS74 ~]#mdadm –zero-superblock /dev/sda7
[root@CentOS74 ~]#
[root@CentOS74 ~]#blkid
/dev/sr0: UUID=”2017-06-17-02-34-50-00″ LABEL=”CDROM” TYPE=”iso9660″
/dev/sda1: UUID=”00a9ac3c-f07d-4199-ad38-a62a4e7369dd” TYPE=”xfs”
/dev/sda2: UUID=”ca6c9524-a86e-405b-9d44-e2904b53ad66″ TYPE=”xfs”
/dev/sda3: UUID=”2fad29e9-dedb-4b8b-bc44-b163034c9fa5″ TYPE=”swap”
/dev/sda5: UUID=”9166277f-3e31-43b9-b772-c15058e70859″ TYPE=”xfs”
/dev/sdb1: UUID=”342acd5c-02e5-4f1f-8f70-2cb3838248ce” SEC_TYPE=”ext2″ TYPE=”ext3″
/dev/sdb2: LABEL=”/data/sdb2″ UUID=”a22a417d-600d-44b2-8d50-11f0a80ed8b0″ TYPE=”ext4″
/dev/sr1: UUID=”2017-09-06-10-53-42-00″ LABEL=”CentOS 7 x86_64″ TYPE=”iso9660″ PTTYPE=”dos”
[root@CentOS74 ~]#

删除设备

本文来自投稿,不代表Linux运维部落立场,如若转载,请注明出处:http://www.178linux.com/97189

发表评论

登录后才能评论

This site uses Akismet to reduce spam. Learn how your comment data is processed.

评论列表(1条)

  • linux_test
    linux_test 2018-04-28 21:29

    6666666666666666666666666666666666

联系我们

400-080-6560

在线咨询:点击这里给我发消息

邮件:1823388528@qq.com

工作时间:周一至周五,9:30-18:30,节假日同时也值班