歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> Linux教程 >> Linux下構建raid0、raid1、raid5

Linux下構建raid0、raid1、raid5

日期:2017/2/28 16:30:59   编辑:Linux教程

根據raid0屬性,構建時至少需要兩塊硬盤,硬盤類型不限
假設系統後加入3塊scsi硬盤,系統識別後分別是sdb、sdc、sdd
各分成一個區,這裡先設置sdb
[root@myserver root]# fdisk /dev/sdb
The number of cylinders for this disk is set to 1044.
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 OSs
(e.g., DOS FDISK, OS/2 FDISK)
Command (m for help):n --新建分區
First cylinder (1-1044, default 1):1 --直接回車就是默認
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-1044, default 1044):1044 --直接回車就是默認
Using default value 1044

Command (m for help): w --保存退出
The partition table has been altered!
Calling ioctl() to re-read partition table.
The new table will be used at the next reboot.
Syncing disks.

[root@myserver root]# fdisk -l /dev/sdb --查看分區結果,這塊硬盤只分一個區,所以只有一個"sdb1"
Disk /dev/sda: 8589 MB, 8589934592 bytes
255 heads, 63 sectors/track, 1044 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sdb1 1 1044 3068383+ 83 Linux
同樣方法對另外兩個新加硬盤進行分區,得到 /dev/sdc1 和 /dev/sdd1

下面看系統中是否已經安裝了raid軟件包
[root@myserver root]# rpm -q raidtools
raidtools-1.00.3-2 --已經安裝
[root@myserver root]# rpm -ql raidtools-1.00.3-2 --查看示范配置文件路徑
/usr/share/doc/raidtools-1.00.3/raid0.conf.sample
/usr/share/doc/raidtools-1.00.3/raid1.conf.sample
/usr/share/doc/raidtools-1.00.3/raid4.conf.sample
/usr/share/doc/raidtools-1.00.3/raid5.conf.sample
/usr/share/doc/raidtools-1.00.3/raidtab.sample
-
-
-
[root@myserver root]# cp /usr/share/doc/raidtools-1.00.3/raid0.conf.sample /etc/raidtab
--把raid0的示范配置文件拷到/etc下,並命名為raidtab

修改raidtab文件內容以符合當前情況
# Sample raid-0 configuration
raiddev /dev/md0 --raid設備
raid-level 0 # it's not obvious but this *must* be --raid級別
# right after raiddev
persistent-superblock 0 # set this to 1 if you want autostart,
# BUT SETTING TO 1 WILL DESTROY PREVIOUS
# CONTENTS if this is a RAID0 array created
# by older raidtools (0.40-0.51) or mdtools!
chunk-size 16
nr-raid-disks 3 --由幾塊硬盤組成
nr-spare-disks 0
device /dev/sdb1 --第一塊
raid-disk 0 --硬盤序號0,代表第一塊
device /dev/sdc1 --第二塊
raid-disk 1 --硬盤序號1,代表第二塊
device /dev/sdd1 --第三塊
raid-disk 2 --硬盤序號2,代表第三塊

[root@myserver root]# mkraid /dev/md0 --創建raid設備
handling MD device /dev/md0
analyzing super-block

[root@myserver root]# mkfs.ext3 /dev/md0 --格式化已創建的raid設備

[root@myserver root]# mount /dev/md0 /mnt/md0 --掛載到/mnt/md0


然後df查看一下是否掛載成功並測試是否可寫進文件
目前為止raid0就算構建完了,現在他的存儲速度就要快了很多
為了長久使用這個raid設備,可將它寫進fstab
[root@myserver root]# cat /etc/fstab
LABEL=/ / ext3 defaults 1 1
/dev/md0 /mnt/md0 ext3 defaults 0 0

[root@myserver root]# raidstop /dev/md0 --停止raid0設備工作,停止前要先卸載/dev/md0

[root@myserver root]# lsraid -A -a /dev/md0 --查看raid設備中硬盤工作狀態,是否有壞盤

----------------------------------------- -----------------------------------

raid1、raid5和raid0構建類似,不過需要注意:

1,因為raid1是做數據鏡像,所以構建raid1需要的硬盤數為偶數
2,因為raid5是做數據校驗,所以構建raid5需要的硬盤數為至少三塊
3,采用對應的示范配置文件,raid1就取raid1.conf.sample,raid5就取raid5.conf.sample,按實際情況修改它

Copyright © Linux教程網 All Rights Reserved