P02: Cài đặt RAID 1 trên hệ thống LVM trong Ubuntu 10.04

Tạo hệ thống RAID Arrays
Trong bước tiếp theo, chúng ta sẽ tiến hành khởi tạo RAID arrays /dev/md0 và /dev/md1. Trong đó, /dev/sdb1 sẽ được thêm vào /dev/md0 và/dev/sdb5 tới /dev/md1. Nhưng /dev/sda1 và /dev/sda5 vẫn chưa thể thêm vào thời điểm hiện tại (bởi vì hệ thống được cài đặt và hoạt động trên những phân vùng này), do vậy ta phải sử dụng cú pháp missing trong các câu lệnh sau:
mdadm --create /dev/md0 --level=1 --raid-disks=2 missing /dev/sdb1
mdadm --create /dev/md1 --level=1 --raid-disks=2 missing /dev/sdb5

Câu lệnh:
cat /proc/mdstat
chỉ ra rằng chúng ta đang có 2 RAID arrays xuống cấp ([_U] hoặc [U_] có nghĩa là 1 array bị xuống cấp, còn [UU] vẫn ổn):
root@server1:~# cat /proc/mdstat
Personalities : [linear] [multipath] [raid0] [raid1] [raid6] [raid5] [raid4] [raid10]
md1 : active raid1 sdb5[1]
4990912 blocks [2/1] [_U]

md0 : active raid1 sdb1[1]
248768 blocks [2/1] [_U]

unused devices:
root@server1:~#

Tiếp theo, tạo file hệ thống (ext2) trên RAID array non-LVM /dev/md0:
mkfs.ext2 /dev/md0
Và LVM RAID array trên /dev/md1. Để chuẩn bị cho LVM, thực hiện lệnh sau:
pvcreate /dev/md1
Sau đó thêm /dev/md1 tới volume group server1:
vgextend server1 /dev/md1
Kết quả của
pvdisplay
sẽ trông giống như sau:
root@server1:~# pvdisplay
--- Physical volume ---
PV Name /dev/sda5
VG Name server1
PV Size 4.76 GiB / not usable 2.00 MiB
Allocatable yes
PE Size 4.00 MiB
Total PE 1218
Free PE 3
Allocated PE 1215
PV UUID bsF5F5-s2RN-ed1h-zjeb-4mAJ-aktq-kEn86r

--- Physical volume ---
PV Name /dev/md1
VG Name server1
PV Size 4.76 GiB / not usable 1.94 MiB
Allocatable yes
PE Size 4.00 MiB
Total PE 1218
Free PE 1218
Allocated PE 0
PV UUID rQf0Rj-Nn9l-VgbP-0kIr-2lve-5jlC-TWTBGp

root@server1:~#

Kết quả của
vgdisplay
sẽ có dạng như sau:
root@server1:~# vgdisplay
--- Volume group ---
VG Name server1
System ID
Format lvm2
Metadata Areas 2
Metadata Sequence No 4
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 2
Open LV 2
Max PV 0
Cur PV 2
Act PV 2
VG Size 9.52 GiB
PE Size 4.00 MiB
Total PE 2436
Alloc PE / Size 1215 / 4.75 GiB
Free PE / Size 1221 / 4.77 GiB
VG UUID hMwXAh-zZsA-w39k-g6Bg-LW4W-XX8q-EbyXfA

You have new mail in /var/mail/root
root@server1:~#

Bước tiếp theo là điều chỉnh /etc/mdadm/mdadm.conf như sau:
cp /etc/mdadm/mdadm.conf /etc/mdadm/mdadm.conf_orig
mdadm --examine --scan >> /etc/mdadm/mdadm.conf

Hiển thị nội dung của file:
cat /etc/mdadm/mdadm.conf
Và bạn sẽ thấy thông tin chi tiết của 2 RAID array:
# mdadm.conf
#
# Please refer to mdadm.conf(5) for information about this file.
#

# by default, scan all partitions (/proc/partitions) for MD superblocks.
# alternatively, specify devices to scan, using wildcards if desired.
DEVICE partitions

# auto-create devices with Debian standard permissions
CREATE owner=root group=disk mode=0660 auto=yes

# automatically tag new arrays as belonging to the local system
HOMEHOST

# instruct the monitoring daemon where to send mail alerts
MAILADDR root

# definitions of existing MD arrays

# This file was auto-generated on Wed, 16 Jun 2010 20:01:25 +0200
# by mkconf $Id$
ARRAY /dev/md0 level=raid1 num-devices=2 UUID=90f05e41:bf936896:325ecf68:79913751
ARRAY /dev/md1 level=raid1 num-devices=2 UUID=1ab36b7f:3e2031c0:325ecf68:79913751

Tiếp theo là chính sửa /etc/fstab:
vi /etc/fstab

# /etc/fstab: static file system information.
#
# Use 'blkid -o value -s UUID' to print the universally unique identifier
# for a device; this may be used with UUID= as a more robust way to name
# devices that works even if disks are added and removed. See fstab(5).
#
#
proc /proc proc nodev,noexec,nosuid 0 0
/dev/mapper/server1-root / ext4 errors=remount-ro 0 1
# /boot was on /dev/sda1 during installation
#UUID=67b1337f-89a2-4729-a6c8-6d43ba82d1f1 /boot ext2 defaults 0 2
/dev/md0 /boot ext2 defaults 0 2
/dev/mapper/server1-swap_1 none swap sw 0 0
/dev/fd0 /media/floppy0 auto rw,user,noauto,exec,utf8 0 0

Thay thế /dev/sda1 với /dev/md0 trong /etc/mtab:
vi /etc/mtab

/dev/mapper/server1-root / ext4 rw,errors=remount-ro 0 0
proc /proc proc rw,noexec,nosuid,nodev 0 0
none /sys sysfs rw,noexec,nosuid,nodev 0 0
none /sys/fs/fuse/connections fusectl rw 0 0
none /sys/kernel/debug debugfs rw 0 0
none /sys/kernel/security securityfs rw 0 0
none /dev devtmpfs rw,mode=0755 0 0
none /dev/pts devpts rw,noexec,nosuid,gid=5,mode=0620 0 0
none /dev/shm tmpfs rw,nosuid,nodev 0 0
none /var/run tmpfs rw,nosuid,mode=0755 0 0
none /var/lock tmpfs rw,noexec,nosuid,nodev 0 0
none /lib/init/rw tmpfs rw,nosuid,mode=0755 0 0
/dev/md0 /boot ext2 rw 0 0

Và GRUB2 boot loader, tạo file /etc/grub.d/09_swraid1_setup như sau:
cp /etc/grub.d/40_custom /etc/grub.d/09_swraid1_setup
vi /etc/grub.d/09_swraid1_setup

#!/bin/sh
exec tail -n +3 $0
# This file provides an easy way to add custom menu entries. Simply type the
# menu entries you want to add after this comment. Be careful not to change
# the 'exec tail' line above.
menuentry 'Ubuntu, with Linux 2.6.32-21-server' --class ubuntu --class gnu-linux --class gnu --class os {
recordfail
insmod raid
insmod mdraid
insmod ext2
set root='(md0)'
linux /vmlinuz-2.6.32-21-server root=/dev/mapper/server1-root ro quiet
initrd /initrd.img-2.6.32-21-server
}

Hãy chắc chắn rằng phiên bản bộ nhân kernel dùng trong menuentry stanza (được khai báo trong dòng lệnh linux và initrd). Các bạn có thể tìm thông tin này bằng lệnh sau:
uname -r
Chạy lệnh:
update-grub
để viết nhân kernel stanza mới từ etc/grub.d/09_swraid1_setup tới /boot/grub/grub.cfg. Tiếp theo là điều chỉnh ramdisk:
update-initramfs -u 

Di chuyển dữ liệu tới RAID Array
Khi chúng ta đã hoàn thành quá trình tạo và thiết lập các file cần thiết, tiếp theo sẽ copy toàn bộ dữ liệu từ /dev/sda tới /dev/sdb. Để chuyển nội dung của phân vùng LVM /dev/sda5 tới LVM RAID array /dev/md1, sử dụng lệnh pvmove:
pvmove -i 2 /dev/sda5 /dev/md1
Chờ 1 lúc để quá trình này kết thúc hoàn toàn. Sau đó, bỏ phân vùng /dev/sda5 từ volume group server1 …:
vgreduce server1 /dev/sda5
và “nhắc nhở” hệ thống không sử dụng /dev/sda5 với LVM nữa:
pvremove /dev/sda5
Kết quả của câu lệnh:
pvdisplay
sẽ có dạng giống như sau:
root@server1:~# pvdisplay
--- Physical volume ---
PV Name /dev/md1
VG Name server1
PV Size 4.76 GiB / not usable 1.94 MiB
Allocatable yes
PE Size 4.00 MiB
Total PE 1218
Free PE 3
Allocated PE 1215
PV UUID rQf0Rj-Nn9l-VgbP-0kIr-2lve-5jlC-TWTBGp

root@server1:~#

Sau đó, thay đổi định dạng phân vùng của /dev/sda5 thành Linux raid autodetect và thêm /dev/sda5 vào the /dev/md1 array:
fdisk /dev/sda

root@server1:~# fdisk /dev/sda

WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
switch off the mode (command 'c') and change display units to
sectors (command 'u').

Command (m for help): <-- gõ t
Partition number (1-5): <-- gõ 5
Hex code (type L to list codes): <-- gõ fd
Changed system type of partition 5 to fd (Linux raid autodetect)

Command (m for help): <-- gõ w
The partition table has been altered!

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.
root@server1:~#

mdadm --add /dev/md1 /dev/sda5

Tiếp theo, hãy nhìn qua
cat /proc/mdstat
và bạn sẽ thấy rằng RAID array /dev/md1 đang được tích hợp:
root@server1:~# cat /proc/mdstat
Personalities : [linear] [multipath] [raid0] [raid1] [raid6] [raid5] [raid4] [raid10]
md1 : active raid1 sda5[2] sdb5[1]
4990912 blocks [2/1] [_U]
[=========>...........] recovery = 45.1% (2251776/4990912) finish=0.4min speed=90071K/sec

md0 : active raid1 sdb1[1]
248768 blocks [2/1] [_U]

unused devices:
root@server1:~#

Chờ tới khi quá trình này kết thúc:
root@server1:~# cat /proc/mdstat
Personalities : [linear] [multipath] [raid0] [raid1] [raid6] [raid5] [raid4] [raid10]
md1 : active raid1 sda5[0] sdb5[1]
4990912 blocks [2/2] [UU]

md0 : active raid1 sdb1[1]
248768 blocks [2/1] [_U]

unused devices:
root@server1:~#

).

Việc tiếp theo là kết hợp phân vùng /dev/md0:
mkdir /mnt/md0

mount /dev/md0 /mnt/md0

mount

root@server1:~# mount
/dev/mapper/server1-root on / type ext4 (rw,errors=remount-ro)
proc on /proc type proc (rw,noexec,nosuid,nodev)
none on /sys type sysfs (rw,noexec,nosuid,nodev)
none on /sys/fs/fuse/connections type fusectl (rw)
none on /sys/kernel/debug type debugfs (rw)
none on /sys/kernel/security type securityfs (rw)
none on /dev type devtmpfs (rw,mode=0755)
none on /dev/pts type devpts (rw,noexec,nosuid,gid=5,mode=0620)
none on /dev/shm type tmpfs (rw,nosuid,nodev)
none on /var/run type tmpfs (rw,nosuid,mode=0755)
none on /var/lock type tmpfs (rw,noexec,nosuid,nodev)
none on /lib/init/rw type tmpfs (rw,nosuid,mode=0755)
/dev/md0 on /boot type ext2 (rw)
/dev/md0 on /mnt/md0 type ext2 (rw)
root@server1:~#

Bây giờ, chúng ta có thể sao chép toàn bộ dữ liệu của /dev/sda1 tới /dev/md0 (đã được kết hợp trên /mnt/md0):
cd /boot
cp -dpRx . /mnt/md0 

Theo QuanTriMang

0 comments:

Post a Comment