FT越来越爱用软Raid,因为实在廉价性能与硬Raid差别不大。而且最重要的功能是监控磁盘的状况。呵呵~~ 这篇文章介绍如何在运营中的CentOS 5.3系统上安装上软Raid。 马上开始: 看看我们的磁盘结构 /dev/sda1: /boot partition, ext3; /dev/sda2: swap; /dev/sda3: / partition, ext3 我想把以上的磁盘转换为 md0、md1、md2 /dev/md0 (made up of /dev/sda1 and /dev/sdb1): /boot partition, ext3; /dev/md1 (made up of /dev/sda2 and /dev/sdb2): swap; /dev/md2 (made up of /dev/sda3 and /dev/sdb3): / partition, ext3 # df -h Filesystem Size Used Avail Use% Mounted on /dev/sda3 9.1G 1.1G 7.6G 12% / /dev/sda1 190M 12M 169M 7% /boot tmpfs 252M 0 252M 0% /dev/shm # fdisk -l Disk /dev/sda: 10.7 GB, 10737418240 bytes 255 heads, 63 sectors/track, 1305 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Device Boot Start End Blocks Id System /dev/sda1 * 1 25 200781 83 Linux /dev/sda2 26 90 522112+ 82 Linux swap / Solaris /dev/sda3 91 1305 9759487+ 83 Linux Disk /dev/sdb: 10.7 GB, 10737418240 bytes 255 heads, 63 sectors/track, 1305 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Disk /dev/sdb doesn't contain a valid partition table 安装需要用到的软件 #yum install mkinitrd mdadm 把模组到核心挂载 #modprobe linear #modprobe multipath #modprobe raid0 #modprobe raid1 #modprobe raid5 #modprobe raid6 #modprobe raid10 前期的功夫都准备好了!现在正式开始 1. 把磁盘挂上,分区。 #sfdisk -d /dev/sda | sfdisk /dev/sdb 把/dev/sda 的分区附到 /dev/sdb上 # sfdisk -d /dev/sda | sfdisk /dev/sdb Checking that no-one is using this disk right now ... OK Disk /dev/sdb: 1305 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 * 63 401624 401562 83 Linux /dev/sdb2 401625 1445849 1044225 82 Linux swap / Solaris /dev/sdb3 1445850 20964824 19518975 83 Linux /dev/sdb4 0 - 0 0 Empty 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).) 然后把/dev/sdb 3个分区改变id 为 fd [raid 设备] #fdisk /dev/sdb 按t 然后 1 然后 fd 按t 然后 2 然后 fd 按t 然后 fd 最后w 为安全起见,把/dev/sdb 上的raid设备初次化 #mdadm --zero-superblock /dev/sdb1 #mdadm --zero-superblock /dev/sdb2 #mdadm --zero-superblock /dev/sdb3 2 建立software Raid 1 #mdadm --create /dev/md0 --level=1 --raid-disks=2 missing /dev/sdb1 #mdadm --create /dev/md1 --level=1 --raid-disks=2 missing /dev/sdb2 #mdadm --create /dev/md2 --level=1 --raid-disks=2 missing /dev/sdb3 格式化 #mkfs.ext3 /dev/md0 #mkswap /dev/md1 #mkfs.ext3 /dev/md2 写入/etc/mdadm.conf #mdadm --examine --scan > /etc/mdadm.conf 建立临时目录 #mkdir /mnt/md0 #mkdir /mnt/md2 挂载 #mount /dev/md0 /mnt/md0 #mount /dev/md2 /mnt/md2 修改 /etc/fstab #vim /etc/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 开机时自动把 / 分区 挂载到 /dev/md2 开机时自动把 /boot 分区 挂载到 /dev/md0 修改/etc/mtab #vim /etc/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/md2 开机时自动把 /boot 分区 挂载到 /dev/md0 修改/boot/grub/menu.lst [...] #加入#title CentOS (2.6.18-128.el5) #加入# root (hd1,0) #加入# kernel /vmlinuz-2.6.18-128.el5 ro root=/dev/md2 #加入# initrd /initrd-2.6.18-128.el5.img #原来#title CentOS (2.6.18-128.el5) #原来# root (hd0,0) #原来# kernel /vmlinuz-2.6.18-128.el5 ro root=LABEL=/ #原来# initrd /initrd-2.6.18-128.el5.img 告诉grub开启服务器时root的位置. 调整ramdisk 现在的分区状况 #mv /boot/initrd-`uname -r`.img /boot/initrd-`uname -r`.img_orig #mkinitrd /boot/initrd-`uname -r`.img `uname -r` 复制数据 #cp -dpRx / /mnt/md2 #cp -dpRx /boot/ /mnt/md0 3. 告诉GRUB boot sector 位置 #grub root (hd0,0) setup (hd0) root (hd1,0) setup (hd1) 完成:重启动 #reboot 4.把/dev/sda 加入到software Raid 1 中 #fdisk /dev/sda 按t 然后 1 然后 fd 按t 然后 2 然后 fd 按t 然后 fd 最后w 加入到Software Raid 1 #mdadm --add /dev/md0 /dev/sda1 #mdadm --add /dev/md1 /dev/sda2 #mdadm --add /dev/md2 /dev/sda3 查看重建Software Raid 1的情况 # cat /proc/mdstat Personalities : [raid1] md0 : active raid1 sda1[0] sdb1[1] 200704 blocks [2/2] [UU] md1 : active raid1 sda2[0] sdb2[1] 522048 blocks [2/2] [UU] md2 : active raid1 sda3[2] sdb3[1] 9759360 blocks [2/1] [_U] [====>................] recovery = 22.8% (2232576/9759360) finish=2.4min speed=50816K/sec unused devices: <none> 同步完成后把Software Raid 1 状态写入/etc/mdadm.conf #mdadm --examine --scan > /etc/mdadm.conf 5.更好地修改/boot/grub/menu.list title CentOS (2.6.18-128.el5) root (hd1,0) kernel /vmlinuz-2.6.18-128.el5 ro root=/dev/md2 initrd /initrd-2.6.18-128.el5.img title CentOS (2.6.18-128.el5) root (hd0,0) kernel /vmlinuz-2.6.18-128.el5 ro root=/dev/md2 initrd /initrd-2.6.18-128.el5.img 告诉GRUB两块磁盘都可以随时启动.(责任编辑:IT) |