KVM virtual machine live migration

​For KVM dynamic migration, there are the following suggestions and precautions. Try to use a network shared storage system on the source host and the destination host to save the client disk image. For example: NFS, ISCSI, Glusterfs, etc.

download-icon
Free Download
for VM, OS, DB, File, NAS, etc.
nick-zhao

Updated by Nick Zhao on 2021/05/26

Table of contents
  • For KVM dynamic migration, there are the following suggestions and precautions

  • V2V migration

  • Verify in the host

For KVM dynamic migration, there are the following suggestions and precautions

  • Try to use a network shared storage system on the source host and the destination host to save the client disk image. For example: NFS, ISCSI, Glusterfs, etc.

  • In order to improve the success rate of dynamic migration, try to perform dynamic migration on hosts with the same type of CPU. Although KVM dynamic migration also supports migration from Intel platform to AMD platform, it is not recommended to do so in terms of security and stability.

  • 64-bit clients can only run migration between 64-bit hosts, while 32-bit clients can migrate between 32-bit hosts and 64-bit hosts.

  • During dynamic migration, the name of the migrated client is unique, and there cannot be a client with the same name as the migrated client of the source host on the destination host.

  • The software of the destination host and the source host are the same as possible as VMware, kvm, xen, etc.

V2V migration

  • Deploy NFS server to realize file sharing between Linux and Linux. NFS usually runs on port 2049

  Because before using the NFS service for file sharing, you need to use the RPC (Remote Procedure Call) service to send information such as the IP address and port number of the NFS server to the client. Therefore, before starting the NFS service, you also need to restart and enable the rpcbind service program.

   

  Server-side configuration:

  •   Downlaod nfs and rpcbind

   1 [root@localhost ~]# yum install nfs-utils rpcbind -y 

 

  •   Configure nfs file

  

[root@localhost ~]# mkdir /nfsdate[root@localhost ~]# vim /etc/exports/nfsdate 192.168.127.133/24(rw)

 

  •    Reboot nfs and rpcbind

   1 [root@localhost ~]# systemctl restart rpcbind nfs 

 

  

  Client configuration

  •   Download nfs-utils

   1 [root@localhost ~]# yum install nfs-utils -y 

 

  •   View shared file

  

1 [root@localhost ~]# showmount -e 192.168.127.1302 Export list for 192.168.127.130:3 /nfsdate 192.168.127.133/24

 

  •   Mount server nfs to local

  

 1 [root@localhost ~]# mkdir /nfsdate 2 [root@localhost ~]# mount -t nfs 192.168.127.130:/nfsdate /nfsdate 3 [root@localhost ~]# df -h 4 文件系统                  容量  已用  可用 已用% 挂载点 5 /dev/mapper/cl-root        17G  8.3G  8.8G   49% / 6 devtmpfs                  478M     0  478M    0% /dev 7 tmpfs                     489M     0  489M    0% /dev/shm 8 tmpfs                     489M  7.1M  482M    2% /run 9 tmpfs                     489M     0  489M    0% /sys/fs/cgroup10 /dev/sda1                1014M  141M  874M   14% /boot11 tmpfs                      98M     0   98M    0% /run/user/012 192.168.127.130:/nfsdate   17G   10G  7.1G   59% /nfsdate

 

  •   The server backs up the configuration file (startup file) /etc/libvirt/qemu/ of the virtual machine to be migrated to /root and moves the disk file /var/lib/libvirt/images/ to the newly created shared file /nfsdate  

 

  •    Move the disk file of vm1 to the shared file

  

1 [root@localhost ~]# cd /var/lib/libvirt/images/2 [root@localhost images]# ls3 centos7.0.qcow2  CentOS-7-x86_64-DVD-1611.iso  test.qcow2  vm1.qcom2  vm2.qcow24 [root@localhost images]# mv vm1.qcom2 /nfsdate

 

  •    Back up the configuration file of vm1 to /root

  

[root@localhost ~]# cd /etc/libvirt/qemu/[root@localhost qemu]# lscentos7.0.xml  networks  test.xml  vm1.xml  vm2.xml[root@localhost qemu]# cp vm1.xml /root

  

  •   Delete vm1 virtual machine domain

  

1 [root@localhost qemu]# ls2 centos7.0.xml  networks  test.xml  vm1.xml  vm2.xml3 [root@localhost qemu]# virsh undefine vm14 域 vm1 已经被取消定义5 6 [root@localhost qemu]# ls7 centos7.0.xml  networks  test.xml  vm2.xml

 

  •   Switch to /root to modify the vm1 configuration file and modify its disk file path

  

1 [root@localhost ~]# vim vm1.xml2     <disk type='file' device='disk'>3       <driver name='qemu' type='qcow2'/>4       <source file='/nfsdate/vm1.qcom2'/>       #把源路径修改为/nfsdate5       <target dev='vda' bus='virtio'/>6       <boot order='1'/>7       <address type='pci' domain='0x0000' bus='0x00' slot='0x07' function='0x0'/>8     </disk>

 

  •   Restore vm1

  

 1 [root@localhost ~]# virsh define vm1.xml 2 定义域 vm1(从 vm1.xml) 3  4 [root@localhost ~]# virsh list --all 5  Id    名称                         状态 6 ---------------------------------------------------- 7  -     centos7.0                      关闭 8  -     test                           关闭 9  -     vm1                            关闭10  -     vm2                            关闭

 

  •    Both the server and the client need to do domain name resolution

  

1 [root@localhost ~]# vim /etc/hosts2 127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain43 ::1         localhost localhost.localdomain localhost6 localhost6.localdomain64 192.168.127.130 yun15 192.168.127.133 yun2

 

  •    View shared files on client server

  

[root@localhost ~]# cd /nfsdate[root@localhost nfsdate]# lsvm1.qcom2

 

 

Verify in the host

  • Create a connection in the host, which is shared by the two hosts.

  

 

  • It is recommended to modify the host names of the two hosts to avoid the same host names. Prevent some unnecessary errors.

  

hostnamectl set-hostname 主机名exit

  

  •  Click Connect, then enter yes and account password respectively, the connection is created

  • Because it is a hot migration, turn on the migrated virtual machine; then click Migrate

Share on:

Categories: VM Migration