茫茫網海中的冷日
         
茫茫網海中的冷日
發生過的事,不可能遺忘,只是想不起來而已!
 恭喜您是本站第 1676295 位訪客!  登入  | 註冊
主選單

Google 自訂搜尋

Goole 廣告

隨機相片
IMG_60D_00070.jpg

授權條款

使用者登入
使用者名稱:

密碼:


忘了密碼?

現在就註冊!

小企鵝開談 : [分享]使用 mdadm 建立 RAID(以 RAID5 為例)

發表者 討論內容
冷日
(冷日)
Webmaster
  • 註冊日: 2008/2/19
  • 來自:
  • 發表數: 15771
[分享]使用 mdadm 建立 RAID(以 RAID5 為例)
1、首先,我們要先建立新磁盤分區
#fdisk /dev/hda

建立3個500MB的分區(hda7,hda8,hda9),然後在fdisk命令下輸入t,
選擇剛建立好的分區,輸入fd,將剛建立好的3個分區轉換為fd格式。
輸入w保存退出

2、激活剛建立好的分區
#partprobe


3、將3個分區加載到md0,l5是代表RAID級別是RAID5,n3代表有3個分區。
#mdadm –C /dev/md0 –l5 –n3 /dev/had{7,8,9}


4、查看一下建立的RAID分區
#cat /proc/mdstat


5、將md0分區格式化成ext3格式,將RAID分區mount到目錄上,
並修改fstab表
#mkfs.ext3 /dev/md0
#mount /dev/md0 /pot
#vi /etc/fstab


這樣我們就成功建立了一個RAID5的磁盤分區。

------------------------------------------------------------
建立LVM
1、首先,我們要先建立新磁盤分區
#fdisk /dev/had

建立2個500MB分區(hda10,hda11),然後在fdisk命令下輸入t,
選擇剛建立好的分區,輸入8e,將剛建立好的2個分區轉換為8e格式。
輸入w保存退出

2、激活剛建立好的分區
#partprobe


3、建立成pv格式
#pvcreate /dev/had{10,11}
#pvdisplay


4、將分區加載到vg卷組,vg0是卷組名稱,vg0卷組總空間是1000MB
#vgcreate vg0 /dev/had{10,11}
#vgdisplay


5、建立lv分區800M是分區大小,lv0是lv分區名稱,vg0是加載到卷組名稱,
此時建立了一個800MB的lvm分區,vg0卷組還剩餘200MB的空間
#lvcreate –L 800M –nlv0 vg0
#lvdisplay


6、將lv分區格式化成ext3格式
#mkfs.ext3 /dev/vg0/lv0


7、將LVM分區mount到目錄上,並修改fstab表
#mount /dev/vg0/lv0 /lvm
#vi /etc/fstab


8、擴展(lv)剛才我們建立了800mb的lvm分區,當要對分區進行擴展應
如下操作:
#lvextend –L+100M /dev/vg0/lv0
#ext2online /dev/vg0/lv0


此時,我們已經向lv0分區增加了100MB空間,vg0卷組還剩餘100MB空間,
如果當我們認為空間還是不足,需要擴充,而vg0卷組的空間也不足時,我們
就需要對vg0卷組進行擴展,然後再對lv分區進行擴展

1、建立1個500MB分區(hda12),然後在fdisk命令下輸入t,選擇剛建立
好的分區,輸入8e,將剛建立好的分區轉換為8e格式。輸入w保存退出
#fdisk /dev/had


2、激活剛建立好的分區
#partprobe


3、建立成pv格式
#pvcreate /dev/had12


4、將hda12添加到vg0卷組,此時vg0卷組的總空間大小為1500MB
#vgextend vg0 /dev/hda12


5、對lv0分區進行動態擴展,增加500M空間
#lvextend –L+500M /dev/vg0/lv0
#ext2online /dev/vg0/lv0


此時我們建立 LVM分區大小總空間應為800M+100M+500M=1400M
冷日
(冷日)
Webmaster
  • 註冊日: 2008/2/19
  • 來自:
  • 發表數: 15771
[分享]不景氣下的省錢妙招 在linux上玩 Soft RAID
這一次我安裝 Mandriva 10,核心是2.6,使用 mdadm這一套softraid 軟體,程序如下(整理於 自身建立過程與網路資料):
=====
安裝
=====
先安裝
# rpm -ivh mdadm-1.12.0-1mdk.i586.rpm
...應該已經夠用!沒有 RAID10 及 GROW MODE
也可再升級
# rpm -Uvh mdadm-2.6-1.i386.rpm

==========
準備磁碟
==========
# fdisk -l
(顯示所有系統上的硬碟狀況,可以知道哪一些硬碟尚未配置及代號)
# fdisk /dev/sdb
將設備/dev/sdb上的全部磁碟空間劃分給一個主分區,建立/dev/sdb1分區,並修改分區的類型標識為fd(linux raid auto)

建立RAID的使用指令
==================================
清除已經建立的raid記錄資料 重新開始
==================================
# mdadm -C /dev/md0 -l5 -n3 /dev/sd{a,b,c}1 --assume-clean
注意,如果沒有使用--assume-clean系統建立陣列後,會自動重建原有的內容!若要全新來過,一定要加此指令!

============
建立RAID 0:
============
# mdadm -Cv -l 0 /dev/md0 -n 2 /dev/hdc {8,9}

-C是指建立
-v是指察看過程
-l是指建立的屬於level linear、0、1或5
/dec/md0是指在linux中建立的裝置名稱為RAID 0
-n 2是指幾個RAID裝置屬於建立好的RAID 0
/dev/hdc {8,9}是指建立在/dev/hdc8和/dev/hdc9兩個partition上

======================
查閱目前的raid資訊
======================
方法一:
可利用--detail參數來觀看建立好的RAID 0(1、5)的資訊
# mdadm --detail /dev/md0(md1、5)

其中有chunk-size是指寫進一個partition的大小 ,例如RAID 0中把一個file同時寫進兩個或以上partition時,會把file分成多大寫進其中一個partition(系統記錄在/proc/mdstat)

方法二:
mdadm -D /dev/md0


========
格式化:
========
ext2 格式:
# mke2fs -v -b 4096 -R stride=16 /dev/md0
(md後為數字0)
(-R stride=n來增加效能,因為chunk-size=block*stride,因此對於RAID 0來說可以增加效能,對於其它RAID不一定能增加效能,例:RAID 1)

ext3格式:
mkfs -t ext3 /dev/md0


==========
掛載並使用
==========
# mkdir /mnt/md0
(建立/mnt/md0資料夾)
# mount /dev/md0 /mnt/md0
(掛載/dev/md0至/mnt/md0)

============
解除RAID裝置
============
# umount /dev/md0
(卸載/dev/md0)
# mdadm -S /dev/md0
(參數-S會直接解除 /dev/md0上的RAID 0)

================
重新啟用raid裝置
================
方法一:直接指定使用的磁區
# mdadm -A /dev/md0 /dev/sd{c,d,e}1
(啟動先前已經建立的陣列,並指定原來使用的磁區)

方法二:使用配置檔 /etc/mdadm.conf
mdadm的缺省配置檔為/etc/mdadm.conf,它主要是為了方便陣列的日常管理而設置的,對於陣列而言不是必須的,但是為了減少日後管理中不必要的麻煩,還是應該堅持把這一步做完。
在mdadm.conf檔中要包含兩種類型的行:
一種是以DEVICE開頭的行,它指明在陣列中的設備列表;
另一種是以ARRAY開頭的行,它詳細地說明了陣列的名稱、模式、陣列中活動設備的數目以及設備的UUID號。
格式如下:
DEVICE /dev/sdb1 /dev/sdc1 /dev/sdd1 /dev/sde1
ARRAY /dev/md0 level=raid5 num-devices=3 UUID=8f128343:715a42df: baece2a8: a5b878e0

以上的這些資訊可以通過掃描系統的陣列來獲取
建立好被製檔案後,啟動的語法如下
# mdadm -As /dev/md0
(s 表示使用配置檔中的設定啟動raid)

======================
如果是做raid1+0 的啟動
======================
# mdadm -As /dev/md0
# mdadm -As /dev/md1
# mdadm -A /dev/md2 /dev/md{0,1}

===================
希望開機時直接啟用 .....前提是必須建立配置檔才可以,不然開機時無法順利啟動raid
===================

=======
方法一:
=======
當不是使用raid1時,或是raid1的硬碟群不很大!至於極限到哪,未測試!
寫入/etc/fstab(開機時會載入的硬體設定檔)
# vi /etc/fstab
(以vi編輯/etc/fstab設定檔)

最後一行加入
/dev/md0 /mnt/md0 ext2 default 0 0


(fstab欄位說明)
第一欄 實際的 device 名稱。
第二欄 對應到的目錄結構(mount point)。
第三欄 該分割區的檔案系統ext、ext2、msdos、iso9660、nfs、swap。
第四欄 在 mount 時的參數。
第五欄 在使用 dump 時是否記錄,不需要則輸入0。
第六欄 決定在開機時執行 fsck 的先後順序。

=======
方法二:
=======
針對raid1硬碟群過大的時,必須加入指令於
/etc/rc.d/rc.sysinit or /etc/rc.d/rc.local

的最後面,讓raid1先隨系統啟動!以免無法順利掛載!
mdadm -As /dev/md0
mount /dev/md0 掛載目錄


=======
方法三:
=======
在/etc/profile.d/
自行增加 **.sh的指令檔 例如 vi mdadm.sh
然後賦予mdadm.sh執行的權限 chmod 755 mdadm.sh
mdadm -As /dev/md0
mount /dev/md0 /dev/md0 掛載目錄


===>以上應該已經可以建立完成一個soft raid,以下是一些補充建立、修復說明

=========================================
建立RAID 1(建立流程,並參考RAID 0之說明)
=========================================
# mdadm -Cv --level=1 /dev/md0 -n 2 /dev/hdc8 /dev/hdc9 -x1 /dev/hdc10
(-x:指定備用的硬碟,當其中一個毀損時會自動備援)
# mke2fs -j /dev/md0
# mount /dev/md0 /mnt/md0
# cp -a /bin /mnt/md0
(copy /bin中的資料做測試,-R 可以讓複製過去的資料保有相同的資料權限)

=======================
測試/dev/hdc9壞掉與替換
=======================
# mdadm /dev/md0 -f /dev/hdc9
(測試/dev/hdc9壞掉時,將/dev/hdc9標記為已損壞的設備)
# mdadm -D /dev/md0
查閱raid目前狀況一

=================
查看當前陣列狀態二..可以看到目前正在自動恢復資料,這是抓其他地方的資料來補充,並不是原來的raid1
=================
# more /proc/mdstat
Personalities : [raid5]
md0 : active raid5 sdd1[2] sde1[3] sdc1[1] sdb1[4](F)
75469842 blocks level 5, 128k chunk, algorithm 2 [3/2] [_UU]
[=>...................] recovery = 8.9% (3358407/37734912) finish=1.6min speed=9382K/sec
unused devices:

因為有備份設備,所以當陣列中出現設備損壞時,陣列能夠在短時間內實現重構和
資料的恢復。從當前的狀態可以看出,陣列正在重構,且運行在降級模式,
sdb1[4]的後面已經標上了(F),活動設備數也降為2個。

經過幾分鐘後,再次查看當前陣列狀態。
# more /proc/mdstat
Personalities : [raid5]
md0 : active raid5 sdd1[2] sde1[0] sdc1[1] sdb1[3](F)
75469842 blocks level 5, 128k chunk, algorithm 2 [3/3] [UUU]
unused devices:

此時陣列重構已經完成,資料恢復完畢,原有的備份設備sde1成為了活動設備。

=============
恢復/dev/hdc9
=============
# mdadm /dev/md0 --remove /dev/hdc9
移除損壞的設備
# mdadm /dev/md0 --add /dev/hdc9
將新設備添加到陣列中
# mdadm --grow /dev/md-linear --add /dev/new-device
如果使用的是 linear raid

=========================================
建立RAID 5(建立流程,並參考RAID 0之說明)
=========================================
# mdadm -C -l 5 /dev/md0 -n 3 /dev/hdc{8,9,10} -x 1 /dev/hdc11
(可加入-c128的參數,代表chunk-size為128:可以增加raid的效能,由於是軟體陣列所以是使用系統主記憶體來進行 chunk,這個數值設大一點雖然對磁碟陣列效能有幫助,但卻會耗掉系統資源,建議使用預設值就好了)
冷日
(冷日)
Webmaster
  • 註冊日: 2008/2/19
  • 來自:
  • 發表數: 15771
[轉貼]linux下軟raid的實現
linux下軟raid的實現

raid是當前存儲提高安全和性能的主要技術手段,實現raid一般用raid卡實現,也就是硬raid。除此之外,我們還可以用軟件來實現raid技術。
這篇文章就簡單介紹如何用軟件實現raid技術(以raid0為例)。

參考:http://space6212.itpub.net/post/12157/306986

但覺得步驟有點問題,且在生成mdadm配置文件寫的不夠詳細,現整理一下以備後查.

有兩個可以實現軟raid的工具:raidtools, mdadm。
raidtool,這是在RHEL3中所使用的,但是我在RHEL4中沒有找到raidtool,只有mdadm,看來RH也是偏向於使用mdadm的。
本文也以mdadm為例講述。

一、查看當前硬盤情況
[root@primary /]# fdisk -l

Disk /dev/sda: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System
/dev/sda1 * 1 13 104391 83 Linux
/dev/sda2 14 1114 8843782+ 83 Linux
/dev/sda3 1115 1305 1534207+ 82 Linux swap

Disk /dev/sdb: 107 MB, 107374080 bytes
64 heads, 32 sectors/track, 102 cylinders
Units = cylinders of 2048 * 512 = 1048576 bytes

Disk /dev/sdb doesn't contain a valid partition table

Disk /dev/sdc: 107 MB, 107374080 bytes
64 heads, 32 sectors/track, 102 cylinders
Units = cylinders of 2048 * 512 = 1048576 bytes

Disk /dev/sdc doesn't contain a valid partition table


二、為硬盤分區
raid一般多個硬盤來組成,你也可以用同一個硬盤的多個分區組成raid,但這樣是沒有意義的。
[root@primary /]# 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.

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-102, default 1):
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-102, default 102):
Using default value 102

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.
[root@primary /]# 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 previous
content 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
First cylinder (1-102, default 1):
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-102, default 102):
Using default value 102

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.

此時硬盤的分區情況:
[root@primary /]# fdisk -l

Disk /dev/sda: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System
/dev/sda1 * 1 13 104391 83 Linux
/dev/sda2 14 1114 8843782+ 83 Linux
/dev/sda3 1115 1305 1534207+ 82 Linux swap

Disk /dev/sdb: 107 MB, 107374080 bytes
64 heads, 32 sectors/track, 102 cylinders
Units = cylinders of 2048 * 512 = 1048576 bytes

Device Boot Start End Blocks Id System
/dev/sdb1 1 102 104432 83 Linux

Disk /dev/sdc: 107 MB, 107374080 bytes
64 heads, 32 sectors/track, 102 cylinders
Units = cylinders of 2048 * 512 = 1048576 bytes

Device Boot Start End Blocks Id System
/dev/sdc1 1 102 104432 83 Linux


三、創建raid0
[root@primary /]# mdadm --create /dev/md0 --level=raid0 --chunk=8 --raid-devices=2 /dev/sdb1 /dev/sdc1


四、生成mdadm配置文件
mdadm的缺省配置文件為/etc/mdadm.conf,它主要是為了方便陣列的日常管理而設置的,對於陣列而言不是必須的,但是為了減少日後管理中不必要的麻煩,還是應該堅持把這一步做完。

在mdadm.conf文件中要包含兩種類型的行:一種是以DEVICE開頭的行,它指明在陣列中的設備列表;另一種是以ARRAY開頭的行,它詳細地說明了陣列的名稱、模式、陣列中活動設備的數目以及設備的UUID號。
我們可以用mdadm -Ds來得到mdadm.conf文件需要的信息:
[root@primary ~]# mdadm -Ds
ARRAY /dev/md0 level=raid0 num-devices=2 UUID=63f24968:d367038d:f207e458:9a803df9
devices=/dev/sdb1,/dev/sdc1

根據上面的信息編輯/etc/mdadm.conf,如下:
[root@primary ~]# more /etc/mdadm.conf
ARRAY /dev/md0 level=raid0 num-devices=2 UUID=63f24968:d367038d:f207e458:9a803df9
device /dev/sdb1 /dev/sdc1

如果不配置這個文件,在重啟後嘗試mount raid設備的時候會報錯:
[root@primary ~]# mount /dev/md0 /opt
/dev/md0: Invalid argument
mount: /dev/md0: can't read superblock

也可能通過命令生成這個配置文件:
# mdadm --detail --scan > /etc/mdadm.conf

但是當前生成「mdadm.conf」文件的內容並不符合所規定的格式,所以也是不生效的,這時需要手工修改該文件內容為如下格式:
# vi /etc/mdadm.conf
DEVICE /dev/sdb1 /dev/sdc1
ARRAY /dev/md0 level=raid0 num-devices=2 UUID=b372436a:6ba09b3d:2c80612c:efe19d75


五、格式化raid
mdadm: array /dev/md0 started.
[root@primary /]# mkfs.ext3 /dev/md0
mke2fs 1.35 (28-Feb-2004)
max_blocks 213647360, rsv_groups = 26080, rsv_gdb = 256
Filesystem label=
OS type: Linux
Block size=1024 (log=0)
Fragment size=1024 (log=0)
52208 inodes, 208640 blocks
10432 blocks (5.00%) reserved for the super user
First data block=1
Maximum filesystem blocks=67371008
26 block groups
8192 blocks per group, 8192 fragments per group
2008 inodes per group
Superblock backups stored on blocks:
8193, 24577, 40961, 57345, 73729, 204801

Writing inode tables: done
inode.i_blocks = 3586, i_size = 67383296
Creating journal (4096 blocks): done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 26 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.


六、掛載raid分區
[root@primary /]# mount /dev/md0 /opt
[root@primary /]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda2 8.4G 5.7G 2.3G 73% /
/dev/sda1 99M 8.4M 86M 9% /boot
none 252M 0 252M 0% /dev/shm
/dev/hdc 161M 161M 0 100% /media/cdrom
/dev/md0 198M 5.8M 182M 4% /opt


七、查看raid的信息
[root@primary opt]# mdadm --detail /dev/md0
/dev/md0:
Version : 00.90.01
Creation Time : Sun Jul 8 22:54:28 2007
Raid Level : raid0
Array Size : 208640 (203.75 MiB 213.65 MB)
Raid Devices : 2
Total Devices : 2
Preferred Minor : 0
Persistence : Superblock is persistent

Update Time : Sun Jul 8 22:54:29 2007
State : clean
Active Devices : 2
Working Devices : 2
Failed Devices : 0
Spare Devices : 0

Chunk Size : 8K

Number Major Minor RaidDevice State
0 8 17 0 active sync /dev/sdb1
1 8 33 1 active sync /dev/sdc1
UUID : a86f0502:df5715c0:fd871bbc:9f75e0ad
Events : 0.1


八、設置開機自動掛載
為了讓系統開機後能自動掛載raid設備,需要在/etc/fstab添加如下行:
vi /etc/fstab
/dev/md0 /opt ext3 defaults 0 0

至此,一個raid0就算配置完畢了。其他級別的raid也可以用類似的方法配置,具體可以看幫助。

取消移除軟raid的方法:
[root@linx131 etc]# umount /dev/md2
[root@linx131 etc]# mdadm --stop /dev/md2
[root@linx131 etc]# mdadm --misc --zero-superblock /dev/sdd5
[root@linx131 etc]# mdadm --misc --zero-superblock /dev/sde5

測試一下原來raid的數據是否存在.
[root@linx131 etc]# mount /dev/sde5 /mnt
[root@linx131 etc]# cd /mnt
[root@linx131 mnt]# ls
lost+found md2
[root@linx131 mnt]# cat md2
aaaa

查看一下狀態,md2已不存在了.
[root@linx131 /]# cat /proc/mdstat
Personalities : [raid1] [raid5]
md1 : active raid1 sde1[1] sdd1[0]
987840 blocks [2/2] [UU]

md0 : active raid5 sdb1[0] sdc1[1]
5237056 blocks level 5, 8k chunk, algorithm 2 [2/2] [UU]

unused devices:


經過我們經理指點,其實取消軟raid只需要兩步:
1.mdadm /dev/md1 --fail /dev/sda1
2.mdadm /dev/md1 -r /dev/sda1


這樣的話,原先md1的一個分區/sda1就從raid中移除了,自然raid就不存在了.


原文出處:Get lot Everyday | linux下軟raid的實現
冷日
(冷日)
Webmaster
  • 註冊日: 2008/2/19
  • 來自:
  • 發表數: 15771
[轉貼]mdadm使用詳解及 RAID 5 簡單分析

mdadm使用詳解及RAID 5簡單分析


本文是 用raidtools創建Linux Soft RAID的續篇,關於如何使用raidtools在Linux下創建軟RAID請參考原文

關於RAID原理、常用的RAID級別和參數以及各種RAID之間的對比可參考以下鏈接:

RAID Calculator ( en | ch ) &
RAID Summary Comparison ( en | ch ) beta @ my googlepage



★什麼是mdadm?

mdadm是 multiple devices admin的簡稱,它是Linux下的一款標準的軟件 RAID 管理工具,作者是 Neil Brown


★為什麼選擇mdadm?


我們知道 raidtools是Linux下一款經典的用於管理軟件 RAID 的工具,但是因為配置
/etc/raidtab比較繁瑣,而且其功能有限,所以現在越來越多的人選擇mdadm。

mdadm 和 raidtools 主要有以下幾點不同

  • mdadm能夠診斷、監控和收集詳細的陣列信息
  • mdadm是一個單獨集成化的程序而不是一些分散程序的集合,因此對不同RAID管理命令有共通的語法
  • mdadm能夠執行幾乎所有的功能而不需要配置文件(也沒有默認的配置文件)
  • 當然,如果需要一個配置文件,mdadm將幫助管理它的內容


★準備工作

QUOTE:
首先我們在虛擬機中添加四塊SCSI硬盤(我們仍然直接使用只有一個分區的硬盤( sdb、sdc、sdd、sde)來作為RAID設備的成員,每個盤大小為 8G)並分區格式化,具體步驟可參考 用raidtools創建Linux Soft RAID,這裡從略

你也可以使用基於RPM的發佈包,你可以從 這裡下載,不過最新的RPM為 2.6-1
版本:

[root@localhost mdadm-2.6.2]# rpm -ihv mdadm-1.4.0-1.i386.rpm 


★mdadm簡介

我們可以使用 man mdadm命令來查看mdadm的幫助信息:

[root@localhost mdadm-2.6.2]# man mdadm


關於 man mdadm的詳細信息請查看 4樓



☆mdadm用法

基本語法

mdadm [mode] <raid-device> [options] <component-devices>


目前支持

LINEAR, RAID0(striping), RAID1(mirroring), RAID4, RAID5, RAID6, RAID10, MULTIPATH和FAULTY


模式(7種):

  • Assemble:加入一個以前定義的陣列
  • Build:創建一個沒有超級塊的陣列
  • Create:創建一個新的陣列,每個設備具有超級塊
  • Manage: 管理陣列(如添加和刪除)
  • Misc:允許單獨對陣列中的某個設備進行操作(如停止陣列)
  • Follow or Monitor:監控RAID的狀態
  • Grow:改變RAID的容量或陣列中的設備數目


選項:
-A, --assemble:加入一個以前定義的陣列
-B, --build:創建一個沒有超級塊的陣列(Build a legacy array without superblocks.)
-C, --create:創建一個新的陣列
-F, --follow, --monitor:選擇監控(Monitor)模式
-G, --grow:改變激活陣列的大小或形態
-I, --incremental:添加一個單獨的設備到合適的陣列,並可能啟動陣列
--auto-detect:請求內核啟動任何自動檢測到的陣列
-h, --help:幫助信息,用在以上選項後,則顯示該選項信息
--help-options:顯示更詳細的幫助
-V, --version:打印mdadm的版本信息
-v, --verbose:顯示細節
-b, --brief:較少的細節。用於 --detail 和 --examine 選項
-Q, --query:查看一個device,判斷它為一個 md device 或是 一個 md 陣列的一部分
-D, --detail:打印一個或多個 md device 的詳細信息
-E, --examine:打印 device 上的 md superblock 的內容
-c, --config= :指定配置文件,缺省為 /etc/mdadm.conf

-s, --scan:掃瞄配置文件或 /proc/mdstat以搜尋丟失的信息。配置文件/etc/mdadm.conf



★使用mdadm創建RAID5

Create ( mdadm --create)模式用來創建一個新的陣列。 在這裡我們首先使用 mdadm --create --help查看一下幫助:

[root@localhost mdadm-2.6.2]# mdadm --create --help
Usage:  mdadm --create device -chunk=X --level=Y --raid-devices=Z devices

This usage will initialise a new md array, associate some
devices with it, and activate the array.   In order to create an
array with some devices missing, use the special word 'missing' in
place of the relevant device name.

Before devices are added, they are checked to see if they already contain
raid superblocks or filesystems.  They are also checked to see if
the variance in device size exceeds 1%.
If any discrepancy is found, the user will be prompted for confirmation

before the array is created.  The presence of a '--run' can override this
caution.

If the --size option is given then only that many kilobytes of each
device is used, no matter how big each device is.
If no --size is given, the apparent size of the smallest drive given
is used for raid level 1 and greater, and the full device is used for
other levels.

Options that are valid with --create (-C) are:
 --bitmap=          : Create a bitmap for the array with the given filename
 --chunk=      -c   : chunk size of kibibytes
 --rounding=        : rounding factor for linear array (==chunk size)
 --level=      -l   : raid level: 0,1,4,5,6,linear,multipath and synonyms
 --parity=     -p   : raid5/6 parity algorithm: {left,right}-{,a}symmetric
 --layout=          : same as --parity

 --raid-devices= -n : number of active devices in array
 --spare-devices= -x: number of spares (eXtras) devices in initial array
 --size=       -z   : Size (in K) of each drive in RAID1/4/5/6/10 - optional
 --force       -f   : Honour devices as listed on command line.  Don't
                    : insert a missing drive for RAID5.
 --run         -R   : insist of running the array even if not all
                    : devices are present or some look odd.
 --readonly    -o   : start the array readonly - not supported yet.
 --name=       -N   : Textual name for array - max 32 characters
 --bitmap-chunk=    : bitmap chunksize in Kilobytes.
 --delay=      -d   : bitmap update delay in seconds.


接下來我們使用 mdadm創建在/dev/md0上創建一個由 sdb、sdc、sdd3塊盤組成(另外1塊盤 sde為熱備)的RAID5:

[root@localhost mdadm-2.6.2]# mdadm --create --verbose /dev/md0 --level=raid5 --raid-devices=3 /dev/sdb /dev/sdc /dev/sdd --spare-devices=1 /dev/sde
mdadm: layout defaults to left-symmetric
mdadm: chunk size defaults to 64K
mdadm: size set to 8388544K
mdadm: array /dev/md0 started.


每個 mdadm的選項都有一個 縮寫的形式,例如,上面我們創建RAID 5的命令可以使用下列的縮寫形式:

[root@localhost mdadm-2.6.2]# mdadm -Cv /dev/md0 -l5 -n3 /dev/sdb /dev/sdc /dev/sdd -x1 /dev/sde


二者的效果是相同的。



★查看RAID狀態

接下來我們使用 cat /proc/mdstat命令來查看一下RAID的狀態,我們也可以利用 watch命令來每隔一段時間刷新 /proc/mdstat的輸出。使用
CTRL+C可以取消。

[root@localhost mdadm-2.6.2]# watch -n 10 'cat /proc/mdstat'
Every 10s: cat /proc/mdstat                             Thu May 24 11:53:46 2007

Personalities : [raid5]
read_ahead 1024 sectors
md0 : active raid5 sdd[4] sde[3] sdc[1] sdb[0]
     16777088 blocks level 5, 64k chunk, algorithm 2 [3/2] [UU_]
     [====>................]  recovery = 24.0% (2016364/8388544) finish=10.2min
speed=10324K/sec
unused devices: <none>
[root@localhost mdadm-2.6.2]#


接下來我們為陣列創建文件系統:

[root@localhost mdadm-2.6.2]# mkfs.ext3 /dev/md0
mke2fs 1.34 (25-Jul-2003)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
2097152 inodes, 4194272 blocks
209713 blocks (5.00%) reserved for the super user
First data block=0
128 block groups

32768 blocks per group, 32768 fragments per group
16384 inodes per group
Superblock backups stored on blocks:
       32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
       4096000

Writing inode tables: done
Creating journal (8192 blocks): done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 34 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.
You have new mail in /var/spool/mail/root


我們嘗試向RAID中寫入一個test2文件:

[root@localhost eric4ever]# vi test2
copy succeed!
eric@tlf
[url]http://eric4ever.googlepages.com/[/url]
done!
[root@localhost eric4ever]# ls
LATEST.tgz  mdadm-2.6.2  test2
[root@localhost eric4ever]# mount /dev/md0 /mnt/md0
[root@localhost eric4ever]# df -lh

Filesystem            Size  Used Avail Use% Mounted on
/dev/sda1             2.9G  1.8G  1.1G  63% /
/dev/sda3             4.6G   33M  4.3G   1% /opt
none                  125M     0  125M   0% /dev/shm
/dev/md0               16G   33M   15G   1% /mnt/md0
[root@localhost eric4ever]# ls /mnt/md0
lost+found
[root@localhost eric4ever]# cp ./test2 /mnt/md0
[root@localhost eric4ever]# ls /mnt/md0
lost+found  test2
[root@localhost eric4ever]# ls -lh /mnt/md0
total 20K
drwx------    2 root     root          16K May 24 11:55 lost+found
-rw-r--r--    1 root     root           63 May 24 11:56 test2


使用
mdadm --detail /dev/md0(或 mdadm -D /dev/md0)命令以及 cat /proc/mdstat命令可以查看RAID設備的狀態:

[root@localhost eric4ever]# mdadm -D /dev/md0  (或mdadm --detail /dev/md0)
/dev/md0:
       Version : 00.90.00
 Creation Time : Thu May 24 13:45:35 2007
    Raid Level : raid5
    Array Size : 16777088 (16.00 GiB 17.18 GB)
 Used Dev Size : 8388544 (8.00 GiB 8.59 GB)
  Raid Devices : 3
 Total Devices : 5
Preferred Minor : 0
   Persistence : Superblock is persistent

   Update Time : Thu May 24 13:45:36 2007
         State : active, degraded, recovering
Active Devices : 2
Working Devices : 4
Failed Devices : 1
 Spare Devices : 2

        Layout : left-symmetric
    Chunk Size : 64K


Rebuild Status : 16% complete

          UUID : 4b15050e:7d0c477d:98ed7d00:0f3c29e4
        Events : 0.2

   Number   Major   Minor   RaidDevice State
      0       8       16        0      active sync   /dev/sdb
      1       8       32        1      active sync   /dev/sdc
      2       0        0        2      removed

      3       8       64        3      spare   /dev/sde
      4       8       48        4      spare   /dev/sdd


通過
mdadm -D命令,我們可以查看RAID的 版本、創建的時間、RAID級別、陣列容量、可用空間、設備數量、超級塊、更新時間、各個設備的狀態、RAID算法以及塊大小等信息,通過上面的信息我們可以看到目前RAID正處於 重建過程之中,進度為 16%,其中 /dev/sdb/dev/sdc兩塊盤已經 同步。使用 watch命令每個30秒刷新一下查看的進度:

[root@localhost eric4ever]# watch -n 30 'cat /proc/mdstat'
Every 30s: cat /proc/mdstat                             Thu May 24 13:55:56 2007

Personalities : [raid5]
read_ahead 1024 sectors
md0 : active raid5 sdd[4] sde[3] sdc[1] sdb[0]
     16777088 blocks level 5, 64k chunk, algorithm 2 [3/2] [UU_]
     [==============>......]  recovery = 72.3% (6067444/8388544) finish=3.7min
speed=10324K/sec
unused devices: <none>

當進度進行到
100%時,顯示如下:

Every 30s: cat /proc/mdstat                             Thu May 24 14:00:57 2007

Personalities : [raid5]
read_ahead 1024 sectors
md0 : active raid5 sdd[2] sde[3] sdc[1] sdb[0]
     16777088 blocks level 5, 64k chunk, algorithm 2 [3/3] [UUU]

unused devices: <none>


這是我們再使用 mdadm -D命令查看一下:

[root@localhost eric4ever]# mdadm -D /dev/md0  (或mdadm --detail /dev/md0)
/dev/md0:
       Version : 00.90.00
 Creation Time : Thu May 24 13:45:35 2007
    Raid Level : raid5
    Array Size : 16777088 (16.00 GiB 17.18 GB)
 Used Dev Size : 8388544 (8.00 GiB 8.59 GB)
  Raid Devices : 3
 Total Devices : 5
Preferred Minor : 0
   Persistence : Superblock is persistent


   Update Time : Thu May 24 13:59:48 2007
         State : active
Active Devices : 3
Working Devices : 4
Failed Devices : 1
 Spare Devices : 1

        Layout : left-symmetric
    Chunk Size : 64K

          UUID : 4b15050e:7d0c477d:98ed7d00:0f3c29e4
        Events : 0.3

   Number   Major   Minor   RaidDevice State
      0       8       16        0      active sync   /dev/sdb
      1       8       32        1      active sync   /dev/sdc
      2       8       48        2      active sync   /dev/sdd


      3       8       64        3      spare   /dev/sde


這時我們可以發現 sdb、sdc、sdd三塊盤均已經同步。

一般來說,一個新陣列被創建後我們最好創建一個/etc/mdadm.conf文件。沒有該文件在激活陣列時我們就得指定更詳細的信息,為方便,我們使用下列命令:

[root@localhost eric4ever]# mdadm --detail --scan
ARRAY /dev/md0 level=raid5 num-devices=3 spares=1 UUID=4b15050e:7d0c477d:98ed7d00:0f3c29e4
[root@localhost eric4ever]# mdadm --detail --scan >> /etc/mdadm.conf
[root@localhost eric4ever]# cat /etc/mdadm.conf
ARRAY /dev/md0 level=raid5 num-devices=3 spares=1 UUID=4b15050e:7d0c477d:98ed7d00:0f3c29e4


★啟動停止RAID

使用 --stop-S命令選項可以停止運行的陣列(注意:
停止前必須先umount):

[root@localhost eric4ever]# umount /mnt/md0
[root@localhost eric4ever]# mdadm -S /dev/md0  (或mdadm --stop /dev/md0)
mdadm: stopped /dev/md0


重新啟動可以使用:

[root@localhost eric4ever]# mdadm -As /dev/md0
mdadm: /dev/md0 has been started with 3 drives and 1 spare.



★模擬故障

同raidtools一樣,mdadm也可以軟件模擬故障,命令選項為 --fail--set-faulty

[root@localhost eric4ever]# mdadm --set-faulty --help
Usage: mdadm arraydevice options component devices...

This usage is for managing the component devices within an array.
The --manage option is not needed and is assumed if the first argument
is a device name or a management option.

The first device listed will be taken to be an md array device, and
subsequent devices are (potential) components of that array.

Options that are valid with management mode are:
 --add         -a   : hotadd subsequent devices to the array
 --remove      -r   : remove subsequent devices, which must not be active
 --fail        -f   : mark subsequent devices a faulty
 --set-faulty       : same as --fail
 --run         -R   : start a partially built array
 --stop        -S   : deactivate array, releasing all resources
 --readonly    -o   : mark array as readonly
 --readwrite   -w   : mark array as readwrite
[root@localhost eric4ever]# mdadm --fail --help
Usage: mdadm arraydevice options component devices...


This usage is for managing the component devices within an array.
The --manage option is not needed and is assumed if the first argument
is a device name or a management option.
The first device listed will be taken to be an md array device, and
subsequent devices are (potential) components of that array.

Options that are valid with management mode are:
 --add         -a   : hotadd subsequent devices to the array
 --remove      -r   : remove subsequent devices, which must not be active
 --fail        -f   : mark subsequent devices a faulty
 --set-faulty       : same as --fail
 --run         -R   : start a partially built array
 --stop        -S   : deactivate array, releasing all resources
 --readonly    -o   : mark array as readonly

 --readwrite   -w   : mark array as readwrite


接下來我們模擬 /dev/sdb故障:

[root@localhost eric4ever]# mdadm --manage --set-faulty /dev/md0 /dev/sdb
mdadm: set /dev/sdb faulty in /dev/md0


查看一下系統日誌,如果你配置了冗余磁盤,可能會顯示如下信息:

   kernel: raid5: Disk failure on sdb, disabling device.
   kernel: md0: resyncing spare disk sde to replace failed disk


檢查 /proc/mdstat,如果配置的冗余磁盤可用,陣列可能已經開始重建。

首先我們使用 mdadm --detail /dev/md0命令來查看一下RAID的狀態:

[root@localhost eric4ever]# mdadm --detail /dev/md0
/dev/md0:
       Version : 00.90.00
 Creation Time : Thu May 24 13:45:35 2007
    Raid Level : raid5
    Array Size : 16777088 (16.00 GiB 17.18 GB)
 Used Dev Size : 8388544 (8.00 GiB 8.59 GB)
  Raid Devices : 3
 Total Devices : 5

Preferred Minor : 0
   Persistence : Superblock is persistent

   Update Time : Thu May 24 14:07:55 2007
         State : active, degraded, recovering
Active Devices : 2
Working Devices : 3
Failed Devices : 2
 Spare Devices : 1

        Layout : left-symmetric
    Chunk Size : 64K

Rebuild Status : 3% complete

          UUID : 4b15050e:7d0c477d:98ed7d00:0f3c29e4
        Events : 0.6

   Number   Major   Minor   RaidDevice State
      0       8       16        0      faulty spare   /dev/sdb
      1       8       32        1      active sync   /dev/sdc

      2       8       48        2      active sync   /dev/sdd

      3       8       64        3      spare rebuilding   /dev/sde


查看 /proc/mdstat

[root@localhost eric4ever]# cat /proc/mdstat
Personalities : [raid5]
read_ahead 1024 sectors
md0 : active raid5 sdb[4] sde[3] sdd[2] sdc[1]
     16777088 blocks level 5, 64k chunk, algorithm 2 [3/2] [_UU]
     [==>..................]  recovery = 10.2% (858824/8388544) finish=12.4min speed=10076K/sec
unused devices: <none>


再查看一下RAID狀態:

[root@localhost eric4ever]# mdadm --detail /dev/md0
/dev/md0:
       Version : 00.90.00
 Creation Time : Thu May 24 13:45:35 2007

    Raid Level : raid5
    Array Size : 16777088 (16.00 GiB 17.18 GB)
 Used Dev Size : 8388544 (8.00 GiB 8.59 GB)
  Raid Devices : 3
 Total Devices : 5
Preferred Minor : 0
   Persistence : Superblock is persistent

   Update Time : Thu May 24 14:08:27 2007
         State : active, degraded, recovering
Active Devices : 2
Working Devices : 4
Failed Devices : 1
 Spare Devices : 2

        Layout : left-symmetric
    Chunk Size : 64K

Rebuild Status : 11% complete

          UUID : 4b15050e:7d0c477d:98ed7d00:0f3c29e4
        Events : 0.8

   Number   Major   Minor   RaidDevice State
      0       0        0        0      removed

      1       8       32        1      active sync   /dev/sdc
      2       8       48        2      active sync   /dev/sdd

      3       8       64        3      spare   /dev/sde
      4       8       16        4      spare   /dev/sdb


已經完成到 11%了。查看一下日誌消息:

[root@localhost eric4ever]# tail /var/log/messages
May 24 14:08:27 localhost kernel:  --- rd:3 wd:2 fd:1
May 24 14:08:27 localhost kernel:  disk 0, s:0, o:0, n:0 rd:0 us:0 dev:[dev 00:00]
May 24 14:08:27 localhost kernel:  disk 1, s:0, o:1, n:1 rd:1 us:1 dev:sdc

May 24 14:08:27 localhost kernel:  disk 2, s:0, o:1, n:2 rd:2 us:1 dev:sdd
May 24 14:08:27 localhost kernel: RAID5 conf printout:
May 24 14:08:27 localhost kernel:  --- rd:3 wd:2 fd:1
May 24 14:08:27 localhost kernel:  disk 0, s:0, o:0, n:0 rd:0 us:0 dev:[dev 00:00]
May 24 14:08:27 localhost kernel:  disk 1, s:0, o:1, n:1 rd:1 us:1 dev:sdc
May 24 14:08:27 localhost kernel:  disk 2, s:0, o:1, n:2 rd:2 us:1 dev:sdd
May 24 14:08:27 localhost kernel: md: cannot remove active disk sde from md0 ...


使用 mdadm -E命令查看一下 /dev/sdb的情況:

[root@localhost eric4ever]# mdadm -E /dev/sdb
/dev/sdb:
         Magic : a92b4efc
       Version : 00.90.00
          UUID : 4b15050e:7d0c477d:98ed7d00:0f3c29e4
 Creation Time : Thu May 24 13:45:35 2007
    Raid Level : raid5

 Used Dev Size : 8388544 (8.00 GiB 8.59 GB)
    Array Size : 16777088 (16.00 GiB 17.18 GB)
  Raid Devices : 3
 Total Devices : 5
Preferred Minor : 0

   Update Time : Thu May 24 14:08:27 2007
         State : active
Active Devices : 2
Working Devices : 4
Failed Devices : 1
 Spare Devices : 2
      Checksum : a6a19662 - correct
        Events : 0.8

        Layout : left-symmetric
    Chunk Size : 64K

     Number   Major   Minor   RaidDevice State
this     4       8       16        4      spare   /dev/sdb

  0     0       0        0        0      faulty removed

  1     1       8       32        1      active sync   /dev/sdc
  2     2       8       48        2      active sync   /dev/sdd
  3     3       8       64        3      spare   /dev/sde
  4     4       8       16        4      spare   /dev/sdb


自動修復完成後,我們再查看一下RAID的狀態:

[root@localhost eric4ever]# mdadm --detail /dev/md0
/dev/md0:
       Version : 00.90.00
 Creation Time : Thu May 24 13:45:35 2007
    Raid Level : raid5
    Array Size : 16777088 (16.00 GiB 17.18 GB)
 Used Dev Size : 8388544 (8.00 GiB 8.59 GB)
  Raid Devices : 3

 Total Devices : 5
Preferred Minor : 0
   Persistence : Superblock is persistent

   Update Time : Thu May 24 14:21:54 2007
         State : active
Active Devices : 3
Working Devices : 4
Failed Devices : 1
 Spare Devices : 1

        Layout : left-symmetric
    Chunk Size : 64K

          UUID : 4b15050e:7d0c477d:98ed7d00:0f3c29e4
        Events : 0.9

   Number   Major   Minor   RaidDevice State
      0       8       64        0      active sync   /dev/sde
      1       8       32        1      active sync   /dev/sdc

      2       8       48        2      active sync   /dev/sdd

      4       8       16        4      spare   /dev/sdb
[root@localhost eric4ever]# cat /proc/mdstat
Personalities : [raid5]
read_ahead 1024 sectors
md0 : active raid5 sdb[4] sde[0] sdd[2] sdc[1]
     16777088 blocks level 5, 64k chunk, algorithm 2 [3/3] [UUU]

unused devices: <none>


我們可以看到 /dev/sde已經替換了 /dev/sdb。看看系統的日誌消息:

[root@localhost eric4ever]# tail /var/log/messages
May 24 14:21:54 localhost kernel:  --- rd:3 wd:3 fd:0
May 24 14:21:54 localhost kernel:  disk 0, s:0, o:1, n:0 rd:0 us:1 dev:sde
May 24 14:21:54 localhost kernel:  disk 1, s:0, o:1, n:1 rd:1 us:1 dev:sdc

May 24 14:21:54 localhost kernel:  disk 2, s:0, o:1, n:2 rd:2 us:1 dev:sdd
May 24 14:21:54 localhost kernel: md: updating md0 RAID superblock on device
May 24 14:21:54 localhost kernel: md: sdb [events: 00000009]<6>(write) sdb's sb offset: 8388544
May 24 14:21:54 localhost kernel: md: sde [events: 00000009]<6>(write) sde's sb offset: 8388544
May 24 14:21:54 localhost kernel: md: sdd [events: 00000009]<6>(write) sdd's sb offset: 8388544
May 24 14:21:54 localhost kernel: md: sdc [events: 00000009]<6>(write) sdc's sb offset: 8388544
May 24 14:21:54 localhost kernel: md: recovery thread got woken up ...


recovery thread got woken up ...

這時我們可以從 /dev/md0中移除 /dev/sdb設備:

[root@localhost eric4ever]# mdadm /dev/md0 -r /dev/sdb
mdadm: hot removed /dev/sdb


類似地,我們可以使用下列命令向 /dev/md0中添加一個設備:


[root@localhost eric4ever]# mdadm /dev/md0 --add /dev/sdf



★監控RAID

mdadm的監控模式提供一些實用的功能,你可以使用下列命令來監控 /dev/md0,delay參數意味著檢測的時間間隔,這樣緊急事件和嚴重的錯誤會及時發送給系統管理員:

[root@localhost eric4ever]# mdadm --monitor --mail=eric4ever@localhost --delay=300 /dev/md0


當使用監控模式時,mdadm不會退出,你可以使用下列命令:

[root@localhost eric4ever]# nohup mdadm --monitor --mail=eric4ever@localhost --delay=300 /dev/md0 &
[1] 3113
[root@localhost eric4ever]# nohup: appending output to `nohup.out'

原文出處:mdadm使用詳解及RAID 5簡單分析 - 最實用的Linux博客 - CSDNBlog
前一個主題 | 下一個主題 | 頁首 | | |



Powered by XOOPS 2.0 © 2001-2008 The XOOPS Project|