這是在 CentOS Linux上的 SoftRAID 設定方式,比起FreeBSD稍微覆雜些,原系統主硬碟安裝時parttion是沒有使用LVM(Logical Volume Manager)而是直接採用etx3格式,下面紀錄了 SoftRAID1 的安裝過程。
# fdisk -l # 查看系統上的磁區,總共兩顆 hda 及 hdb
Disk /dev/hda: 20.5 GB, 20547841536 bytes
255 heads, 63 sectors/track, 2498 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/hda1 * 1 16 128488+ 83 Linux
/dev/hda2 17 147 1052257+ 82 Linux swap / Solaris
/dev/hda3 148 2498 18884407+ 83 Linux
Disk /dev/hdb: 20.5 GB, 20547841536 bytes
16 heads, 63 sectors/track, 39813 cylinders
Units = cylinders of 1008 * 512 = 516096 bytes
Device Boot Start End Blocks Id System
# yum install mkinitrd mdadm # 安裝 softraid 管理軟體
# modprobe linear # 載入 raid 的 kernel modules(先別重開機)
# modprobe multipath
# modprobe raid0
# modprobe raid1
# modprobe raid5
# modprobe raid6
# modprobe raid10
# sfdisk -d /dev/hda | sfdisk /dev/hdb --force # 將第一顆硬碟 hda 的 parttion 複製到 hdb
# fdisk -l # 查看磁區資訊
Disk /dev/hda: 20.5 GB, 20547841536 bytes
255 heads, 63 sectors/track, 2498 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/hda1 * 1 16 128488+ 83 Linux
/dev/hda2 17 147 1052257+ 82 Linux swap / Solaris
/dev/hda3 148 2498 18884407+ 83 Linux
Disk /dev/hdb: 20.5 GB, 20547841536 bytes
16 heads, 63 sectors/track, 39813 cylinders
Units = cylinders of 1008 * 512 = 516096 bytes
Device Boot Start End Blocks Id System
/dev/hdb1 * 1 255 128488+ 83 Linux
/dev/hdb2 256 2343 1052257+ 82 Linux swap / Solaris
/dev/hdb3 2343 39812 18884407+ 83 Linux
# fdisk /dev/hdb # 對第二棵硬碟進行parttion規劃
Command (m for help): t
Partition number (1-4): 1
Hex code (type L to list codes): fd
Changed system type of partition 1 to fd (Linux raid autodetect)
Command (m for help): t
Partition number (1-4): 2
Hex code (type L to list codes): fd
Changed system type of partition 2 to fd (Linux raid autodetect)
Command (m for help): t
Partition number (1-4): 3
Hex code (type L to list codes): fd
Changed system type of partition 3 to fd (Linux raid autodetect)
Command (m for help): w
The partition table has been altered!
# mdadm --zero-superblock /dev/hdb1
# mdadm --zero-superblock /dev/hdb2
# mdadm --zero-superblock /dev/hdb3
# mdadm --create /dev/md0 --level=1 --raid-disks=2 missing /dev/hdb1
# mdadm --create /dev/md1 --level=1 --raid-disks=2 missing /dev/hdb2
# mdadm --create /dev/md2 --level=1 --raid-disks=2 missing /dev/hdb3
# cat /proc/mdstat # 查看資訊 hdb 這顆硬碟已經加入 md RAID 中
Personalities : [linear] [multipath] [raid0] [raid1] [raid6] [raid5] [raid4] [raid10]
md2 : active raid1 hdb3[1]
18884288 blocks [2/1] [_U]
md1 : active raid1 hdb2[1]
1052160 blocks [2/1] [_U]
md0 : active raid1 hdb1[1]
128384 blocks [2/1] [_U]
unused devices:
# mkfs.ext3 /dev/md0 # 格式化
# mkfs.ext3 /dev/md2
# mkswap /dev/md1
# mdadm --examine --scan >> /etc/mdadm.conf # RAID的文件配置
# cat /etc/mdadm.conf # 查看raid設定檔
ARRAY /dev/md0 level=raid1 num-devices=2 UUID=99f34a09:5928203e:48d5bb08:74e32d59
ARRAY /dev/md1 level=raid1 num-devices=2 UUID=1e1f6fdc:c7ccbdf0:ef6ede01:cea22d9e
ARRAY /dev/md2 level=raid1 num-devices=2 UUID=c3db9ae6:23891592:55838167:40aa1172
# mkdir /mnt/md0 # 建立資料夾
# mkdir /mnt/md2
# mount /dev/md0 /mnt/md0 # 掛載 md
# mount /dev/md2 /mnt/md2
# mount # 查看掛載資訊
/dev/hda3 on / type ext3 (rw)
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
devpts on /dev/pts type devpts (rw,gid=5,mode=620)
/dev/hda1 on /boot type ext3 (rw)
tmpfs on /dev/shm type tmpfs (rw)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw)
/dev/md0 on /mnt/md0 type ext3 (rw)
/dev/md2 on /mnt/md2 type ext3 (rw)
# vi /etc/fstab # 編輯 fstab 檔
/dev/md2 / ext3 defaults 1 1
/dev/md0 /boot ext3 defaults 1 2
tmpfs /dev/shm tmpfs defaults 0 0
devpts /dev/pts devpts gid=5,mode=620 0 0
sysfs /sys sysfs defaults 0 0
proc /proc proc defaults 0 0
/dev/md1 swap swap defaults 0 0
# vi /etc/mtab # 編輯 mtab 檔
/dev/md2 / ext3 rw 0 0
proc /proc proc rw 0 0
sysfs /sys sysfs rw 0 0
devpts /dev/pts devpts rw,gid=5,mode=620 0 0
/dev/md0 /boot ext3 rw 0 0
tmpfs /dev/shm tmpfs rw 0 0
none /proc/sys/fs/binfmt_misc binfmt_misc rw 0 0
sunrpc /var/lib/nfs/rpc_pipefs rpc_pipefs rw 0 0
#/dev/md0 /mnt/md0 ext3 rw 0 0
#/dev/md2 /mnt/md2 ext3 rw 0 0
# vi /boot/grub/menu.lst # 在 default=0 之後加入 fallback=1 同時將hd0改hd1以及修改root為/dev/md2
default=0
timeout=5
splashimage=(hd1,0)/grub/splash.xpm.gz
hiddenmenu
title CentOS (2.6.18-164.el5)
root (hd1,0)
kernel /vmlinuz-2.6.18-164.el5 ro root=/dev/md2
initrd /initrd-2.6.18-164.el5-raid.img
# mv /boot/initrd-`uname -r`.img /boot/initrd-`uname -r`.img_orig #備份
# mkinitrd /boot/initrd-`uname -r`.img `uname -r` # 將 Software RAID Module 載入 initrd.img
# cp -dpRx / /mnt/md2 # 將第一顆硬碟裡的資料全數複製到第二顆硬碟
# cd /boot # 切換目錄
# cp -dpRx . /mnt/md0 # 將第一顆硬碟裡的boot複製到第二顆硬碟
# grub # 修改開機設定檔
grub>root (hd0,0)
grub>setup (hd0)
grub>root (hd1,0)
grub>setup (hd1)
grub>quit
# quit
# reboot
# df -h
檔案系統 容量 已用 可用 已用% 掛載點
/dev/md2 18G 1.3G 16G 8% /
/dev/md0 122M 14M 102M 12% /boot
tmpfs 252M 0 252M 0% /dev/shm
# cat /proc/mdstat
Personalities : [raid1]
md0 : active raid1 hdb1[1]
128384 blocks [2/1] [_U]
md1 : active raid1 hdb2[1]
1052160 blocks [2/1] [_U]
md2 : active raid1 hdb3[1]
18884288 blocks [2/1] [_U]
# fdisk /dev/hda # 規劃 parttion 為 fd(Linux raid auto)格式
# mdadm --add /dev/md0 /dev/hda1 # 新增加 Parttion 到 md 軟體RAID中
# mdadm --add /dev/md1 /dev/hda2
# mdadm --add /dev/md2 /dev/hda3
# cat /proc/mdstat # 查看兩個UU表示兩顆硬碟都ok ===> 為同步進度
Personalities : [raid1]
md0 : active raid1 hda1[0] hdb1[1]
128384 blocks [2/2] [UU]
md1 : active raid1 hda2[2] hdb2[1]
1052160 blocks [2/1] [_U]
[====>................] recovery = 24.6% (259456/1052160) finish=0.6min speed=21621K/sec
md2 : active raid1 hda3[2] hdb3[1]
18884288 blocks [2/1] [_U]
resync=DELAYED
unused devices:
# watch cat /proc/mdstat # 即時查看同步進度
# vi /boot/grub/menu.lst # 修改 menu.lst 增加一筆 hd0
default=0
fallback=1
timeout=5
splashimage=(hd1,0)/grub/splash.xpm.gz
hiddenmenu
title CentOS (2.6.18-164.el5)
root (hd1,0)
kernel /vmlinuz-2.6.18-164.el5 ro root=/dev/md2
initrd /initrd-2.6.18-164.el5.img
title CentOS (2.6.18-164.el5)
root (hd0,0)
kernel /vmlinuz-2.6.18-164.el5 ro root=/dev/md2
initrd /initrd-2.6.18-164.el5.img
# mdadm --examine --scan > /etc/mdadm.conf # 完成同步後再進行第二次掃描建立 mdadm.conf 檔
# mv /boot/initrd-`uname -r`.img /boot/initrd-`uname -r`.img_orig2 # 備份
# mkinitrd /boot/initrd-`uname -r`.img `uname -r` # 將 Software RAID Module 載入 initrd.img
# reboot
※ 模擬狀況測試
1. 下指令模擬摘除某個parttion再重新掛回:
# mdadm --manage /dev/md0 --fail /dev/hdb1 --remove /dev/hdb1 # 移除第二顆硬碟hdb的第一個parttion
# mdadm --add /dev/md0 /dev/hdb1 # 重新加入 hdb1 要下指令 sync
# cat /proc/mdstat # 觀察是否正在進行 sync 動做
2. 實際關機後摘除其中一顆硬碟,開機一樣可以正常運作,接著再關機重新插回硬碟,開機後執行:
# cat /proc/mdstat # 查看
# mdadm --add /dev/md0 /dev/hda1 # 必須手動將 parttion 重新加到 md0
# mdadm --add /dev/md1 /dev/hda2 # 必須手動將 parttion 重新加到 md1
# mdadm --add /dev/md2 /dev/hda3 # 必須手動將 parttion 重新加到 md2
# cat /proc/mdstat # 可看到系統正在進行 sync
3. 關機後實際摘除其中一顆硬碟(hdb),以另一顆全新硬碟取代(新硬碟當第二顆),開機後執行:
# sfdisk -d /dev/hda | sfdisk /dev/hdb
# mdadm --add /dev/md0 /dev/hdb1
# mdadm --add /dev/md1 /dev/hdb2
# cat /proc/mdstat # 靜候 sync 作業完成
※ 監控管理
# mdadm --monitor --scan --mail= your-email@address.com /dev/md0 -t -1 #手動測試監控發信通知
# crontab -e # 加入 crontab 每隔一段時間監控發信通知
*/5 * * * * /sbin/mdadm --monitor --scan --mail= your-email@address.com /dev/md0 -1
Ref.
http://www.howtoforge.com/how-to-set-up-software-raid1-on-a-running-system-incl-grub-configuration-centos-5.3
2010/04/30
[ LOS ] Set Up Software RAID1 On CentOS Linux
訂閱:
張貼意見 (Atom)


0 意見:
張貼意見