LVM 镜像,数据和日志镜像在相同的 2 个设备上

LVM 镜像,数据和日志镜像在相同的 2 个设备上

我正在尝试设置只有 2 个设备的 LVM 镜像。当我为 mirrorlog 添加第三个设备或使用 corelog 时,它工作得很好。但只有 2 个设备并且--在任何地方分配LVM 几乎总是在一个设备上创建两个镜像。

情况

  • 2 x 50GB 设备 /dev/xvdf 和 /dev/xvdg
  • 我需要在 /dev/xvdf 上创建一个 40GB 的分区,该分区将在 /dev/xvdg 上进行镜像
  • 我不希望有 2 个单独的驱动器用于镜像日志,我希望镜像日志位于 /dev/xvdf 和 /dev/xvdg 上(在某些范围内)

问题

LVM 几乎总是(如果我正确理解了 lvs 命令输出)在 /dev/xvdf 上创建镜像,在 /dev/xvdg 上创建镜像日志(是的 :-(

我使用的命令

场景 1-最简单:

$ lvcreate -m 1 --mirrorlog mirrored -L40G -n test forfiter --alloc anywhere

$ lvs -a -o +devices
  LV                   VG       Attr   LSize  Origin Snap%  Move Log       Copy%  Convert Devices                                    
  test                 forfiter mwa-a- 40,00g                    test_mlog   7,09         test_mimage_0(0),test_mimage_1(0)          
  [test_mimage_0]      forfiter Iwi-ao 40,00g                                             /dev/xvdf(0)                               
  [test_mimage_1]      forfiter Iwi-ao 40,00g                                             /dev/xvdf(10240)                           
  [test_mimage_1]      forfiter Iwi-ao 40,00g                                             /dev/xvdg(2)                               
  [test_mlog]          forfiter mwa-ao  4,00m                              100,00         test_mlog_mimage_0(0),test_mlog_mimage_1(0)
  [test_mlog_mimage_0] forfiter iwi-ao  4,00m                                             /dev/xvdg(0)                               
  [test_mlog_mimage_1] forfiter iwi-ao  4,00m                                             /dev/xvdg(1)      

如您所见,test_mimage_1 部分位于 /dev/xvdf,部分位于 /dev/xvdf。xvdf 上分配了 12799 PE,xvdg 上分配了 7683 PE。

最有趣的是 LVM 也在一个设备上创建了 mlog......

场景 2-我尝试指定要使用的区数:

$ lvcreate  -m 1 --mirrorlog mirrored  -L 40G -n test forfiter /dev/xvdf:6-12700 /dev/xvdg:6-12700 /dev/xvdf:0-4 /dev/xvdg:0-4 --alloc anywhere

$ lvs -a -o +devices
  LV                   VG       Attr   LSize  Origin Snap%  Move Log       Copy%  Convert Devices                                    
  test                 forfiter mwa-a- 40,00g                    test_mlog   2,79         test_mimage_0(0),test_mimage_1(0)          
  [test_mimage_0]      forfiter Iwi-ao 40,00g                                             /dev/xvdf(6)                               
  [test_mimage_1]      forfiter Iwi-ao 40,00g                                             /dev/xvdf(10246)                           
  [test_mimage_1]      forfiter Iwi-ao 40,00g                                             /dev/xvdf(0)                               
  [test_mimage_1]      forfiter Iwi-ao 40,00g                                             /dev/xvdg(7)                               
  [test_mlog]          forfiter mwa-ao  4,00m                              100,00         test_mlog_mimage_0(0),test_mlog_mimage_1(0)
  [test_mlog_mimage_0] forfiter iwi-ao  4,00m                                             /dev/xvdg(6)                               
  [test_mlog_mimage_1] forfiter iwi-ao  4,00m                                             /dev/xvdg(0)    

没有成功:-)

我读了很多教程——作者建议使用--在任何地方分配但对我来说,结果看起来很奇怪(镜像有效,但不像我预期的那样)

我想将 raid1 从 MDADM 迁移到 LVM。

答案1

使用分区编辑器(例如partedcfdisk或 )fdisk创建分区:/dev/xvdf1/dev/xvdf2等,并将它们放入您的forfiterVG。

在这个例子中我使用/dev/mapper/loop0p1等等。

pvcreate /dev/mapper/loop1p1
  Physical volume "/dev/mapper/loop1p1" successfully created
pvcreate /dev/mapper/loop1p2
  Physical volume "/dev/mapper/loop1p2" successfully created

vgcreate forfiter /dev/mapper/loop0p1
  Volume group "forfiter" successfully created

vgextend forfiter /dev/mapper/loop1p1
  Volume group "forfiter" successfully extended
vgextend forfiter /dev/mapper/loop0p2
  Volume group "forfiter" successfully extended
vgextend forfiter /dev/mapper/loop1p2
  Volume group "forfiter" successfully extended

vgs forfiter
  VG       #PV #LV #SN Attr   VSize   VFree  
  forfiter   4   0   0 wz--n- 248.00m 248.00m

ls -l /dev/mapper/loop0p1
  lrwxrwxrwx 1 root root 8 Apr 18 08:59 /dev/mapper/loop0p1 -> ../dm-21


vgdisplay -v forfiter | tail -n mumble

  --- Physical volumes ---
  PV Name               /dev/dm-21     
  PV UUID               uFJpEH-dLFA-gJiM-cnao-cFFm-DEZG-RnNvSM
  PV Status             allocatable
  Total PE / Free PE    15 / 15

  PV Name               /dev/dm-23     
  PV UUID               1T7DIL-Xw4s-4tVy-CVQc-lKDp-aUNA-lyk8v2
  PV Status             allocatable
  Total PE / Free PE    15 / 15

  PV Name               /dev/dm-22     
  PV UUID               T0prpa-KKEO-uWUb-zQU3-cosM-uyEI-ext9F7
  PV Status             allocatable
  Total PE / Free PE    16 / 16

  PV Name               /dev/dm-24     
  PV UUID               PC2aCZ-eKdU-p8eS-SBDc-uWzY-54gG-952ndg
  PV Status             allocatable
  Total PE / Free PE    16 / 16

lvcreate -m 1 --mirrorlog mirrored -L64M -n test forfiter
  The link /dev/forfiter/test_mlog should had been created by udev but it was not found. Falling back to direct link creation.
  The link /dev/forfiter/test_mlog should have been removed by udev but it is still present. Falling back to direct link removal.
  Logical volume "test" created

lvs -a -o +devices forfiter
  LV                   VG       Attr   LSize  Origin Snap%  Move Log       Copy%  Convert Devices                                    
  test                 forfiter mwi-a- 64.00m                    test_mlog 100.00         test_mimage_0(0),test_mimage_1(0)          
  [test_mimage_0]      forfiter iwi-ao 64.00m                                             /dev/dm-22(0)                              
  [test_mimage_1]      forfiter iwi-ao 64.00m                                             /dev/dm-24(0)                              
  [test_mlog]          forfiter mwi-ao  4.00m                              100.00         test_mlog_mimage_0(0),test_mlog_mimage_1(0)
  [test_mlog_mimage_0] forfiter iwi-ao  4.00m                                             /dev/dm-21(0)                              
  [test_mlog_mimage_1] forfiter iwi-ao  4.00m                                             /dev/dm-23(0)          

答案2

如果没有创建分区,你的问题是你正在使用相同的命令"--mirrorlog mirrored and --alloc anywhere"

我在 suse 11 上遇到了同样的问题,"--mirrorlog mirrored"但我通过以下方式使用 lvm 命令解决了这个问题:

lvcreate -m 1 --mirrorlog mirrored -L40G -n test forfiter /dev/xvdb /dev/xvdc

在 redhat 或 centos 中,你可以在 lvm.conf 中找到此注释

# Set to 1 to guarantee that mirror logs will always be placed on 
# different PVs from the mirror images.  This was the default
# until version 2.02.85.
mirror_logs_require_separate_pvs = 0

有很多方法可以解决这个问题,无需创建分区。

相关内容