1. Trang chủ
  2. » Công Nghệ Thông Tin

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

40 16 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Bài viết sau sẽ hướng dẫn và giải thích với các bạn cách thiết lập, cài đặt phần mềm theo chuẩn RAID1 trên hệ thống LVM đang hoạt dộng trong nền tảng Ubuntu 10.04. Và GRUB2 bootloader sẽ được thiết lập để hệ thống không thể khởi động khi 1 trong 2 ổ cứng có vấn đề. Lưu ý sơ bộ Trong thí nghiệm này sử dụng hệ điều hành Ubuntu 10.04 và 2 ổ cứng (/dev/sda và /dev/sdb), trong đó /dev/sdb không sử dụng, /dev/sda có các phân vùng sau: /dev/sda1: phân vùng boot - ext2 /dev/sda2: là phân...

Cài đặt RAID hệ thống LVM Ubuntu 10.04 Bài viết sau hướng dẫn giải thích với bạn cách thiết lập, cài đặt phần mềm theo chuẩn RAID1 hệ thống LVM hoạt dộng tảng Ubuntu 10.04 Và GRUB2 bootloader thiết lập để hệ thống khởi động ổ cứng có vấn đề Lưu ý sơ Trong thí nghiệm sử dụng hệ điều hành Ubuntu 10.04 ổ cứng (/dev/sda /dev/sdb), /dev/sdb khơng sử dụng, /dev/sda có phân vùng sau: /dev/sda1: phân vùng boot - ext2 /dev/sda2: phân vùng extended, có chứa /dev/sda5 /dev/sda5: sử dụng cho LVM (volume group server1) có ký tự / (root) swap (swap_1) Và đến kết thúc, có kết sau: /dev/md0 (tạo từ /dev/sda1 /dev/sdb1): phân vùng /boot - ext2 /dev/md1 (tạo từ /dev/sda5 /dev/sdb5): LVM (volume group server1) có ký tự / (root) swap (volume swap_1) Còn tại: df -h root@server1:~# df -h Filesystem Size Used Avail Use% Mounted on /dev/mapper/server1-root 4.5G 809M 3.5G 19% / none 243M 176K 242M 1% /dev none 247M 247M 0% /dev/shm none 247M 36K 247M 1% /var/run none 247M 247M 0% /var/lock none 247M 247M 0% /lib/init/rw /dev/sda1 228M 17M 199M 8% /boot root@server1:~# fdisk -l 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 * 32 248832 83 Linux Partition does not end on cylinder boundary /dev/sda2 32 653 4990977 Extended Partition does not end on cylinder boundary /dev/sda5 32 653 4990976 8e Linux LVM 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 root@server1:~# pvdisplay 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 Allocated PE 1215 PV UUID bsF5F5-s2RN-ed1h-zjeb-4mAJ-aktq-kEn86r root@server1:~# vgdisplay root@server1:~# vgdisplay - Volume group VG Name server1 System ID Format lvm2 Metadata Areas Metadata Sequence No VG Access read/write VG Status resizable MAX LV Cur LV Open LV Max PV Cur PV Act PV VG Size 4.76 GiB PE Size 4.00 MiB Total PE 1218 Alloc PE / Size 1215 / 4.75 GiB Free PE / Size / 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 LV Size 4.49 GiB Current LE 1149 Segments 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 LV Size 264.00 MiB Current LE 66 Segments Allocation inherit Read ahead sectors auto - currently set to 256 Block device 251:1 root@server1:~# Cài đặt mdadm Một công cụ quan trọng để thiết lập chế độ RAID mdadm Sử dụng câu lệnh sau để cài đặt: aptitude install initramfs-tools mdadm Sau đó, tiến hành tải thêm vài module kernel khác (để tránh phải khởi động lại hệ thống): modprobe linear modprobe multipath modprobe raid0 modprobe raid1 modprobe raid5 modprobe raid6 modprobe raid10 Tiếp theo chạy câu lệnh sau: cat /proc/mdstat Và kết trả có dạng sau: root@server1:~# cat /proc/mdstat Personalities : [linear] [multipath] [raid0] [raid1] [raid6] [raid5] [raid4] [raid10] unused devices: root@server1:~# Chuẩn bị cho phân vùng /dev/sdb Để tạo RAID1 array hệ thống hoạt động sẵn, cần chuẩn bị phân vùng /dev/sdb cho RAID1, sau copy tồn nội dung /dev/sda tới phân vùng đó, cuối thêm /dev/sda tới RAID1 array Trước tiên ta copy toàn bảng phân vùng từ /dev/sda tới /dev/sdb, ổ đĩa có kết nhau: sfdisk -d /dev/sda | sfdisk force /dev/sdb Và kết trả có dạng sau: 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 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 Device Boot Start End #sectors Id System /dev/sdb1 * 2048 499711 497664 83 Linux /dev/sdb2 501758 10483711 9981954 Extended /dev/sdb3 - 0 Empty /dev/sdb4 - 0 Empty /dev/sdb5 501760 10483711 9981952 8e Linux LVM Warning: partition 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:~# Sử dụng câu lệnh sau: fdisk -l ổ cứng này: 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 * 32 248832 83 Linux Partition does not end on cylinder boundary /dev/sda2 32 653 4990977 Extended Partition does not end on cylinder boundary /dev/sda5 32 653 4990976 8e Linux LVM 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 Device Boot Start End Blocks Id System /dev/sdb1 * 32 248832 83 Linux Partition does not end on cylinder boundary /dev/sdb2 32 653 4990977 Extended Partition does not end on cylinder boundary /dev/sdb5 32 653 4990976 8e Linux LVM root@server1:~# Tiếp theo, tiến hành chuyển đổi định dạng phân vùng /dev/sdb thành Linux raid autodetect: fdisk /dev/sdb root@server1:~# fdisk /dev/sdb WARNING: DOS-compatible mode is deprecated It's strongly recommended to 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ép toàn liệu /dev/sda1 tới /dev/md0 (đã kết hợp /mnt/md0): cd /boot cp -dpRx /mnt/md0 Chuẩn bị GRUB2 điểm quan trọng không GRUB2 bootloader phải cài đặt phân vùng ổ cứng, /dev/sda /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 hoạt động bình thường, bạn thấy /dev/md0 kết trả 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 247M 0% /dev/shm none 247M 40K 247M 1% /var/run none 247M 247M 0% /var/lock none 247M 247M 0% /lib/init/rw /dev/md0 236M 23M 201M 11% /boot root@server1:~# Và kết cat /proc/mdstat 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: root@server1:~# Tượng tự, kết thu pvdisplay, vgdisplay, lvdisplay 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 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 Metadata Sequence No VG Access read/write VG Status resizable MAX LV Cur LV Open LV Max PV Cur PV Act PV VG Size 4.76 GiB PE Size 4.00 MiB Total PE 1218 Alloc PE / Size 1215 / 4.75 GiB Free PE / Size / 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 LV Size 4.49 GiB Current LE 1149 Segments 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 LV Size 264.00 MiB Current LE 66 Segments Allocation inherit Read ahead sectors auto - currently set to 256 Block device 251:1 root@server1:~# Đồng thời, thay đổi định dạng /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õ Hex code (type L to list codes): < gõ fd Changed system type of partition 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 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: root@server1:~# Sau thay đổi file /etc/mdadm/mdadm.conf sau: cp /etc/mdadm/mdadm.conf_orig /etc/mdadm/mdadm.conf mdadm examine scan >> /etc/mdadm/mdadm.conf File /etc/mdadm/mdadm.conf trông giống 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 # 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ờ, cần xóa file /etc/grub.d/09_swraid1_setup …: rm -f /etc/grub.d/09_swraid1_setup 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 đề xảy có nghĩa bạn hồn tất q trình thiết lập cài đặt phần mềm theo chuẩn RAID1 hệ thống LVM Kiểm tra toàn Bây giờ, giả sử có ổ cứng bị lỗi Nhưng thực khơng có vấn đề xảy bạn lựa chọn /dev/sda /dev/sdb trường hợp Trong ví dụ này, phân vùng /dev/sdb bị lỗi Để mô lỗi này, bạn tắt bỏ hệ thống 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 khởi động hệ thống: cat /proc/mdstat bạn 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: root@server1:~# Kết của: fdisk -l 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 * 32 248832 fd Linux raid autodetect Partition does not end on cylinder boundary /dev/sda2 32 653 4990977 Extended Partition 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 heads, sectors/track, 1247728 cylinders Units = cylinders of * 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 heads, sectors/track, 62192 cylinders Units = cylinders of * 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, chép định dạng phân vùng /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 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 Device Boot Start End #sectors Id System /dev/sdb1 * 2048 499711 497664 fd Linux raid autodetect /dev/sdb2 501758 10483711 9981954 Extended /dev/sdb3 - 0 Empty /dev/sdb4 - 0 Empty /dev/sdb5 501760 10483711 9981952 fd Linux raid autodetect Warning: partition 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 sót lại từ q trình cài đặt RAID array từ /dev/sdb …: mdadm zero-superblock /dev/sdb1 mdadm zero-superblock /dev/sdb5 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: 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: root@server1:~# Sau cùng, tiến hành cài đặt bootloader ổ cứng: grub-install /dev/sda grub-install /dev/sdb Vậy bạn hồn thành tồn q trình Giờ đây, ổ lỗi có vấn đề, hệ thống khởi động từ ổ lại cách bình thường Chúc bạn thành cơng! ... [multipath] [raid0 ] [raid1 ] [raid6 ] [raid5 ] [raid4 ] [raid1 0] md1 : active raid1 sdb5 [1] 4990 912 blocks [2 /1] [_U] md0 : active raid1 sdb1 [1] 248768 blocks [2 /1] [_U] unused devices: root@server1:~#... [multipath] [raid0 ] [raid1 ] [raid6 ] [raid5 ] [raid4 ] [raid1 0] md0 : active raid1 sda1[0] 248768 blocks [2 /1] [U_] md1 : active raid1 sda5[0] 4990 912 blocks [2 /1] [U_] unused devices: root@server1:~#... [linear] [multipath] [raid0 ] [raid1 ] [raid6 ] [raid5 ] [raid4 ] [raid1 0] md0 : active raid1 sdb1 [1] sda1[0] 248768 blocks [2/2] [UU] md1 : active raid1 sdb5[2] sda5[0] 4990 912 blocks [2 /1] [U_] [========>

Ngày đăng: 11/05/2021, 08:20

Xem thêm:

TỪ KHÓA LIÊN QUAN

w