KVM virtualization platform - KVM virtual machine migration

Bowen outline:
a, KVM virtual machine migration way
Second, to achieve static KVM virtual machine migration
Third, to achieve KVM virtual machine live migration

A, KVM virtual machine migration ways

KVM platform KVM virtual machine migration is divided into the following two:

(1) cold migration (migration static)

We store the virtual machine's disk directories are hanging on a nfs disk file system, a cold migration, as long as nfs mount the file system on the target host, you can see that you want to migrate virtual machine disk files, usually end .qcow2 or .raw, and then just send virtual machine .xml configuration file to the target server, and then re-definition of what a virtual machine can be migrated!

(2) thermal migration (live migration)

If the state of the source host and the destination host the shared storage system, the client only needs to be sent through a network vCPU execution state, the contents of memory, the virtual machine device to the destination host. Otherwise, you also need the client's disk storage sent to the main purpose of
the machine. Refers to the shared storage system image file source and destination directory is on a virtual machine a shared storage.

: Specific process based on the shared storage system, migration dynamic
(1) when the migration starts, the client is still running on the host, at the same time, client memory page is transmitted to the destination host;
(2) the QEMU / be the KVM monitor and record any changes have all been transferred memory page, under the migration process, and begin transmitting in the previous procedure to change the contents of memory pages in memory after all pages are completed transfer;
(3) QEMU / estimates the KVM migration process the transmission speed, the time period when the remaining amount of memory in a data can be set (default 30 milliseconds) when the transfer is complete, QEMU / KVM client closes on the source host, then the remaining amount of data transferred to the destination host, the last transmission over the contents of memory to resume operation client state on the destination host;
(4) at this point, the KVM live migration operation is complete! Migrated as far as possible consistent with the client prior to migration, missing some configuration unless the destination host, such as bridges and so on. Note that when the client memory usage is very large and is modified often, in-memory data constantly being modified faster than memory speed KVM can be transmitted when the live migration process is not complete, and this time only static migration.

(3) Notes

(1) brand CPU migration server is preferably the same;
(2) between the 64-bit only 64-bit host mobility, 32 and 32 can migrate host 64;
virtual machine names (3) in the host can not be conflict;
(4) object of the host and the source host the same software configuration as much as possible;

(4) summary

Static migration:
(1) copy the image files and virtual machine configuration file;
(2) the virtual machine can be redefined!

Dynamic migration:
(1) Create a shared memory;
(2) two KVM host to mount shared storage;
live migration (3) starts;
(4) to create a virtual configuration file migration;
(5) redefines the virtual machine;

Second, to achieve static KVM virtual machine migration

(1) environmental requirements

  • A KVM service and A: IP address: 192.168.1.7, one of which is the KVM web01 virtual machine;
  • A KVM server B: IP address: 192.168.1.8;

(2) step to achieve

A KVM server operations:

Due to the experimental environment, simplicity, here a little too, are interested can create your own files or directories for testing!

[root@localhost ~]# systemctl stop firewalld
[root@localhost ~]# setenforce 0
//实验环境,简单起见关闭防火墙与SElinux
[root@localhost ~]# lsmod | grep kvm          //确认虚拟机支持kvm环境
kvm_intel             174841  0 
kvm                   578518  1 kvm_intel
irqbypass              13503  1 kvm
[root@localhost ~]# virsh list --all     //确认虚拟机存在,而且是关机的状态
 Id    名称                         状态
----------------------------------------------------
 -     web01                          关闭

KVM server B's operation:

[root@localhost ~]# systemctl stop firewalld
[root@localhost ~]# setenforce 0
//实验环境,简单起见关闭防火墙与SElinux
[root@localhost ~]# lsmod | grep kvm          //确认虚拟机支持kvm环境
kvm_intel             174841  0 
kvm                   578518  1 kvm_intel
irqbypass              13503  1 kvm
[root@localhost ~]# virsh list --all           //确认没有kvm虚拟机
 Id    名称                         状态
----------------------------------------------------
[root@localhost ~]# scp 192.168.1.7:/etc/libvirt/qemu/web01.xml /etc/libvirt/qemu/web01.xml
//复制KVM宿主机A的虚拟机配置文件
[root@localhost ~]# scp 192.168.1.7:/kvm/disk/web01.raw /kvm/disk/web01.raw
//复制KVM宿主机的虚拟机磁盘文件
[root@localhost ~]#  cd /etc/libvirt/qemu/
[root@localhost qemu]# virsh define web01.xml
定义域 web01(从 web01.xml)
//根据配置文件生成虚拟机
[root@localhost qemu]# virsh start web01     //开启虚拟机进行测试
域 web01 已开始

[root@localhost qemu]# virsh list --all
 Id    名称                         状态
----------------------------------------------------
 1     web01                          running
//可以正常开机表示没有问题,自行进行测试即可!

Static migration migration is complete!

In fact, there's really nothing static migration, plainly, with almost the same clone!

Third, to achieve KVM virtual machine live migration

(1) environmental requirements

  • An NFS server: IP address: 192.168.1.6;
  • A KVM server A: IP address: 192.168.1.7;
  • A KVM server B: IP address: 192.168.1.8;

Note: KVM KVM virtual machine host does not need!

(2) step to achieve

NFS server operations:

[root@localhost ~]# systemctl stop firewalld
[root@localhost ~]# setenforce 0
//实验环境,简单起见关闭防火墙与SElinux
[root@localhost ~]# yum -y install nfs-utils rpcbind
//安装NFS所需软件
[root@localhost ~]# mkdir /kvmshare          //创建共享目录
[root@localhost ~]# echo "/kvmshare  *(rw,sync,no_root_squash)" >> /etc/exports
//配置共享目录的权限,共享的用户
//no_root_squash:使其获取NFS服务器的root权限
[root@localhost ~]# systemctl start rpcbind           //启动远程传输控制服务
[root@localhost ~]# systemctl start nfs       //启动NFS共享服务

Two KVM to verify:

[root@localhost ~]# showmount -e 192.168.1.6
Export list for 192.168.1.6:
/kvmshare *

A KVM server operations:

[root@localhost ~]# systemctl stop firewalld
[root@localhost ~]# setenforce 0
//实验环境,简单起见关闭防火墙与SElinux
[root@localhost ~]# lsmod | grep kvm          //确认虚拟机支持kvm环境
kvm_intel             174841  0 
kvm                   578518  1 kvm_intel
irqbypass              13503  1 kvm
[root@localhost ~]# virsh list --all           //确认没有kvm虚拟机
 Id    名称                         状态
----------------------------------------------------
[root@localhost ~]# virt-manager          //打开图像化界面管理KVM

The preferred create a storage pool, as:
KVM virtualization platform - KVM virtual machine migration
KVM virtualization platform - KVM virtual machine migration
KVM virtualization platform - KVM virtual machine migration
KVM virtualization platform - KVM virtual machine migration
Next, you create based storage pool storage volumes, as shown:
KVM virtualization platform - KVM virtual machine migration
KVM virtualization platform - KVM virtual machine migration
Next, create a virtual machine, as shown:
KVM virtualization platform - KVM virtual machine migration
KVM virtualization platform - KVM virtual machine migration
KVM virtualization platform - KVM virtual machine migration
KVM virtualization platform - KVM virtual machine migration
KVM virtualization platform - KVM virtual machine migration
KVM virtualization platform - KVM virtual machine migration
KVM virtualization platform - KVM virtual machine migration
Next, create an appropriate virtual machines according to their actual situation!
KVM virtualization platform - KVM virtual machine migration
After completion of restarting the virtual machine, turning it off, which is configured as a bridged network following process:

[root@localhost ~]# virsh destroy centos7.0             //实验环境,就采取强制关机了,但不建议使用
域 centos7.0 被删除

[root@localhost ~]# systemctl stop NetworkManager       //关闭网络管理工具
[root@localhost ~]# virsh iface-bridge ens33 br0       //通过ens33生成br0
使用附加设备 br0 生成桥接 ens33 失败            //提示失败没有关系
已启动桥接接口 br0

[root@localhost ~]# virsh edit centos7.0      //使用“edit”命令编辑虚拟机的配置文件
定位到interface,修改一下内容:
    <interface type='bridge'>          修改为bridge
      <mac address='52:54:00:ef:a3:93'/>
      <source bridge='br0'/>     修改为 bridge='br0'
[root@localhost ~]# virsh start centos7.0         //启动centos7虚拟机

KVM virtualization platform - KVM virtual machine migration
KVM virtualization platform - KVM virtual machine migration
KVM virtualization platform - KVM virtual machine migration

KVM server B's operation:

[root@localhost ~]# systemctl stop firewalld
[root@localhost ~]# setenforce 0
//实验环境,简单起见关闭防火墙与SElinux
[root@localhost ~]# lsmod | grep kvm          //确认虚拟机支持kvm环境
kvm_intel             174841  0 
kvm                   578518  1 kvm_intel
irqbypass              13503  1 kvm
[root@localhost ~]# virsh list --all           //确认没有kvm虚拟机
 Id    名称                         状态
----------------------------------------------------
[root@localhost ~]# virt-manager          //打开图像化界面管理KVM

Create a storage pool, with exactly the same operation KVM server A, as shown:
KVM virtualization platform - KVM virtual machine migration
KVM virtualization platform - KVM virtual machine migration
KVM virtualization platform - KVM virtual machine migration
KVM virtualization platform - KVM virtual machine migration
KVM virtualization platform - KVM virtual machine migration
generating a bridged card BR0, heat will facilitate a migration operation, as follows:

[root@localhost ~]# systemctl stop NetworkManager
[root@localhost ~]#  virsh iface-bridge ens33 br0 
使用附加设备 br0 生成桥接 ens33 失败
已启动桥接接口 br0
//因为本地现在并没有虚拟机,所以只需生成桥接网卡即可!
[root@localhost ~]# hostname kvmB
[root@localhost ~]# su -
上一次登录:三 12月  4 20:05:59 CST 2019从 192.168.1.253pts/1 上
[root@kvmB ~]#                        //修改主机名,否则一会可能会出现错误

A KVM server to do the following:
KVM virtualization platform - KVM virtual machine migration
KVM virtualization platform - KVM virtual machine migration
If the following error appears, as shown:
KVM virtualization platform - KVM virtual machine migration
That is because there is no installation package using the SSH protocol connections needed to ask for a password!

The following operations are required to operate in two KVM:

[root@localhost ~]# yum -y install openssh-askpass
[root@kvmB ~]#  yum -y install openssh-askpass 
//安装询问密码的依赖包,注意两台KVM服务器都需安装

After the installation is complete, the server on the KVM again connected A:
KVM virtualization platform - KVM virtual machine migration
KVM virtualization platform - KVM virtual machine migration
Open KVM virtual machine, it has access Baidu, as shown:
KVM virtualization platform - KVM virtual machine migration
the next hot migration, as shown:
KVM virtualization platform - KVM virtual machine migration
KVM virtualization platform - KVM virtual machine migration
KVM virtualization platform - KVM virtual machine migration
View KVM virtual machines to access the existence of the phenomenon of the terminal, as :
KVM virtualization platform - KVM virtual machine migration
according to the results show, and found access without interruption, thus, live migration success!

-------- end of this article so far, thanks for reading --------

Guess you like

Origin blog.51cto.com/14157628/2456147