第一種方法:直接遷移node
一、開啓ESXI上的ssh服務和ESXI Shell服務。ubuntu
ESXI5.5以下:app
ESXI6.7以下:dom
二、配置KVM到ESXI免密認證ssh
[root@SIT-KVM01 ~]# ssh-keygen Generating public/private rsa key pair. Enter file in which to save the key (/root/.ssh/id_rsa): Created directory '/root/.ssh'. Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /root/.ssh/id_rsa. Your public key has been saved in /root/.ssh/id_rsa.pub. The key fingerprint is: SHA256:Cd2XpDjQiR0Nz1eGRDcJhQFm6hyapIXLQ3BeAzRectk root@SIT-KVM01 The key's randomart image is: +---[RSA 2048]----+ | ...o=++. | | = Bo+EO.oo=.. | | = + * = + | | o = * + o | | = o S | | . | | | | | | | +----[SHA256]-----+ [root@SIT-KVM01 ~]# ssh-copy-id -i .ssh/id_rsa.pub 10.xxx.128.145 /usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: ".ssh/id_rsa.pub" The authenticity of host '10.xxx.128.145 (10.xxx.128.145)' can't be established. RSA key fingerprint is SHA256:DUhcdrc8dWdwMVv6RwOQs9AVjonPqIFwD7kumhURcjQ. RSA key fingerprint is MD5:86:2f:b2:02:e4:75:6b:13:3e:ec:32:48:c9:01:85:d3. Are you sure you want to continue connecting (yes/no)? yes /usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed /usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys Password: Number of key(s) added: 1 Now try logging into the machine, with: "ssh '10.xxx.128.145'" and check to make sure that only the key(s) you wanted were added. [root@SIT-KVM01 ~]#
三、調整ESXI中上一步添加的KEY認證文件ide
[root@SIT-KVM01 ~]# ssh 10.xxx.128.145 Password: The time and date of this login have been sent to the system logs. VMware offers supported, powerful system administration tools. Please see www.vmware.com/go/sysadmintools for details. The ESXi Shell can be disabled by an administrative user. See the vSphere Security documentation for more information. ~ # cd /etc/ssh/ /etc/ssh # ls keys-root moduli ssh_host_dsa_key ssh_host_dsa_key.pub ssh_host_rsa_key ssh_host_rsa_key.pub sshd_config /etc/ssh # cd keys-root/ /etc/ssh/keys-root # ls authorized_keys /etc/ssh/keys-root # cd ~ # cat .ssh/authorized_keys >> /etc/ssh/keys-root/authorized_keys ~ # exit Connection to 10.xxx.128.145 closed. [root@SIT-KVM01 ~]# ssh 10.xxx.128.145 The time and date of this login have been sent to the system logs. VMware offers supported, powerful system administration tools. Please see www.vmware.com/go/sysadmintools for details. The ESXi Shell can be disabled by an administrative user. See the vSphere Security documentation for more information. ~ #
四、開始遷移,(注:遷移前須要將虛擬機關機,虛擬機路徑裏面不要包含空格,中文字符,不然彙報URI錯誤)。ui
[root@SIT-KVM01 ~]# eval `ssh-agent` Agent pid 30714 [root@SIT-KVM01 ~]# ssh-add .ssh/id_rsa Identity added: .ssh/id_rsa (.ssh/id_rsa) [root@SIT-KVM01 ~]# export LIBGUESTFS_BACKEND=direct [root@SIT-KVM01 vmfs]# virt-v2v -i vmx -it ssh "ssh://root@10.xxx.128.145/vmfs/volumes/553503c1-37053e17-f472-a0369f6/d1search02--10.xxx.128.55/d1search02--10.xxx.128.55.vmx" -os vmfs -of qcow2 --bridge br128 [ 0.0] Opening the source -i vmx ssh://root@10.xxx.128.145/vmfs/volumes/553503c1-37053e17-f472-a0369f677064/d1searc [ 0.6] Creating an overlay to protect the source from being modified [ 1.0] Opening the overlay [ 5.6] Inspecting the overlay [ 19.4] Checking for sufficient free disk space in the guest [ 19.4] Estimating space required on target for each disk [ 19.4] Converting Red Hat Enterprise Linux Server release 6.5 (Santiago) to run on KVM virt-v2v: This guest has virtio drivers installed. [ 110.6] Mapping filesystem data to avoid copying unused and blank areas [ 112.1] Closing the overlay [ 112.2] Assigning disks to buses [ 112.2] Checking if the guest needs BIOS or UEFI to boot [ 112.2] Initializing the target -o libvirt -os vmfs [ 112.2] Copying disk 1/1 to /vmfs/d1search02--10.xxx.128.55-sda (qcow2) (100.00/100%) [2321.3] Creating output metadata Pool vmfs refreshed Domain d1search02--10.xxx.128.55 defined from /tmp/v2vlibvirt56ad9d.xml [2321.4] Finishing off [root@SIT-KVM01 ~]# virt-v2v -i vmx -it ssh "ssh://root@10.xxx.128.145/vmfs/volumes/553503c1-37053e17-f472-a0369f677064/sitdns2 --10.xxx.128.203/sitdns2 --10.xxx.128.203.vmx" -os vmfs -of qcow2 --bridge br128 [ 0.0] Opening the source -i vmx ssh://root@10.xxx.128.145/vmfs/volumes/553503c1-37053e17-f472-a0369f677064/sitdns2 --10.xxx.128.203/sitdns2 --10.xxx.128.203.vmx virt-v2v: error: remote vmx ‘ssh://root@10.xxx.128.145/vmfs/volumes/553503c1-37053e17-f472-a0369f677064/sitdns2 --10.xxx.128.203/sitdns2 --10.xxx.128.203.vmx’ could not be parsed as a URI
五、查看遷移完成的虛擬機。this
[root@SIT-KVM01 ~]# virsh list --all Id Name State ---------------------------------------------------- 1 d1test-10.xxx.128.213 running 2 d1rongyiwang-10.xxx.128.135 running 3 d1search02--10.xxx.128.55 running 4 D1openAPI--10.xxx.128.239--IBM running 5 d1search04-10.xxx.128.136 running
第二種方法:將虛擬機導出爲OVF模板,而後轉換爲KVM。spa
[root@SIT-KVM01 OVF]# virt-v2v -i ova 'sitdns2 --10.xxx.128.203' -os vmfs -of qcow2 -b br128 [ 0.0] Opening the source -i ova sitdns2 --10.xxx.128.203 [ 6.4] Creating an overlay to protect the source from being modified [ 6.5] Opening the overlay [ 10.1] Inspecting the overlay [ 21.5] Checking for sufficient free disk space in the guest [ 21.5] Estimating space required on target for each disk [ 21.5] Converting Red Hat Enterprise Linux Server release 6.5 (Santiago) to run on KVM virt-v2v: This guest has virtio drivers installed. [ 83.2] Mapping filesystem data to avoid copying unused and blank areas [ 85.5] Closing the overlay [ 85.5] Assigning disks to buses [ 85.5] Checking if the guest needs BIOS or UEFI to boot [ 85.5] Initializing the target -o libvirt -os vmfs [ 85.6] Copying disk 1/1 to /vmfs/sitdns2 --10.xxx.128.203-sda (qcow2) (100.00/100%) [ 247.0] Creating output metadata Pool vmfs refreshed Domain sitdns2 --10.xxx.128.203 defined from /tmp/v2vlibvirt3a4adb.xml [ 247.0] Finishing off [root@SIT-KVM01 OVF]# virsh list --all Id Name State ---------------------------------------------------- 1 d1test-10.xxx.128.213 running 2 d1rongyiwang-10.xxx.128.135 running 3 d1search02--10.xxx.128.55 running 4 D1openAPI--10.xxx.128.239--IBM running 5 d1search04-10.xxx.128.136 running 6 d1search03--10.xxx.128.56 running 7 sitdns2 --10.xxx.128.203 running
第三種方法:將虛擬機導出爲OVF模板,而後將磁盤文件轉換爲KVM磁盤文件格式,再導入KVM。3d
[root@SIT-KVM01 OVF]#qemu-img convert -f vmdk -O qcow2 redhat-6.5--10.xxx.128.136-disk1.vmdk redhat-6.5--10.xxx.128.136-disk1.qcow2 [root@SIT-KVM01 OVF]#virt-manager
查看KVM支持machine列表,導入時選擇適當的類型
root@sit-kvm04:/vmfs# /usr/libexec/qemu-kvm -M help
Supported machines are:
microvm microvm (i386)
pc-i440fx-zesty Ubuntu 17.04 PC (i440FX + PIIX, 1996)
pc-i440fx-yakkety Ubuntu 16.10 PC (i440FX + PIIX, 1996)
pc-i440fx-xenial Ubuntu 16.04 PC (i440FX + PIIX, 1996)
pc-i440fx-wily Ubuntu 15.04 PC (i440FX + PIIX, 1996)
pc-i440fx-trusty Ubuntu 14.04 PC (i440FX + PIIX, 1996)
ubuntu Ubuntu 20.04 PC (i440FX + PIIX, 1996) (alias of pc-i440fx-focal)
pc-i440fx-focal Ubuntu 20.04 PC (i440FX + PIIX, 1996) (default)
pc-i440fx-focal-hpb Ubuntu 20.04 PC (i440FX + PIIX +host-phys-bits=true, 1996)
pc-i440fx-eoan Ubuntu 19.10 PC (i440FX + PIIX, 1996)
pc-i440fx-eoan-hpb Ubuntu 19.10 PC (i440FX + PIIX +host-phys-bits=true, 1996)
排錯一
root@sit-kvm04:/vmfs# virsh start D1ConfigManage--10.201.129.126
error: Failed to start domain D1ConfigManage--10.201.129.126
error: internal error: qemu unexpectedly closed the monitor: 2020-12-24T02:40:06.716466Z qemu-system-x86_64: -blockdev {"driver":"file","filename":"/vmfs/D1ConfigManage--10.201.129.126-sda","node-name":"libvirt-2-storage","cache":{"direct":true,"no-flush":false},"auto-read-only":true,"discard":"unmap"}: Could not open '/vmfs/D1ConfigManage--10.201.129.126-sda': Permission denied
資源池路徑不識別,調整文件絕對路徑
<disk type="volume" device="disk">
<driver name="qemu" type="qcow2" cache="none"/>
<source pool="vmfs" volume="D1ConfigManage--10.201.129.126-sda"/>
<target dev="vda" bus="virtio"/>
<address type="pci" domain="0x0000" bus="0x00" slot="0x04" function="0x0"/>
</disk>
修改成
<disk type="file" device="disk">
<driver name="qemu" type="qcow2" cache="none"/>
<source file="/vmfs/D1ConfigManage--10.201.129.126-sda"/>
<target dev="vda" bus="virtio"/>
<address type="pci" domain="0x0000" bus="0x00" slot="0x04" function="0x0"/>
</disk>