Tải bản đầy đủ (.pdf) (10 trang)

Cài đặt RAID 1 trên hệ thống LVM trong Ubuntu 10.4 (phần cuối ) ppsx

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (109.72 KB, 10 trang )

Cài đặt RAID 1 trên hệ thống LVM trong Ubuntu 10.4
(phần cuối )

Chuẩn bị GRUB2
1 điểm quan trọng không kém là GRUB2 bootloader phải được cài đặt
trên cả 2 phân vùng ổ cứng, /dev/sda và /dev/sdb:
grub-install /dev/sda
grub-install /dev/sdb
Khởi động lại hệ thống:
reboot
Chuẩn bị /dev/sda
Nếu tất cả hoạt động bình thường, bạn sẽ thấy /dev/md0 trong kết quả trả
về của câu lệnh:
df -h

root@server1:~# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/server1-root
4.5G 816M 3.4G 19% /
none 242M 196K 242M 1% /dev
none 247M 0 247M 0% /dev/shm
none 247M 40K 247M 1% /var/run
none 247M 0 247M 0% /var/lock
none 247M 0 247M 0% /lib/init/rw
/dev/md0 236M 23M 201M 11% /boot
root@server1:~#
Và kết quả của
cat /proc/mdstat
sẽ như thế này:
root@server1:~# cat /proc/mdstat
Personalities : [linear] [multipath] [raid0] [raid1] [raid6] [raid5]


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

md1 : active raid1 sda5[0] sdb5[1]
4990912 blocks [2/2] [UU]

unused devices: <none>
root@server1:~#
Tượng tự, kết quả thu được của pvdisplay, vgdisplay, và lvdisplay sẽ như
vậy:
pvdisplay

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:~#

vgdisplay

root@server1:~# vgdisplay

Volume group
VG Name server1
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 9
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 2
Open LV 2
Max PV 0
Cur PV 1
Act PV 1
VG Size 4.76 GiB
PE Size 4.00 MiB
Total PE 1218
Alloc PE / Size 1215 / 4.75 GiB
Free PE / Size 3 / 12.00 MiB
VG UUID hMwXAh-zZsA-w39k-g6Bg-LW4W-XX8q-EbyXfA

root@server1:~#

lvdisplay

root@server1:~# lvdisplay
Logical volume
LV Name /dev/server1/root
VG Name server1
LV UUID b5A1R5-Zhml-LSNy-v7WY-NVmD-yX1w-tuQVUW

LV Write Access read/write
LV Status available
# open 1
LV Size 4.49 GiB
Current LE 1149
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 251:0

Logical volume
LV Name /dev/server1/swap_1
VG Name server1
LV UUID 2UuF7C-zxKA-Hgz1-gZHe-rFlq-cKW7-jYVCzp
LV Write Access read/write
LV Status available
# open 1
LV Size 264.00 MiB
Current LE 66
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 251:1

root@server1:~#
Đồng thời, thay đổi định dạng của /dev/sda1 thành Linux raid autodetect:
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õ 1
Hex code (type L to list codes): < gõ fd
Changed system type of partition 1 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:~#
Thêm /dev/sda1 vào /dev/md0 RAID array:
mdadm add /dev/md0 /dev/sda1
Bây giờ hãy xem qua:
cat /proc/mdstat

root@server1:~# cat /proc/mdstat
Personalities : [linear] [multipath] [raid0] [raid1] [raid6] [raid5]

[raid4] [raid10]
md0 : active raid1 sda1[0] sdb1[1]
248768 blocks [2/2] [UU]

md1 : active raid1 sda5[0] sdb5[1]
4990912 blocks [2/2] [UU]

unused devices: <none>
root@server1:~#
Sau đó thay đổi file /etc/mdadm/mdadm.conf như sau:
cp /etc/mdadm/mdadm.conf_orig /etc/mdadm/mdadm.conf
mdadm examine scan >> /etc/mdadm/mdadm.conf
File /etc/mdadm/mdadm.conf sẽ trông giống như sau:
cat /etc/mdadm/mdadm.conf

# 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 <system>


# 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
Bây giờ, chúng ta cần xóa file /etc/grub.d/09_swraid1_setup …:

rm -f /etc/grub.d/09_swraid1_setup
và cập nhật file thiết lập GRUB2 bootloader:
update-grub
update-initramfs -u
Sau đó khởi động lại hệ thống:
reboot
Nếu không có vấn đề gì xảy ra thì có nghĩa là bạn đã hoàn tất quá trình
thiết lập và cài đặt phần mềm theo chuẩn RAID1 trên hệ thống LVM.
Kiểm tra toàn bộ
Bây giờ, hãy giả sử rằng có 1 ổ cứng bị lỗi. Nhưng thực sự không có vấn
đề gì xảy ra nếu bạn lựa chọn /dev/sda hoặc /dev/sdb trong trường hợp
này. Trong ví dụ này, phân vùng /dev/sdb bị lỗi.
Để mô phỏng lỗi này, bạn có thể tắt bỏ hệ thống hoặc gỡ bỏ /dev/sdb khỏi
hệ thống:
mdadm manage /dev/md0 fail /dev/sdb1
mdadm manage /dev/md1 fail /dev/sdb5


mdadm manage /dev/md0 remove /dev/sdb1
mdadm manage /dev/md1 remove /dev/sdb5
Sau đó tắt hệ thống:
shutdown -h now
Rồi gắn ổ cứng /dev/sdb và khởi động hệ thống:
cat /proc/mdstat
và bạn sẽ nhìn thấy mã miêu tả tình trạng hệ thống tạm thời:
root@server1:~# cat /proc/mdstat
Personalities : [linear] [multipath] [raid0] [raid1] [raid6] [raid5]
[raid4] [raid10]
md0 : active raid1 sda1[0]
248768 blocks [2/1] [U_]

md1 : active raid1 sda5[0]
4990912 blocks [2/1] [U_]

unused devices: <none>
root@server1:~#
Kết quả của:
fdisk -l
sẽ như sau:
root@server1:~# fdisk -l

Disk /dev/sda: 5368 MB, 5368709120 bytes
255 heads, 63 sectors/track, 652 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x0006b7b7


Device Boot Start End Blocks Id System
/dev/sda1 * 1 32 248832 fd Linux raid autodetect
Partition 1 does not end on cylinder boundary.
/dev/sda2 32 653 4990977 5 Extended
Partition 2 does not end on cylinder boundary.
/dev/sda5 32 653 4990976 fd Linux raid autodetect

Disk /dev/sdb: 5368 MB, 5368709120 bytes
255 heads, 63 sectors/track, 652 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

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

Disk /dev/md1: 5110 MB, 5110693888 bytes
2 heads, 4 sectors/track, 1247728 cylinders
Units = cylinders of 8 * 512 = 4096 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

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

Disk /dev/md0: 254 MB, 254738432 bytes
2 heads, 4 sectors/track, 62192 cylinders
Units = cylinders of 8 * 512 = 4096 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes

Disk identifier: 0x00000000

Disk /dev/md0 doesn't contain a valid partition table
root@server1:~#
Tiếp theo, sao chép định dạng phân vùng của /dev/sda tới /dev/sdb:
sfdisk -d /dev/sda | sfdisk force /dev/sdb

root@server1:~# sfdisk -d /dev/sda | sfdisk force /dev/sdb
Checking that no-one is using this disk right now
Warning: extended partition does not start at a cylinder boundary.
DOS and Linux will interpret the contents differently.
OK

Disk /dev/sdb: 652 cylinders, 255 heads, 63 sectors/track

sfdisk: ERROR: sector 0 does not have an msdos signature
/dev/sdb: unrecognized partition table type
Old situation:
No partitions found
New situation:
Units = sectors of 512 bytes, counting from 0

Device Boot Start End #sectors Id System
/dev/sdb1 * 2048 499711 497664 fd Linux raid autodetect
/dev/sdb2 501758 10483711 9981954 5 Extended
/dev/sdb3 0 - 0 0 Empty
/dev/sdb4 0 - 0 0 Empty
/dev/sdb5 501760 10483711 9981952 fd Linux raid autodetect
Warning: partition 1 does not end at a cylinder boundary
Successfully wrote the new partition table


Re-reading the partition table

If you created or changed a DOS partition, /dev/foo7, say, then use dd(1)
to zero the first 512 bytes: dd if=/dev/zero of=/dev/foo7 bs=512 count=1
(See fdisk(8).)
root@server1:~#
Sau đó, xóa bỏ tất cả những gì sót lại từ quá trình cài đặt RAID array từ
/dev/sdb …:
mdadm zero-superblock /dev/sdb1
mdadm zero-superblock /dev/sdb5
và thêm thành phần sau vào RAID array:
mdadm -a /dev/md0 /dev/sdb1
mdadm -a /dev/md1 /dev/sdb5
Tiếp đến, kiểm tra:
cat /proc/mdstat

root@server1:~# cat /proc/mdstat
Personalities : [linear] [multipath] [raid0] [raid1] [raid6] [raid5]
[raid4] [raid10]
md0 : active raid1 sdb1[1] sda1[0]
248768 blocks [2/2] [UU]

md1 : active raid1 sdb5[2] sda5[0]
4990912 blocks [2/1] [U_]
[========> ] recovery = 42.1% (2101760/4990912)
finish=0.5min speed=87573K/sec

unused devices: <none>
root@server1:~#


Wait until the synchronization has finished:

root@server1:~# cat /proc/mdstat
Personalities : [linear] [multipath] [raid0] [raid1] [raid6] [raid5]
[raid4] [raid10]
md0 : active raid1 sdb1[1] sda1[0]
248768 blocks [2/2] [UU]

md1 : active raid1 sdb5[1] sda5[0]
4990912 blocks [2/2] [UU]

unused devices: <none>
root@server1:~#
Sau cùng, tiến hành cài đặt bootloader trên cả 2 ổ cứng:
grub-install /dev/sda
grub-install /dev/sdb
Vậy là bạn đã hoàn thành toàn bộ quá trình. Giờ đây, bất cứ ổ nào lỗi
hoặc có vấn đề, hệ thống sẽ khởi động từ ổ còn lại 1 cách bình thường.
Chúc các bạn thành công!

×