2021-05-12 14:32:11
磁碟管理之軟RAID
1、RAID概述
RAID,Redundant Arrays of Inexpensive(Independent)Disks的簡稱,獨立磁碟冗餘陣列,簡稱磁碟陣列。簡單來說,RAID是把多個硬碟組合成為一個邏輯磁區,因此,作業系統只會把它當作一個硬碟,經常被用在伺服器電腦上。不同的RAID實現的功能也是不盡相同的,或增強處理速度,或增強容錯能力,當然,更有甚者,是可以兼備這個特性的。
2、RAID分類
<1>RAID0
<2>RAID1
<3>RAID4
<4>RAID5
<5>RAID01
<6>RAID10
3、經典RAID5的實現
如果只是用作測試的話,軟RAID可以在一塊硬碟的不同分割區上實現,此處用不同的硬碟實現
<1>新增五塊硬碟,四塊做成RAID陣列,一塊做spare硬碟
<2>建立檔案系統,並調整分割區型別為fd
[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): t # 調整分割區型別
Selected partition 1
Hex code (type L to list all codes): fd # 選擇fd
Changed type of partition 'Linux' to 'Linux raid autodetect'
Command (m for help): w # 存檔退出
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
<3>建立RAID裝置
[root@centos7~]#mdadm -C /dev/md0 -a yes -l 5 -n 4 -x 1 /dev/sd{b,c,d,e,f}1
mdadm: /dev/sdb1 appears to contain an ext2fs file system
size=2097152K mtime=Thu Jan 1 08:00:00 1970
mdadm: /dev/sde1 appears to contain an ext2fs file system
size=2097152K mtime=Mon Aug 29 21:32:01 2016
Continue creating array? y # 確定建立
mdadm: Defaulting to version 1.2 metadata
mdadm: array /dev/md0 started. # 建立完成並啟動
<4>檢視建立進度
[root@centos7/mnt]#cat /proc/mdstat
Personalities : [raid6] [raid5] [raid4]
md0 : active raid5 sde1[5] sdf1[4](S) sdd1[2] sdc1[1] sdb1[0]
6285312 blocks super 1.2 level 5, 512k chunk, algorithm 2 [4/4] [UUUU]
# RAID5建立完成,正式啟動
unused devices: <none>
<5>檢視RAID設定
[root@centos7~]#mdadm -D /dev/md0
/dev/md0:
Version : 1.2
Creation Time : Tue Aug 30 15:38:04 2016
Raid Level : raid5 # RAID級別
Array Size : 6285312 (5.99 GiB 6.44 GB) # 陣列大小,使用率為n-1/n
Used Dev Size : 2095104 (2046.34 MiB 2145.39 MB) # 備用的磁碟空間大小
Raid Devices : 4
Total Devices : 5
Persistence : Superblock is persistent
Update Time : Tue Aug 30 15:38:14 2016
State : clean
Active Devices : 4 # RAID工作狀況
Working Devices : 5
Failed Devices : 0
Spare Devices : 1
Layout : left-symmetric
Chunk Size : 512K # Chunk預設大小
Name : localhost.localdomain:0 (local to host localhost.localdomain)
UUID : fe6313e4:bc14f451:01602e5e:13820d53
Events : 18
Number Major Minor RaidDevice State
0 8 17 0 active sync /dev/sdb1
1 8 33 1 active sync /dev/sdc1
2 8 49 2 active sync /dev/sdd1
5 8 65 3 active sync /dev/sde1
4 8 81 - spare /dev/sdf1 # 備用盤
<6>為RAID5建立檔案系統
[root@centos7/mnt]#mkfs.ext4 /dev/md0
mke2fs 1.42.9 (28-Dec-2013)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=128 blocks, Stripe width=384 blocks
393216 inodes, 1571328 blocks
... # 檔案系統建立成功
<7>掛載RAID
# 建立掛載點
[root@centos7~]#mkdir /mnt/raid
# 編輯/etc/fstab
[root@centos7~]#vim /etc/fstab
...
UUID="24adec89-2933-47e3-b824-11e25ef679cf" /mnt/raid ext4 defaults 0 0
...
# 掛載
[root@centos7~]#mount -a
# 檢視掛載
[root@centos7~]#mount
...
/dev/md0 on /mnt/raid type ext4 (rw,relatime,seclabel,stripe=384,data=ordered)
<8>建立RAID組態檔
[root@centos7~]#mdadm -Ds /dev/md0 > /etc/mdadm.conf
[root@centos7~]#cat /etc/mdadm.conf
ARRAY /dev/md0 metadata=1.2 spares=1 name=localhost.localdomain:0 UUID=fe6313e4:bc14f451:01602e5e:13820d53
<9>測試
[root@centos7~]#cp /etc/* /mnt/raid/ -r # 資料已通過掛載點儲存在RAID5上
[root@centos7~]#cat /mnt/raid/issue
S
Kernel r on an m
<9>模擬損壞一塊磁碟
# 模擬損壞
[root@centos7~]#mdadm /dev/md0 -f /dev/sdb1
mdadm: set /dev/sdb1 faulty in /dev/md0 # 已損壞
# 檢視RAID執行狀況
[root@centos7~]#mdadm -D /dev/md0
/dev/md0:
Version : 1.2
Creation Time : Tue Aug 30 15:38:04 2016
Raid Level : raid5
Array Size : 6285312 (5.99 GiB 6.44 GB)
Used Dev Size : 2095104 (2046.34 MiB 2145.39 MB)
Raid Devices : 4
Total Devices : 5
Persistence : Superblock is persistent
Update Time : Tue Aug 30 16:25:52 2016
State : clean, degraded, recovering
Active Devices : 3
Working Devices : 4
Failed Devices : 1
Spare Devices : 1
Layout : left-symmetric
Chunk Size : 512K
Rebuild Status : 57% complete # 進度
Name : localhost.localdomain:0 (local to host localhost.localdomain)
UUID : fe6313e4:bc14f451:01602e5e:13820d53
Events : 29
Number Major Minor RaidDevice State
4 8 81 0 spare rebuilding /dev/sdf1 # 正在修復中
1 8 33 1 active sync /dev/sdc1
2 8 49 2 active sync /dev/sdd1
5 8 65 3 active sync /dev/sde1
0 8 17 - faulty /dev/sdb1 # faulty狀態
# 檢視資料
[root@centos7~]#cat /etc/issue
S
Kernel r on an m
# 資料無失真壞
<10>不修復faulty硬碟,再次模擬損壞一塊硬碟
# 損壞硬碟
[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 : Tue Aug 30 15:38:04 2016
Raid Level : raid5
Array Size : 6285312 (5.99 GiB 6.44 GB)
Used Dev Size : 2095104 (2046.34 MiB 2145.39 MB)
Raid Devices : 4
Total Devices : 5
Persistence : Superblock is persistent
Update Time : Tue Aug 30 16:33:01 2016
State : clean, degraded
Active Devices : 3
Working Devices : 3
Failed Devices : 2
Spare Devices : 0
Layout : left-symmetric
Chunk Size : 512K
# 也沒有修復的進度
Name : localhost.localdomain:0 (local to host localhost.localdomain)
UUID : fe6313e4:bc14f451:01602e5e:13820d53
Events : 39
Number Major Minor RaidDevice State
4 8 81 0 active sync /dev/sdf1
2 0 0 2 removed # 沒有硬碟頂替,顯示remove狀態
2 8 49 2 active sync /dev/sdd1
5 8 65 3 active sync /dev/sde1
0 8 17 - faulty /dev/sdb1 # 已損壞
1 8 33 - faulty /dev/sdc1 # 已損壞
# 再次檢視資料
[root@centos7~]#cat /mnt/raid/issue
S
Kernel r on an m
# 資料無失真
<11>依然不修復,再次損壞
# 損壞硬碟
[root@centos7~]#mdadm /dev/md0 -f /dev/sdd1
mdadm: set /dev/sdd1 faulty in /dev/md0
[root@centos7~]#mdadm -D /dev/md0
/dev/md0:
Version : 1.2
Creation Time : Tue Aug 30 15:38:04 2016
Raid Level : raid5
Array Size : 6285312 (5.99 GiB 6.44 GB)
Used Dev Size : 2095104 (2046.34 MiB 2145.39 MB)
Raid Devices : 4
Total Devices : 5
Persistence : Superbloc
k is persistent
Update Time : Tue Aug 30 16:39:41 2016
State : clean, FAILED
Active Devices : 2
Working Devices : 2
Failed Devices : 3
Spare Devices : 0
Layout : left-symmetric
Chunk Size : 512K
Name : localhost.localdomain:0 (local to host localhost.localdomain)
UUID : fe6313e4:bc14f451:01602e5e:13820d53
Events : 41
Number Major Minor RaidDevice State
4 8 81 0 active sync /dev/sdf1
2 0 0 2 removed # 移除
4 0 0 4 removed # 移除
5 8 65 3 active sync /dev/sde1
0 8 17 - faulty /dev/sdb1 # 已損壞
1 8 33 - faulty /dev/sdc1 # 已損壞
2 8 49 - faulty /dev/sdd1 # 已損壞
# RAID5中,已損壞倆塊硬碟,校驗資料失效,資料全部損壞。
[root@centos7~]#cat /mnt/raid/fstab
cat: /mnt/raid/fstab: Input/output error
此時資料已經損壞,不可恢復
RAID支援熱插拔技術
<12>在RAID 不損壞之前也是可以增加RAID的磁碟的
[root@centos7~]#mdadm -G /dev/md0 -a -n 5 /dev/sdg1
RAID損壞後,移除RAID
[root@centos7~]#mdadm /dev/md0 -r /dev/sdb1
mdadm: hot removed /dev/sdb1 from /dev/md0
標準的解除安裝RAID的步驟
<13>取消掛載、停止RAID、刪除組態檔
[root@centos7~]#umount /mnt/raid/
[root@centos7~]#mdadm -S /dev/md0 備註----->啟用RAID:mdadm -A -s /dev/md5
mdadm: stopped /dev/md0
[root@centos7~]#rm -f /etc/mdadm.conf
<14>移除RAID中的磁碟
<15>刪除磁碟上的RAID資訊
[root@centos7~]#mdadm --zero-superblock /dev/sdf1 # 一定要先停止,否則報錯
本文永久更新連結地址:http://www.linuxidc.com/Linux/2016-09/135107.htm
相關文章