virt-v2v工具自動遷移vmware遷移至kvm
virt-v2v工具自動遷移vmware遷移至kvm
如果虛機是ESXi種的虛機,那么我們可以使用virt-v2v的工具直接進行自動遷移。
virt-v2v工具可以將其他hypervisor平臺上的虛擬機遷移到KVM上。
它可以讀取Xen,Hyper-v,VMware平臺上的虛擬機,將它們遷移到由libvirt管理的KVM,openstack或者RHEV環境中。
本節只針對ESCi上如何將虛機遷移到KVM中,往openstack和RHEV上遷移只需要轉換鏡像和導入即可不做贅述。
KVM存儲池配置過程
mkdir -p /data/vmfs
virsh pool-define-as vmdisk --type dir --target /data/vmfs
virsh pool-build vmdisk
virsh pool-autostart vmdisk
virsh pool-start vmdisk
創建ESXi認證文件
(本步驟不是必須步驟,如果不做配置的話則在使用virt-v2v的時候需要稍微改變命令)
vim /root/.netrc
machine YourESXiServerIPAddress login root password YourESXiServerIPAddress
chmod 0600 ~/.netrc
[root@amckvm2 ~]# cat /root/.netrc
machine 192.168.24.13 login root password password 192.168.24.13
[root@amckvm2 ~]#
開始遷移
開始遷移前先測試看是否能夠連接上ESXi主機
virsh -c esx://192.168.24.13/?no_verify=1 list --all
如果能夠看到運行在這個ESXi上的主機說明連接沒有問題。
[root@amckvm2 ~]# virsh -c esx://192.168.24.13/?no_verify=1 list --all
Enter username for 192.168.24.13 [root]:
Enter root's password for 192.168.24.13:
Id Name State
----------------------------------------------------
1 Vcenter_192.168.24.100 running
8 amcctrix1_192.168.24.103 running
9 amcctrix2_192.168.24.104 running
10 amczhtest_192.168.24.105 running
11 amcjrjh_192.168.24.106 running
13 windowsclustertest_192.168.24.108 running
- rhel6.5_db_model_192.168.24.231 shut off
- windows2008_model shut off
開始遷移
virt-v2v -ic esx://192.168.24.13/?no_verify=1 -os vmdisk -of qcow2 -b br0 rhel6.5_db_model_192.168.24.231
注:
1.如果遇到了類似于“ Peer certificate cannot be authenticated with given CA certificates”這一類的錯誤通過在url后面設置no_verify=1 參數來忽略證書檢查。
2.整個url的組成由user@esxi組成。如果在3.2沒有創建認證文件的話這里需要將命令改成如下
virt-v2v -ic esx://root@192.168.24.13/no_verify=1 -os vmdisk -of qcow2 -b br0 rhel6.5_db_model_192.168.24.231
3.如果用戶名使用的是域賬戶(domain\name)或者虛機名中包含有反斜線,則反斜線需要轉碼特殊標示,使用“%5c”代替“\”
4.-os表示指定到KVM中的哪個存儲池,-of表示遷移轉出的虛機磁盤格式,我這里指定的事qcow2,-b表示指定KVM中的虛擬網橋。
輸出結果如下
[root@amckvm2 ~]# virt-v2v -ic esx://192.168.24.13/?no_verify=1 -os vmdisk -of qcow2 -b br0 rhel6.5_db_model_192.168.24.231
rhel6.5_db_model_rhel6.5_db_model: 100% [==========================================================]D 1h32m16s
virt-v2v: rhel6.5_db_model_192.168.24.231 configured with virtio drivers
virt-v2v: inner-db configured without virtio drivers.
查看轉換出來的xml配置文件
[root@amckvm2 qemu]# pwd
/etc/libvirt/qemu
[root@amckvm2 qemu]# cat rhel6.5_db_model_192.168.24.231.xml
<!--
WARNING: THIS IS AN AUTO-GENERATED FILE. CHANGES TO IT ARE LIKELY TO BE
OVERWRITTEN AND LOST. Changes to this xml configuration should be made using:
virsh edit rhel6.5_db_model_192.168.24.231
or other application using the libvirt API.
-->
<domain type='kvm'>
<name>rhel6.5_db_model_192.168.24.231</name>
<uuid>c97c0167-fde4-e309-e477-4e5592e8507e</uuid>
<memory unit='KiB'>8388608</memory>
<currentMemory unit='KiB'>8388608</currentMemory>
<vcpu placement='static'>8</vcpu>
<os>
<type arch='x86_64' machine='rhel6.5.0'>hvm</type>
<boot dev='hd'/>
</os>
<features>
<acpi/>
<apic/>
</features>
<clock offset='utc'/>
<on_poweroff>destroy</on_poweroff>
<on_reboot>restart</on_reboot>
<on_crash>restart</on_crash>
<devices>
<emulator>/usr/libexec/qemu-kvm</emulator>
<disk type='file' device='disk'>
<driver name='qemu' type='qcow2' cache='none'/>
<source file='/home/data/vmfs/rhel6.5_db_model_rhel6.5_db_model'/>
<target dev='vda' bus='virtio'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0'/>
</disk>
<controller type='usb' index='0'>
<address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x2'/>
</controller>
<interface type='bridge'>
<mac address='00:50:56:ab:3f:15'/>
<source bridge='br0'/>
<model type='virtio'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x03' 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'/>
<graphics type='vnc' port='-1' autoport='yes'/>
<video>
<model type='cirrus' 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='0x05' function='0x0'/>
</memballoon>
</devices>
</domain>
[root@amckvm2 qemu]#