CentOS Stream 8
Sponsored Link

KVM : Live Migration2021/03/10

 
This is the example to use Live Migration feature for Virtual Machines.
It requires 2 KVM host server and also a storage server like follows.
Configure DNS or hosts to resolve names or IP addresses normally, first.
                      +----------------------+
                      |   [  NFS Servver  ]  |
                      |     nfs.srv.world    |
                      |                      |
                      +-----------+----------+
                                  |10.0.0.35
                                  |
+----------------------+          |          +----------------------+
|  [   KVM Host #1  ]  |10.0.0.21 | 10.0.0.22|  [  KVM Host #2   ]  |
|                      +----------+----------+                      |
|    kvm01.srv.world   |                     |    kvm02.srv.world   |
+----------------------+                     +----------------------+

[1]
Configure Storage server that virtual machine images are placed.
For Storage server, it's OK to use NFS, iSCSI, GlusterFS and so on.
It uses NFS on this example.
[2]
Configure 2 KVM host server and mount a directory provided from Storage server on the same mount point on both KVM server. It uses [/var/kvm/images] for mount point on this example.
[3] On KVM Hosts, if SELinux is enabled and also uses NFS shared directory, change rules like follows.
[root@kvm01 ~]#
setsebool -P virt_use_nfs on
[4] On KVM Hosts, if Firewalld is running, allow ports.
[root@kvm01 ~]#
firewall-cmd --add-service={libvirt,libvirt-tls} --permanent

[root@kvm01 ~]#
firewall-cmd --add-port=49152-49215/tcp --permanent

[root@kvm01 ~]#
firewall-cmd --reload

[5] Create and Start a Virtual Machine on a KVM Host and run Live Migration like follows.
For connection between KVM Hosts, they connects to others with SSH, so it had better to set SSH key-pair with root account before running live migration.
# edit the setting of a VM you'd like to run live migration

[root@kvm01 ~]#
virsh edit centos-st8
 <disk type='file' device='disk'>
      # add : change cache mode to [none]
      <driver name='qemu' type='qcow2' cache='none'/>
      <source file='/var/kvm/images2/centos-st8.img'/>

[root@kvm01 ~]#
virsh start centos-st8

[root@kvm01 ~]#
virsh list

 Id   Name         State
----------------------------
 1    centos-st8   running

[root@kvm01 ~]#
virsh migrate --live centos-st8 qemu+ssh://kvm02.srv.world/system

[root@kvm01 ~]#
virsh list

 Id   Name   State
--------------------

# just migrated
### on another KVM Host ###

[root@kvm02 ~]#
virsh list

 Id   Name         State
----------------------------
 1    centos-st8   running

# back to the KVM Host again like follows

[root@kvm02 ~]#
virsh migrate --live centos-st8 qemu+ssh://kvm01.srv.world/system

[root@kvm02 ~]#
virsh list

 Id   Name   State
--------------------

Matched Content