RAID英文全稱redundant array of independent disks意思“獨立磁盤備援”,簡稱磁盤陣列。
是用來擴充磁盤,缺點如果一塊硬碟壞掉系統崩潰;
centos5.6
我們首先增加一個10G新磁盤:
我們fdisk -l,檢視磁盤狀态可以看到新磁盤目前不可用
<a target="_blank" href="http://blog.51cto.com/attachment/201210/154419985.png"></a>
制作Raid0磁盤陣列
Fdisk /dev/sdb //建立新分區
<a target="_blank" href="http://blog.51cto.com/attachment/201210/154559569.png"></a>
我們接下來鍵入n建立新分區,盡量建立擴充分區,按e建立擴充分區,輸入分區号,然後給分區配置設定大小,我們配置設定所有大小,于是從1開始按enter即可配置設定所有的大小。最後按p檢視。
<a target="_blank" href="http://blog.51cto.com/attachment/201210/154620786.png"></a>
擴充分區建立完畢,開始建立邏輯分區,按n開始建立新的分區。按“l”建立邏輯分區,使用“+100MB”配置設定一個大小為100MB的空間,按p檢視即可。邏輯分區是從5開始的。
<a target="_blank" href="http://blog.51cto.com/attachment/201210/155009497.png"></a>
我們建立了兩個100MB的邏輯分區來測試RID1.我們需要更改磁盤的系統id,我們按“t”修改,然後選擇“5”“代表第五塊磁盤,然後按"l"可以檢視支援的分區格式,我們選擇fd格式。最後按w儲存。
<a target="_blank" href="http://blog.51cto.com/attachment/201210/155138101.png"></a>
<a target="_blank" href="http://blog.51cto.com/attachment/201210/160146132.png"></a>
我們這時在fdisk -l檢視磁盤,會看到sdb已經有了新的内容。
<a target="_blank" href="http://blog.51cto.com/attachment/201210/160113473.png"></a>
然後通過mdadm 建立磁盤陣列,-C指md0陣列名,-ayes是激活為active狀态,-l後接0代表raid0磁盤陣列,-n後接2位2塊磁盤,最後接磁盤名,磁盤用{n1..n2}來簡寫。最後我們通過mdadm -D(detail)方式來檢視,會看到陣列為raid0,并且兩塊磁盤都是active狀态。Cat /proc/mdstat也可以檢視狀态。注:64Kchunks意思是磁盤是并行寫入資料的,第一塊磁盤寫了多少開始寫第二塊……。
<a target="_blank" href="http://blog.51cto.com/attachment/201210/160337902.png"></a>
<a target="_blank" href="http://blog.51cto.com/attachment/201210/160351785.png"></a>
Raid0做好了,我們建立3個檔案分别挂載用。
<a target="_blank" href="http://blog.51cto.com/attachment/201210/160404511.png"></a>
然後格式化磁盤mkfs.ext3 /dev/md0
<a target="_blank" href="http://blog.51cto.com/attachment/201210/160416748.png"></a>
接着mount 挂載磁盤。
<a target="_blank" href="http://blog.51cto.com/attachment/201210/160435360.png"></a>
這時我們重新開機電腦磁盤會丢失,我們将磁盤資訊寫入配置檔案
Vi /etc/fstab
<a target="_blank" href="http://blog.51cto.com/attachment/201210/160451969.png"></a>
這時我們在模拟重新開機,umount解除安裝,mount -a 檢查,會自動挂載好的。
<a target="_blank" href="http://blog.51cto.com/attachment/201210/160504978.png"></a>
我們首先建立兩塊一樣大小的磁盤7和8,然後分别給他們賦予100MB,格式為fd格式,然後儲存,通過fdisk -l檢視狀态成功。
<a target="_blank" href="http://blog.51cto.com/attachment/201210/160641328.png"></a>
然後我們建立raid1,使用mdadm 建立磁盤陣列,接着使用mdadm -D檢視會看到acitve資訊和raid1.
<a target="_blank" href="http://blog.51cto.com/attachment/201210/161126697.png"></a>
然後格式化磁盤,挂載磁盤,會看到磁盤挂載成功。
<a target="_blank" href="http://blog.51cto.com/attachment/201210/161204105.png"></a>
Vi /etc/fstab
<a target="_blank" href="http://blog.51cto.com/attachment/201210/161219435.png"></a>
測試一下重新開機是否可以正常挂載。
<a target="_blank" href="http://blog.51cto.com/attachment/201210/161229322.png"></a>
首先建立3塊磁盤,選擇fd格式。
<a target="_blank" href="http://blog.51cto.com/attachment/201210/161241848.png"></a>
建立raid5,然後檢視結果。然後格式化挂載即可。修改/etc/fstab後,測試即可。
<a target="_blank" href="http://blog.51cto.com/attachment/201210/161304283.png"></a>
<a target="_blank" href="http://blog.51cto.com/attachment/201210/161317153.png"></a>
如果要删除raid磁盤陣列,要先解除安裝挂載,然後删除
umount /raid5
mdadm -S /dev/md5
mdadm --zero-superblock /dev/sdb{9..11}
這邊是raid的一些實戰,希望對大家有幫助。
本文轉自zsaisai 51CTO部落格,原文連結:http://blog.51cto.com/3402313/1029866