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

Google 自訂搜尋

Goole 廣告

隨機相片
IMG_221459.jpg

授權條款

使用者登入
使用者名稱:

密碼:


忘了密碼?

現在就註冊!

對這文章發表回應

發表限制: 非會員 可以發表

發表者: 冷日 發表時間: 2009/1/7 6:34:45
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的實現
內容圖示
url email imgsrc image code quote
樣本
bold italic underline linethrough   












 [詳情...]
validation picture

注意事項:
預覽不需輸入認證碼,僅真正發送文章時才會檢查驗證碼。
認證碼有效期10分鐘,若輸入資料超過10分鐘,請您備份內容後,重新整理本頁並貼回您的內容,再輸入驗證碼送出。

選項

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