RAID和LVM综合使用!

由于 LVM 可以弹性调整 filesystem 的大小,但是缺点是可能没有加速与硬件备份(与快照不同)的功能。 而磁盘阵列则具有性能与备份的功能,但是无法提供类似 LVM 的优点。在此情境中,我们想利用『在 RAID 上面建置 LVM』的功能,以达到两者兼顾的能力。

目标:测试在 RAID 磁盘上面架构 LVM 系统;
需求:需要具有磁盘管理的能力,包括 RAID 与 LVM;
那要如何处理呢?如下的流程一个步骤一个步骤的实施看看吧:

1、复原系统时,你必项要:
 利用 umount 先卸除之前挂载的文件系统;
 修改 /etc/fstab 里面的数据,让开机不会自动挂载;

 利用 fdisk 将该分割槽初除。

最终你的系统应该会只剩下如下的模样:(/dev/sd{b,c,d,e,f}都是已经用mkds格式化为ext3)

  1. Disk /dev/sdb: 8589 MB, 8589934592 bytes  
  2. 255 heads, 63 sectors/track, 1044 cylinders  
  3. Units = cylinders of 16065 * 512 = 8225280 bytes  
  4.   
  5. Disk /dev/sdb doesn't contain a valid partition table  
  6.   
  7. Disk /dev/sdc: 8589 MB, 8589934592 bytes  
  8. 255 heads, 63 sectors/track, 1044 cylinders  
  9. Units = cylinders of 16065 * 512 = 8225280 bytes  
  10.   
  11. Disk /dev/sdc doesn't contain a valid partition table  
  12.   
  13. Disk /dev/sdd: 8589 MB, 8589934592 bytes  
  14. 255 heads, 63 sectors/track, 1044 cylinders  
  15. Units = cylinders of 16065 * 512 = 8225280 bytes  
  16.   
  17. Disk /dev/sdd doesn't contain a valid partition table  
  18.   
  19. Disk /dev/sde: 8589 MB, 8589934592 bytes  
  20. 255 heads, 63 sectors/track, 1044 cylinders  
  21. Units = cylinders of 16065 * 512 = 8225280 bytes  
  22.   
  23. Disk /dev/sde doesn't contain a valid partition table  
  24.   
  25. Disk /dev/sdf: 8589 MB, 8589934592 bytes  
  26. 255 heads, 63 sectors/track, 1044 cylinders  
  27. Units = cylinders of 16065 * 512 = 8225280 bytes  
  28.   
  29. Disk /dev/sdf doesn't contain a valid partition table  

2、建立 RAID ,假设我们利用五个(/dev/sd{b,c,d,e,f}) 8GB 的分割槽建立 RAID-5 ,且具有一个 spare disk
  1. [root@linux ~]# mdadm --create --auto=yes /dev/md0 --level=5 --raid-devices=4 --spare-devices=1 /dev/sd{b,c,d,e,f}  
  2. mdadm: /dev/sdb appears to contain an ext2fs file system  
  3.     size=8388608K  mtime=Thu Jan  1 08:00:00 1970  
  4. mdadm: /dev/sdc appears to contain an ext2fs file system  
  5.     size=8388608K  mtime=Thu Jan  1 08:00:00 1970  
  6. mdadm: /dev/sdd appears to contain an ext2fs file system  
  7.     size=8388608K  mtime=Thu Jan  1 08:00:00 1970  
  8. mdadm: /dev/sde appears to contain an ext2fs file system  
  9.     size=8388608K  mtime=Thu Jan  1 08:00:00 1970  
  10. mdadm: /dev/sdf appears to contain an ext2fs file system  
  11.     size=8388608K  mtime=Thu Jan  1 08:00:00 1970  
  12. Continue creating array? y  
  13. mdadm: array /dev/md0 started.  

3、开始处理 LVM ,现在我们假设所有的参数都使用默认值,包括 PE ,然后 VG 名为 raidvg ,LV 名为 raidlv ,底下为基本的流程:
  1. [root@linux ~]# pvcreate /dev/md0   
  2.   Physical volume "/dev/md0" successfully created  
  3. [root@linux ~]# vgcreate raidvg /dev/md0   
  4.   /dev/cdrom: open failed: 只读文件系统  
  5.   Attempt to close device '/dev/cdrom' which is not open.  
  6.   /dev/cdrom: open failed: 只读文件系统  
  7.   Attempt to close device '/dev/cdrom' which is not open.  
  8.   Volume group "raidvg" successfully created  
  9. [root@linux ~]# lvcreate -l 6143 -n raidlv raidvg  
  10.   Logical volume "raidlv" created  
  11. [root@linux ~]# lvdisplay  
  12.   --- Logical volume ---  
  13.   LV Name                /dev/raidvg/raidlv  
  14.   VG Name                raidvg  
  15.   LV UUID                rBySS0-JxZ6-ANYe-Vp8G-xlUd-Rz1x-G6NjnT  
  16.   LV Write Access        read/write  
  17.   LV Status              available  
  18.   # open                 0  
  19.   LV Size                24.00 GB  
  20.   Current LE             6143  
  21.   Segments               1  
  22.   Allocation             inherit  
  23.   Read ahead sectors     auto  
  24.   - currently set to     768  
  25.   Block device           253:0  

4、挂载
  1. [root@linux ~]# mkdir /mnt/raidlvm  
  2. [root@linux ~]# mkfs -t ext3 /dev/raidvg/raidlv   
  3. mke2fs 1.39 (29-May-2006)  
  4. Filesystem label=  
  5. OS type: Linux  
  6. Block size=4096 (log=2)  
  7. Fragment size=4096 (log=2)  
  8. 3145728 inodes, 6290432 blocks  
  9. 314521 blocks (5.00%) reserved for the super user  
  10. First data block=0  
  11. Maximum filesystem blocks=0  
  12. 192 block groups  
  13. 32768 blocks per group, 32768 fragments per group  
  14. 16384 inodes per group  
  15. Superblock backups stored on blocks:   
  16.         32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,   
  17.         4096000  
  18.   
  19. Writing inode tables: done                              
  20. Creating journal (32768 blocks): done  
  21. Writing superblocks and filesystem accounting information: done  
  22.   
  23. This filesystem will be automatically checked every 21 mounts or  
  24. 180 days, whichever comes first.  Use tune2fs -c or -i to override.  
  25. [root@linux ~]# mount /dev/raidvg/raidlv /mnt/raidlvm/  

5、开机自动挂载

  1. [root@linux raidlvm]# mdadm --detail /dev/md0 | grep UUID  
  2.            UUID : 99de722a:bfd56556:7b3978e1:3bf3f4f9  
  3. [root@linux raidlvm]# cat /etc/mdadm.conf   
  4. ARRAY /dev/md0 UUID=99de722a:bfd56556:7b3978e1:3bf3f4f9  
  5. [root@linux raidlvm]# cat /etc/fstab | grep /mnt/raidlvm  
  6. /dev/raidvg/raidlv          /mnt/raidlvm            ext3    defaults        1 2  
6、检查
  1. [root@linux raidlvm]# mdadm --detail /dev/md0   
  2. /dev/md0:  
  3.         Version : 0.90  
  4.   Creation Time : Fri Feb 17 22:26:44 2012  
  5.      Raid Level : raid5  
  6.      Array Size : 25165632 (24.00 GiB 25.77 GB)  
  7.   Used Dev Size : 8388544 (8.00 GiB 8.59 GB)  
  8.    Raid Devices : 4  
  9.   Total Devices : 5  
  10. Preferred Minor : 0  
  11.     Persistence : Superblock is persistent  
  12.   
  13.     Update Time : Fri Feb 17 22:39:11 2012  
  14.           State : clean  
  15.  Active Devices : 4  
  16. Working Devices : 5  
  17.  Failed Devices : 0  
  18.   Spare Devices : 1  
  19.   
  20.          Layout : left-symmetric  
  21.      Chunk Size : 64K  
  22.   
  23.            UUID : 99de722a:bfd56556:7b3978e1:3bf3f4f9  
  24.          Events : 0.2  
  25.   
  26.     Number   Major   Minor   RaidDevice State  
  27.        0       8       16        0      active sync   /dev/sdb  
  28.        1       8       32        1      active sync   /dev/sdc  
  29.        2       8       48        2      active sync   /dev/sdd  
  30.        3       8       64        3      active sync   /dev/sde  
  31.   
  32.        4       8       80        -      spare   /dev/sdf  
  33. [root@linux raidlvm]# cat /proc/mdstat  
  34. Personalities : [raid6] [raid5] [raid4]   
  35. md0 : active raid5 sde[3] sdf[4](S) sdd[2] sdc[1] sdb[0]  
  36.       25165632 blocks level 5, 64k chunk, algorithm 2 [4/4] [UUUU]  
  37.         
  38. unused devices: <none>  
  39. [root@linux raidlvm]# pvscan  
  40.   /dev/cdrom: open failed: 只读文件系统  
  41.   Attempt to close device '/dev/cdrom' which is not open.  
  42.   PV /dev/md0   VG raidvg   lvm2 [24.00 GB / 0    free]  
  43.   Total: 1 [24.00 GB] / in use: 1 [24.00 GB] / in no VG: 0 [0   ]  
  44. [root@linux raidlvm]# pvdisplay  
  45.   --- Physical volume ---  
  46.   PV Name               /dev/md0  
  47.   VG Name               raidvg  
  48.   PV Size               24.00 GB / not usable 3.81 MB  
  49.   Allocatable           yes (but full)  
  50.   PE Size (KByte)       4096  
  51.   Total PE              6143  
  52.   Free PE               0  
  53.   Allocated PE          6143  
  54.   PV UUID               KgwVH9-HwTG-q4it-z0Ps-ACac-Si1y-8RxTkx  
  55.      
  56. [root@linux raidlvm]# vgscan  
  57.   Reading all physical volumes.  This may take a while...  
  58.   /dev/cdrom: open failed: 只读文件系统  
  59.   Attempt to close device '/dev/cdrom' which is not open.  
  60.   Found volume group "raidvg" using metadata type lvm2  
  61. [root@linux raidlvm]# vgdisplay  
  62.   --- Volume group ---  
  63.   VG Name               raidvg  
  64.   System ID               
  65.   Format                lvm2  
  66.   Metadata Areas        1  
  67.   Metadata Sequence No  2  
  68.   VG Access             read/write  
  69.   VG Status             resizable  
  70.   MAX LV                0  
  71.   Cur LV                1  
  72.   Open LV               1  
  73.   Max PV                0  
  74.   Cur PV                1  
  75.   Act PV                1  
  76.   VG Size               24.00 GB  
  77.   PE Size               4.00 MB  
  78.   Total PE              6143  
  79.   Alloc PE / Size       6143 / 24.00 GB  
  80.   Free  PE / Size       0 / 0     
  81.   VG UUID               zlM0TJ-fjR0-b2kO-rCpO-D6L9-zw0m-W3SVzp  
  82.      
  83. [root@linux raidlvm]# lvscan  
  84.   ACTIVE            '/dev/raidvg/raidlv' [24.00 GB] inherit  
  85. [root@linux raidlvm]# lvdisplay  
  86.   --- Logical volume ---  
  87.   LV Name                /dev/raidvg/raidlv  
  88.   VG Name                raidvg  
  89.   LV UUID                rBySS0-JxZ6-ANYe-Vp8G-xlUd-Rz1x-G6NjnT  
  90.   LV Write Access        read/write  
  91.   LV Status              available  
  92.   # open                 1  
  93.   LV Size                24.00 GB  
  94.   Current LE             6143  
  95.   Segments               1  
  96.   Allocation             inherit  
  97.   Read ahead sectors     auto  
  98.   - currently set to     768  
  99.   Block device           253:0  
  100. [root@linux ~]# df  
  101. 文件系统               1K-块        已用     可用 已用% 挂载点  
  102. /dev/sda3              5991232   2662984   3019000  47% /  
  103. /dev/sda1               101086     11373     84494  12% /boot  
  104. tmpfs                   517548         0    517548   0% /dev/shm  
  105. /dev/mapper/raidvg-raidlv  
  106.                       24766844    176204  23332556   1% /mnt/raidlvm  
  107. [root@linux ~]# cd /mnt/raidlvm/  
  108. [root@linux raidlvm]# ll  
  109. 总计 20  
  110. drwx------ 2 root root 16384 02-17 22:37 lost+found  
  111. -rw-r--r-- 1 root root     6 02-17 22:38 tt  
  112. [root@linux raidlvm]# cat tt   
  113. aaaaa 
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值