軟raid5創建及管理

linux mdadm raid5

使用軟raid工具做raid5,要求三塊磁盤(各2G分區)加一塊備用磁盤(2G分區)

1、創建4個分區各2G大?。由蟜d)
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.www58058.com/97189

(0)
linux_testlinux_test
上一篇 2018-04-28
下一篇 2018-04-29

相關推薦

評論列表(1條)

  • linux_test
    linux_test 2018-04-28 21:29

    6666666666666666666666666666666666

欧美性久久久久