1. RAID 簡介
RAID是英文Redundant Array of Inexpensive Disks的縮寫,中文名字爲磁盤冗餘陣列,顧名思義它是由磁盤組成陣列而成的。
簡 單地說,RAID就是一種把多塊獨立的硬盤(物理硬盤)按不同方式組合起來的一個硬盤組(邏輯硬盤),提供比單個硬盤更高的存儲性能和數據冗餘的技術,既 保證了存取數據的快捷方便和管理客戶端的簡捷,也解決了存儲海量數據的問題,同時提供了容錯性(Fault Tolerant)。它可以在不須停機的情況下自動檢測故障硬盤、進行硬盤替換,還可以擴充硬盤容量、重建故障硬盤上的數據。
目前最流行的是RAID 0,RAID 1,RAID 5。其中RAID1和RAID 5過多的用於保證數據的安全,最大程度的防止磁盤意外壞掉而丟失數據情況的發生。
RAID0 : 是最早的RAID。Level 0即RAID 0級,通常稱爲帶區,是利用帶區數據映射技巧的特定性能。也就是說,當數據寫入磁盤組的時候,被分成帶區,交錯寫入磁盤組的磁盤中。這帶來了高I/O性 能,低開銷,但不提供任何冗餘。磁盤組的存儲量等於總的各磁盤容量之和。
特徵:並行讀寫數據,性能高,但沒有數據冗餘,陣列中任何一個硬盤壞掉,意味着所有數據丟失
容量:所有硬盤容量之和
條件:至少兩塊硬盤,做爲RAID的分區大小必須是幾乎相同的.
RAID1: Level 1即RAID 1級,它就是常常提到的鏡像RAID,相比其它各級別RAID來說,這個級別使用的時間較長。RAID 1通過把同樣的數據寫到磁盤組的每一個磁盤上,將"鏡像"複製到每個磁盤上,來提供數據冗餘。鏡像由於它的簡單實現和數據的高可信度而一直很受歡迎。 1級在讀數據操作時,並行處理2個或更多的磁盤,因此數據傳輸速率高, 但是其它的操作時無法提供高速的I/O傳輸速率。1級提供了非常好的數據的高可信度,並且改善了讀數據操作的性能,但是耗費很大。要求組成磁盤組的各磁盤 規格相同,而組成後磁盤組的容量僅僅等於一塊磁盤的容量。
特徵:數據冗餘,可靠性強。任何一塊硬盤壞掉,不會丟失數據。寫入慢,讀取快。
容量:所有硬盤容量之和/2。(冗餘度 50%)
條件:至少兩塊硬盤,做爲RAID的分區大小必須是幾乎相同的.
RAID5: 服務器最常用的RAID級別,該級別的RAID是通過把奇偶校驗分佈到磁盤組中的一些或所有磁盤上,5級常使用緩衝技術來降低性能的不對稱性。如果組成磁盤組的各磁盤規格相同,磁盤組容量等於磁盤的總容量,減去一塊磁盤的容量。
如果出現兩個以上硬盤出現問題時,數據是不能得到有效的保護的。也就是說RAID 5只能在其中一塊硬盤出問題時保證數據完好。
特徵:採用奇偶效驗,可靠性強。只有當兩塊硬盤壞掉時纔會丟失數據。並行讀寫數據,性能也很高。
容量:所有硬盤容量-1個硬盤容量
條件:至少三塊硬盤,做爲RAID的分區大小必須是幾乎相同的。
RAID 0+1: RAID 0和RAID 1的組合
特徵:數據冗餘,可靠性強。任何一塊硬盤壞掉,不會丟失數據。寫入慢,讀取快。
容量:所有硬盤容量之和/2。(冗餘度 50%)
條件:至少四塊硬盤,做爲RAID的分區大小必須是幾乎相同的.
2. 準備RAID磁盤分區
① 在做RAID磁盤陣列時必須要有mdadm軟件的支持。Mdadm軟件一般是默認安裝的,如果沒有就在RHEL5光盤中找:
[root@server Server]# rpm -ivh mdadm-
warning: mdadm-
Preparing... ########################################### [100%]
② 爲Linux服務器添加4塊
[root@server Server]# fdisk /dev/sdb
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel. Changes will remain in memory only,
until you decide to write them. After that, of course, the previous
content won't be recoverable.
The number of cylinders for this disk is set to 2610.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other
(e.g., DOS FDISK, OS/2 FDISK)
Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-2610, default 1):
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-2610, default 2610): +
Command (m for help): t
Selected partition 1
Hex code (type L to list codes): fd
Changed system type of partition 1 to fd (Linux raid autodetect)
Command (m for help): p
Disk /dev/sdb: 21.4 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sdb1 1 318 2554303+ fd Linux raid autodetect
③ 創建好分區好之後執行“partprobe”重新檢測分區表,驗證分區類型和容量信息。
[root@server ~]# partprobe
[root@server ~]# fdisk -l /dev/sd[b-e] | grep "^/dev/sd"
/dev/sdb1 1 318 2554303+ fd Linux raid autodetect
/dev/sdc1 1 318 2554303+ fd Linux raid autodetect
/dev/sdd1 1 318 2554303+ fd Linux raid autodetect
/dev/sde1 1 318 2554303+ fd Linux raid autodetect
3. 創建RAID磁盤設備
①使用mdadm工具組合多個RAID分區成一個磁盤陣列
[root@server ~]# mdadm -Cv /dev/md0 -a yes -n4 -l5 /dev/sd[b-e]1
mdadm: layout defaults to left-symmetric
mdadm: chunk size defaults to 64K
mdadm: size set to 2554176K
mdadm: array /dev/md0 started.
②查看RAID磁盤陣列
[root@server ~]# ls -l /dev/md0
brw-r----- 1 root disk 9, 0 06-26 14:54 /dev/md0
[root@server ~]# cat /proc/mdstat
Personalities : [raid6] [raid5] [raid4]
md0 : active raid5 sde1[3] sdd1[2] sdc1[1] sdb1[0]
7662528 blocks level 5, 64k chunk, algorithm 2 [4/4] [UUUU]
unused devices: <none>
③在RAID設備上建立文件系統
[root@server ~]# mkfs -t ext3 /dev/md0
mke2fs 1.39 (29-May-2006)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
959104 inodes, 1915632 blocks
95781 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=1962934272
59 block groups
32768 blocks per group, 32768 fragments per group
16256 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
This filesystem will be automatically checked every 29 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
④掛載RAID設備文件系統
[root@server /]# mount /dev/md0 /liujian
[root@server /]# df -T | grep "md0"
/dev/md0 ext3 7542096 148044 7010928 3% /liujian
如果想重啓後還掛載
[root@server /]# vim /etc/fstab
/dev/md0 /liujian /ext3 defaults 1 1
4. RAID陣列的管理
①掃描RAID陣列的磁盤信息
[root@server /]# mdadm -vDs /dev/md0
/dev/md0:
Version : 0.90
Creation Time : Sat Jun 26 15:14:19 2010
Raid Level : raid5
Array Size : 7662528 (7.31 GiB 7.85 GB)
Used Dev Size : 2554176 (2.44 GiB 2.62 GB)
Raid Devices : 4
Total Devices : 4
Preferred Minor : 0
Persistence : Superblock is persistent
Update Time : Sat Jun 26 15:25:26 2010
State : clean
Active Devices : 4
Working Devices : 4
Failed Devices : 0
Spare Devices : 0
Layout : left-symmetric
Chunk Size : 64K
UUID : fdf
Events : 0.2
Number Major Minor
0 8 17 0 active sync /dev/sdb1
1 8 33 1 active sync /dev/sdc1
2 8 49 2 active sync /dev/sdd1
3 8 65 3 active sync /dev/sde1
②啓動/停止RAID陣列
停止
[root@server /]# mdadm -S /dev/md0
mdadm: fail to stop array /dev/md0: Device or resource busy
Perhaps a running process, mounted filesystem or active volume group?
啓動
[root@server /]# mdadm –A /dev/md0