歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> Linux教程 >> Red Hat Linux 7 下軟件仿真 磁盤陣列(RAID)

Red Hat Linux 7 下軟件仿真 磁盤陣列(RAID)

日期:2017/2/28 13:53:57   编辑:Linux教程

一:磁盤陣列的簡介

磁盤陣列(Redundant Arrays of Independent Disks,RAID),有“獨立磁盤構成的具有冗余能力的陣列”之意。

磁盤陣列是由很多價格較便宜的磁盤,組合成一個容量巨大的磁盤組,利用個別磁盤提供數據所產生加成效果提升整個磁盤系統效能。利用這項技術,將數據切割成許多區段,分別存放在各個硬盤上。
磁盤陣列還能利用同位檢查(Parity Check)的觀念,在數組中任意一個硬盤故障時,仍可讀出數據,在數據重構時,將數據經計算後重新置入新硬盤中。

二:磁盤陣列的模式

磁盤陣列其樣式有三種,一是外接式磁盤陣列櫃、二是內接式磁盤陣列卡,三是利用軟件來仿真。

三:磁盤陣列仿真的具體操作步驟
1:實驗環境 RedHat7.0
首先 用 cat /proc/partitions 查看系統中可用磁盤情況

[root@localhost ~]# cat /proc/partitions
major minor #blocks name

253 0 10485760 vda
253 1 10484142 vda1
253 16 10485760 vdb
7 0 3655680 loop0

其中的 vdb 磁盤為沒有被使用的,那麼我們接下來就裡用它來實現我們的目的
接下來劃分我們需要的分區:

使用命令 fdisk dev/vdb

然後輸入 m 獲得幫助
從中選擇 n 代表需要劃分一個分區

接下來的分區模式選擇主分區 p 也就是默認分區

在選擇Partition number (1-4, default 1): 這個隨意

在接下來確定First sector (2048-20971519, default 2048): 這個最好選擇默認,這樣可以充分利用空間

接下來就是選擇分區的大小:

然後就可以利用 p 查看分區有沒有成功

在下面重要的地方都用藍色標示:

[root@localhost ~]# fdisk /dev/vdb
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 0xe42a4683.

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): 1
First sector (2048-20971519, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-20971519, default 20971519): +2G
Partition 1 of type Linux and of size 2 GiB is set

Command (m for help): p

Disk /dev/vdb: 10.7 GB, 10737418240 bytes, 20971520 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: dosDisk identifier: 0xe42a4683

Device Boot Start End Blocks Id System
/dev/vdb1 2048 4196351 2097152 83 Linux

Command (m for help):


依次類推我們先劃分出3個新的分區

Device Boot Start End Blocks Id System
/dev/vdb1 2048 4196351 2097152 83 Linux
/dev/vdb2 4196352 8390655 2097152 83 Linux
/dev/vdb3 8390656 12584959 2097152 83 Linux


接下來我們需要將新建立的分區功能標簽修改為 raid
先在 Command (m for help): l 輸入 i

發現倒數第三行 有 fd Linux raid auto
那麼我們就找到了改為 raid 格式 所對應的命令

接下來輸入 m
Command (m for help): m

Command (m for help): m
Command action
a toggle a bootable flag
b edit bsd disklabel
c toggle the dos compatibility flag
d delete a partition
g create a new empty GPT partition table
G create an IRIX (SGI) partition table
l list known partition types
m print this menu
n add a new partition
o create a new empty DOS partition table
p print the partition table
q quit without saving changes
s create a new empty Sun disklabel
t change a partition's system id
u change display/entry units
v verify the partition table
w write table to disk and exit
x extra functionality (experts only)
然後發現 t 是我們需要的
以此類推將三個分區格式都修改成 Linux raid autodetect

點擊(此處)折疊或打開

Command (m for help): t
Partition number (1-3, default 3): 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/vdb: 10.7 GB, 10737418240 bytes, 20971520 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: 0xe42a4683

Device Boot Start End Blocks Id System
/dev/vdb1 2048 4196351 2097152 fd Linux raid autodetect
/dev/vdb2 4196352 8390655 2097152 83 Linux
/dev/vdb3 8390656 12584959 2097152 83 Linux

Command (m for help):
然後出來 時用 wq退出保存
在用 命令 cat /proc/partitions 產看分區成功沒

[root@localhost ~]# cat /proc/partitions
major minor #blocks name

253 0 10485760 vda
253 1 10484142 vda1
253 16 10485760 vdb
253 17 2097152 vdb1
253 18 2097152 vdb2
253 19 2097152 vdb3
7 0 3655680 loop0
那麼就該進入主題了
使用命令:
mdadm -C /dev/md0 -a yes -l 1 -n 2 -x 1 /dev/vdb{1..3}
-C 建立
-a 文件不存在建立文件
-l raid級別
-n 設備個數
-x 閒置設備個數
這條命令就將/dev/md0設備做成相當於raid那個內接卡的功能 將vdb1 vdb2 設備關聯 閒置設備 vdb3 以被後患

用 cat/proc/mdstat 查看設備信息

[root@localhost ~]# cat /proc/mdstat

Personalities : [raid1]
md0 : active raid1 vdb3[2](S) vdb2[1] vdb1[0]
2096064 blocks super 1.2 [2/2] [UU]
[===========>.........] resync = 56.3% (1181056/2096064) finish=0.2min speed=56240K/sec

unused devices: <none>
因為你要用它所以需要將其格式化一種文件系統

點擊(此處)折疊或打開

[root@localhost ~]# mkfs.xfs /dev/md0
meta-data=/dev/md0 isize=256 agcount=4, agsize=131004 blks
= sectsz=512 attr=2, projid32bit=1
= crc=0
data = bsize=4096 blocks=524016, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=0
log =internal log bsize=4096 blocks=2560, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
然後將其掛載到/mnt mount /dev/md0 /mnt(臨時掛載)
如需永久掛載 vim /etc/fstab
/dev/md0 /mnt xfs defaults 0 0

[root@localhost ~]# mount /dev/md0 /mnt
[root@localhost ~]# df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/vda1 10473900 7009908 3463992 67% /
devtmpfs 927072 0 927072 0% /dev
tmpfs 942660 92 942568 1% /dev/shm
tmpfs 942660 17064 925596 2% /run
tmpfs 942660 0 942660 0% /sys/fs/cgroup
/dev/loop0 3654720 3654720 0 100% /var/www/html/pub
/dev/md0 2085824 32928 2052896 2% /mnt
這就完成了,但是很多人覺得不看到現象就不覺得成功,那我們接下來 刪除它正在使用的一個分區 比如 vdb1
使用命令 mdadm /dev/mad0 -f /dev/vdb1
接下來查看設備狀況 用命令 cat /proc/mdstat
就會將損壞的那個分區的數據放到剛剛閒置的 vdb3
而我們如果不是查看設備信息是根本不知道它那樣操作,因為是後台悄悄執行,所以並不影響我們手中的工作,我們只需定期檢查,更換壞的就好
我們也可以恢復損壞的分區
mdadm /dev/md0 -a /dev/vdb1 恢復設備

[root@localhost dev]# cat /proc/mdstat
Personalities : [raid1]
md0 : active raid1 vdb3[2] vdb2[1] vdb1[0](F)
2096064 blocks super 1.2 [2/1] [_U]
[==========>..........] recovery = 52.6% (1104448/2096064) finish=0.6min speed=25945K/sec

unused devices:
還可以執行如下命令
mdadm /dev/md0 -r /dev/vdb1 移除設備
mdadm -S /dev/md0 停止設備

更多RedHat相關信息見RedHat 專題頁面 http://www.linuxidc.com/topicnews.aspx?tid=10

Copyright © Linux教程網 All Rights Reserved