Jar*_*red 23 linux lvm kvm-virtualization
我不太确定如何表达这个问题(因此标题很糟糕),所以让我提供一个我正在尝试做的事情的例子。
在我的(旧)Xen 主机上,我能够直接向每个来宾提供 LVM 文件系统。这些文件系统实际上是在主机上创建和格式化的,并直接通过。例如,对于我的一台主机使用单独的 tmp 和交换分区,我这样定义存储:
磁盘 = [
'phy:/dev/vg1/guest1-swap,sda1,w',
'phy:/dev/vg1/guest1-disk,sda2,w',
'phy:/dev/vg1/guest1-tmp,sda3 ,w',
]
因此,guest1-swap 被格式化为交换分区,guest1-disk 和 guest1-tmp 被格式化为 ext4,从来宾的角度来看,它只是将它们视为 /dev/sda 下的三个格式化分区。
(这听起来可能需要做很多工作,但是有一些配置脚本,例如很棒的xen-tools,几乎可以自动化所有内容)。
这提供了一些非常有用的功能,其中两个我对找出 KVM 特别感兴趣:
从主机操作系统挂载来宾文件系统。我可以随时对任何来宾文件系统进行只读挂载,即使是在来宾运行时也是如此。这有一个附带好处,即允许我在来宾运行时创建任何现有卷的 LVM 快照。通过这种方式,我可以在运行时从主机集中备份所有来宾。
在线卷大小调整。因为这些卷包含标准的 Linux 文件系统,所以我可以使用 lvextend 和 resize2fs 的组合来扩展我的来宾文件系统,再次在它们在线时。
我目前正在设置将替换 Xen 主机的 KVM 主机。与 Xen 设置类似,我利用 LVM 提供直接文件系统访问,但 KVM/qemu 的行为有所不同,因为它始终为来宾创建映像文件,即使在 LVM 卷上也是如此。从来宾的角度来看,它认为这是一个未分区的磁盘,由来宾应用分区标签,然后创建分区和文件系统。
从访客的角度来看这很好,但从服务器/管理的角度来看,它似乎远不如我描述的 Xen 设置灵活。我还是 KVM 的新手,所以我可能(希望)遗漏了一些东西。
当我尝试在 KVM 主机上重新实现我以前的备份解决方案时遇到了这个问题,并且当我尝试挂载来宾的文件系统之一时挂载命令被阻塞。所以,解决这个问题是我目前的担忧,但这也让我担心调整大小的事情,因为我相信这个问题也会在某个时候出现。
所以,这里是我的问题:
有没有办法让 kvm/qemu 直接使用 LVM 卷文件系统,就像我在 Xen 设置中描述的那样?如果这有所作为,我会使用 libvirt 进行管理。
如果没有,我该怎么做才能在 KVM 下获得类似的挂载/备份功能?我已经看到有关使用带有 FUSE 的 libguestfs 来执行此操作的讨论,但这真的是最佳选择吗?如果可能的话,我更愿意坚持使用本机文件系统挂载。
另外,如果没有,是否可以在 KVM 下进行在线文件系统大小调整?我已经找到了几个关于这个的讨论/方法,但答案似乎到处都是,没有明确的,也绝对没有直接的解决方案。
很抱歉这篇很长的帖子,只是想确保它清楚。如果我可以提供任何其他有用的信息,请告诉我。期待讨论。:-)
dya*_*sny 10
virt-*
工具)可以以比直接重新安装到主机的任何方式更简洁的方式提供对来宾文件系统的访问,尽管两者都是可能的。resize2fs
将在虚拟机中像在物理硬件上一样工作,唯一的问题是来宾重新检测大小变化。Tryvirt-resize
作为标准工具,但lvresize
也qemu-img
可以轻松使用(尽管在离线模式下,通常需要来宾重新启动)。我认为lvresize
withresize2fs
实际上可以在没有来宾重启的情况下工作,但我还没有尝试过
出于您列出的原因,我将 qemu-kvm+libvirt 与您所询问的配置完全相同,但另外,因为我在没有 KVM 主机的文件系统层的情况下获得了更好的性能。如果在 virt-manager 中将 VG 添加为“存储池”,则可以使用其用户友好的向导创建此类 VM。(但这些天我只是使用现有的 VM 作为模板手工编写 XML)。
这是我的一位客人的“virsh dumpxml”的消毒输出:
<domain type='kvm'>
<name>somevm</name>
<uuid>f173d3b5-704c-909e-b597-c5a823ad48c9</uuid>
<description>Windows Server 2008 R2</description>
<memory unit='KiB'>4194304</memory>
<currentMemory unit='KiB'>4194304</currentMemory>
<vcpu placement='static'>2</vcpu>
<os>
<type arch='x86_64' machine='pc-1.1'>hvm</type>
<boot dev='hd'/>
</os>
<features>
<acpi/>
<apic/>
<pae/>
</features>
<cpu mode='custom' match='exact'>
<model fallback='allow'>Nehalem</model>
<vendor>Intel</vendor>
<feature policy='require' name='tm2'/>
<feature policy='require' name='est'/>
<feature policy='require' name='monitor'/>
<feature policy='require' name='smx'/>
<feature policy='require' name='ss'/>
<feature policy='require' name='vme'/>
<feature policy='require' name='dtes64'/>
<feature policy='require' name='rdtscp'/>
<feature policy='require' name='ht'/>
<feature policy='require' name='ds'/>
<feature policy='require' name='pbe'/>
<feature policy='require' name='tm'/>
<feature policy='require' name='pdcm'/>
<feature policy='require' name='vmx'/>
<feature policy='require' name='ds_cpl'/>
<feature policy='require' name='xtpr'/>
<feature policy='require' name='acpi'/>
</cpu>
<clock offset='localtime'/>
<on_poweroff>destroy</on_poweroff>
<on_reboot>restart</on_reboot>
<on_crash>restart</on_crash>
<devices>
<emulator>/usr/bin/kvm</emulator>
<disk type='block' device='disk'>
<driver name='qemu' type='raw'/>
<source dev='/dev/vg1/somevm'/>
<target dev='hda' bus='virtio'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x06' function='0x0'/>
</disk>
<disk type='file' device='cdrom'>
<driver name='qemu' type='raw'/>
<target dev='hdc' bus='ide'/>
<readonly/>
<address type='drive' controller='0' bus='1' target='0' unit='0'/>
</disk>
<controller type='usb' index='0'>
<address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x2'/>
</controller>
<controller type='ide' index='0'>
<address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x1'/>
</controller>
<controller type='pci' index='0' model='pci-root'/>
<interface type='bridge'>
<mac address='00:00:00:00:00:00'/>
<source bridge='br0'/>
<model type='virtio'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0'/>
</interface>
<serial type='pty'>
<target port='0'/>
</serial>
<console type='pty'>
<target type='serial' port='0'/>
</console>
<input type='tablet' bus='usb'/>
<input type='mouse' bus='ps2'/>
<input type='keyboard' bus='ps2'/>
<graphics type='vnc' port='-1' autoport='yes'/>
<video>
<model type='vga' vram='9216' heads='1'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/>
</video>
<memballoon model='virtio'>
<address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
</memballoon>
</devices>
<seclabel type='none' model='none'/>
</domain>
Run Code Online (Sandbox Code Playgroud)
另一个想法(与您的问题无关,但可能会有所帮助):如果可以,请确保您使用的是“半虚拟化”网络、块、随机、时钟等驱动程序——它们比完全虚拟化的要快得多。这是上面的“model=virtio”内容。您必须将驱动程序模块加载到主机的内核中,例如 virtio_net。
这是“virsh pool-dumpxml vg1”的输出:
<pool type='logical'>
<name>vg1</name>
<uuid>9e26648e-64bc-9221-835f-140f6def0556</uuid>
<capacity unit='bytes'>3000613470208</capacity>
<allocation unit='bytes'>1824287358976</allocation>
<available unit='bytes'>1176326111232</available>
<source>
<device path='/dev/md1'/>
<name>vg1</name>
<format type='lvm2'/>
</source>
<target>
<path>/dev/vg1</path>
<permissions>
<mode>0700</mode>
</permissions>
</target>
</pool>
Run Code Online (Sandbox Code Playgroud)