需求背景
需要将就主机上的jumpserver迁移到新主机上
而jumpserver是运行在一个KVM虚拟机中
也没有当时的部署文档,完全不知道老旧的jumpserver是如何运行启动的
所以这里的思路是直接迁移虚拟机
而现在已经有了VMWare ESXi平台可用
具体实施
参考文档 https://www.cnblogs.com/lixinliang/p/16288254.html
查看虚拟机
原宿主机上操作
virsh list --all
Id Name State
----------------------------------------------------
1 jumpserver running
查看虚拟机详细信息
原宿主机上操作
virsh dumpxml jumpserver
<domain type='kvm' id='1'>
<name>jumpserver</name>
<uuid>0aaf8e3d-fc65-4d4d-89ea-e3f08ab2a3e4</uuid>
<memory unit='KiB'>4194304</memory>
<currentMemory unit='KiB'>4194304</currentMemory>
<vcpu placement='static'>8</vcpu>
<resource>
<partition>/machine</partition>
</resource>
<os>
<type arch='x86_64' machine='pc-i440fx-xenial'>hvm</type>
<boot dev='hd'/>
</os>
<features>
<acpi/>
<apic/>
</features>
<cpu>
<topology sockets='2' cores='2' threads='2'/>
</cpu>
<clock offset='utc'>
<timer name='rtc' tickpolicy='catchup'/>
<timer name='pit' tickpolicy='delay'/>
<timer name='hpet' present='no'/>
</clock>
<on_poweroff>destroy</on_poweroff>
<on_reboot>restart</on_reboot>
<on_crash>restart</on_crash>
<pm>
<suspend-to-mem enabled='no'/>
<suspend-to-disk enabled='no'/>
</pm>
<devices>
<emulator>/usr/bin/kvm-spice</emulator>
<disk type='file' device='disk'>
<driver name='qemu' type='qcow2'/>
<source file='/opt/kvm/jumpserver.qcow2'/>
<backingStore/>
<target dev='vda' bus='virtio'/>
<alias name='virtio-disk0'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0'/>
</disk>
<disk type='file' device='cdrom'>
<driver name='qemu' type='raw'/>
<backingStore/>
<target dev='hda' bus='ide'/>
<readonly/>
<alias name='ide0-0-0'/>
<address type='drive' controller='0' bus='0' target='0' unit='0'/>
</disk>
<controller type='usb' index='0' model='ich9-ehci1'>
<alias name='usb'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x7'/>
</controller>
<controller type='usb' index='0' model='ich9-uhci1'>
<alias name='usb'/>
<master startport='0'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x0' multifunction='on'/>
</controller>
<controller type='usb' index='0' model='ich9-uhci2'>
<alias name='usb'/>
<master startport='2'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x1'/>
</controller>
<controller type='usb' index='0' model='ich9-uhci3'>
<alias name='usb'/>
<master startport='4'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x2'/>
</controller>
<controller type='pci' index='0' model='pci-root'>
<alias name='pci.0'/>
</controller>
<controller type='ide' index='0'>
<alias name='ide'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x1'/>
</controller>
<interface type='bridge'>
<mac address='11:11:11:11:71:11'/>
<source bridge='br0'/>
<target dev='vnet0'/>
<model type='virtio'/>
<alias name='net0'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
</interface>
<serial type='pty'>
<source path='/dev/pts/2'/>
<target port='0'/>
<alias name='serial0'/>
</serial>
<console type='pty' tty='/dev/pts/2'>
<source path='/dev/pts/2'/>
<target type='serial' port='0'/>
<alias name='serial0'/>
</console>
<input type='mouse' bus='ps2'/>
<input type='keyboard' bus='ps2'/>
<graphics type='vnc' port='5900' autoport='yes' listen='0.0.0.0'>
<listen type='address' address='0.0.0.0'/>
</graphics>
<video>
<model type='cirrus' vram='16384' heads='1'/>
<alias name='video0'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/>
</video>
<memballoon model='virtio'>
<alias name='balloon0'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x06' function='0x0'/>
</memballoon>
</devices>
<seclabel type='dynamic' model='apparmor' relabel='yes'>
<label>libvirt-0aaf8e3d-fc65-4d4d-89ea-11111111111</label>
<imagelabel>libvirt-0aaf8e3d-fc65-4d4d-89ea-1111111111111111</imagelabel>
</seclabel>
</domain>
需要关注的部分
磁盘部分
<disk type='file' device='disk'>
<driver name='qemu' type='qcow2'/>
<source file='/opt/kvm/jumpserver.qcow2'/>
<backingStore/>
<target dev='vda' bus='virtio'/>
<alias name='virtio-disk0'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0'/>
</disk>
<disk type='file' device='cdrom'>
<driver name='qemu' type='raw'/>
<backingStore/>
<target dev='hda' bus='ide'/>
<readonly/>
<alias name='ide0-0-0'/>
<address type='drive' controller='0' bus='0' target='0' unit='0'/>
</disk>
可以看到磁盘的镜像文件路径为/opt/kvm/jumpserver.qcow2
另外需要关注
cpu和内存
<memory unit='KiB'>4194304</memory>
<currentMemory unit='KiB'>4194304</currentMemory>
<vcpu placement='static'>8</vcpu>
创建目的虚拟机的时候需要用到
将磁盘镜像的格式qcow2转换成vmdk格式
在将KVM虚拟机镜像迁移至esxi之前需要先转换格式,将kvm虚拟机由qcow2转换成vmdk格式,为了防止镜像被拆分为2GB的小块,需要增加 compat6
的选项。
磁盘镜像路径为/opt/kvm/jumpserver.qcow2。
原宿主机上操作
cd /opt/kvm/
mkdir test
cd test/
qemu-img convert -f qcow2 /opt/kvm/jumpserver.qcow2 -O vmdk test1.vmdk -o compat6
然后将test1.vmdk
文件传到目标主机上,也就是vmware服务器上
vmware ESXI服务器开启ssh服务
将test1.vmdk文件传到vmware服务器上
vmware ESXI服务器上操作
找到存储目录的位置
ls -l /vmfs/volumes/datastore1/
cd /vmfs/volumes/datastore1/
#新建目标虚拟机的存储目录
mkdir jumpserver
cd jumpserver
pwd
/vmfs/volumes/642a7f6e-b511efbe-e346-11111111/jumpserver
原宿主机上操作
scp scp test1.vmdk 192.168.xxx.xx:/vmfs/volumes/642a7f6e-b511efbe-e346-11111111/jumpserver
磁盘镜像第二次转换
vmware ESXI服务器上操作
cd /vmfs/volumes/datastore1/jumpserver
vmkfstools -i test1.vmdk -d thin jumpserver-v1.vmdk
Destination disk format: VMFS thin-provisioned
Cloning disk 'jumpserver-v1.vmdk'...
Clone: 100% done.
此时的磁盘镜像就已经可以挂载到ESXI上进行正常使用了
新建目标虚拟机
vmware ESXI的web平台上操作
注意关闭ssh服务
新建虚拟机
按照之前查看的配置,cpu和内存尽量保证和之前的一致,然后删除硬盘
挂载之前转换之后的镜像文件
然后就可以正常开机
此时就完成了虚拟机的迁移
标签:kvm,ESXi,虚拟机,KVM,jumpserver,vmdk,qcow2,vmware From: https://www.cnblogs.com/guangdelw/p/17822164.html