Linux下實現Raid 5軟陣列

mdadm使用詳解及RAID 5簡單分析,一般系統自帶有。

mdadm用法

基本語法 mdadm [mode] <raid-device> [options] <component-devices>

mode  7種:

  1. Assemble:將以前定義的某個陣列加入當前在用陣列。

  2. BuildBuild a legacy array ,每個device 沒有 superblocks

  3.Create:創建一個新的陣列,每個device 具有 superblocks

  4.Manage 管理陣列,比如 add remove

  5.Misc:允許單獨對陣列中的某個 device 做操作,比如抹去superblocks 終止在用的陣列。

 6. Follow or Monitor:監控 raid 1,4,5,6 multipath 的狀態

 7. Grow:改變raid 容量或 陣列中的 device 數目

 
可用的 [options]:

-A, --assemble:加入一個以前定義的陣列

-B, --buildBuild a legacy array without superblocks.

-C, --create:創建一個新的陣列

-Q, --query:查看一個device,判斷它爲一個 md device 或是 一個 md 陣列的一部分

-D, --detail:打印一個或多個 md device 的詳細信息

-E, --examine:打印 device 上的 md superblock 的內容

-F, --follow, --monitor:選擇 Monitor 模式

-G, --grow:改變在用陣列的大小或形態

-h, --help:幫助信息,用在以上選項後,則顯示該選項信息

--help-options

-V, --version

-v, --verbose:顯示細節

-b, --brief:較少的細節。用於 --detail --examine 選項

-f, --force

-c, --config= :指定配置文件,缺省爲 /etc/mdadm.conf

-s, --scan:掃描配置文件或 /proc/mdstat以搜尋丟失的信息。配置文件/etc/mdadm.conf
RARI-5配置的基本步驟:

添加4塊硬盤。

[root@localhost ~]# fdisk –l  查看
分區

N(開始劃分分區)àP(主分區)->1(第一個主分區)  然後指定大小

           分區的大小要相同

 [root@localhost ~]# fdisk /dev/sdc

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 previouscontent won't be recoverable.

 

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 添加主分區1

First cylinder (1-130, default 1):確定第一個主分區的起始磁柱,默認爲1就好。

Last cylinder or +size or +sizeM or +sizeK (1-130, default 130): 50 設置大小(也可用+200M來指定)

Command (m for help): p  查看

 

Disk /dev/sdc: 1073 MB, 1073741824 bytes

255 heads, 63 sectors/track, 130 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

 

   Device Boot    Start       End      Blocks   Id  System

/dev/sdc1             1        50      401593+  83  Linux

Command (m for help): t 改變分區類型

Selected partition 1

Hex code (type L to list codes): fd    fdlinux raid autodetect

Changed system type of partition 1 to fd (Linux raid autodetect)

 

Command (m for help): p

 

Disk /dev/sdc: 1073 MB, 1073741824 bytes

255 heads, 63 sectors/track, 130 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

 

   Device Boot      Start         End      Blocks   Id  System

/dev/sdc1               1          50      401593+  fd  Linux raid autodetect

 

Command (m for help): w q 保存退出 (不保存退出)

劃分完之後

[root@localhost ~]# fdisk –l 查看

Disk /dev/sdc: 1073 MB, 1073741824 bytes

255 heads, 63 sectors/track, 130 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

 

   Device Boot      Start         End      Blocks   Id  System

/dev/sdc1               1          50      401593+  fd  Linux raid autodetect

 

Disk /dev/sdd: 1073 MB, 1073741824 bytes

255 heads, 63 sectors/track, 130 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

 

   Device Boot      Start         End      Blocks   Id  System

/dev/sdd1               1          50      401593+  fd  Linux raid autodetect

 

Disk /dev/sde: 1073 MB, 1073741824 bytes

255 heads, 63 sectors/track, 130 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

 

   Device Boot      Start         End      Blocks   Id  System

/dev/sde1               1          50      401593+  fd  Linux raid autodetect

創建RAID-5

 

好了現在我們隨便添加些數據

查看RAID信息

[root@localhost ~]# mdadm -D /dev/md5

 

[root@localhost ~]# mdadm /dev/md5 -f /dev/sdc1

mdadm: set /dev/sdc1 faulty in /dev/md5

[root@localhost ~]# mdadm -D /dev/md5

 
 

移除失敗磁盤

[root@localhost ~]# mdadm /dev/md5 –r /dev/sdc1

mdadm: hot removed /dev/sdc1

[root@localhost ~]# mdadm -D /dev/md5

雖然壞了一個盤,但數據依然在。
現在我們來添加一塊盤,分區.格式做成RAID5.

[root@localhost ~]# fdisk /dev/sdf

將磁盤加入到陣列中,可以看到數據正在恢復中並完整恢復

保存配置文件

若要開機自動掛載,請在/etc/fstab中添加:

/dev/md5        /mnt/md5        auto    defaults        0 0

 
 
 

 

 
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章