Detailed local storage-based KVM virtual machine online Migration _KVM

Source: Internet
Author: User
Tags connection reset uuid ssh hosting iptables

KVM Virtual machine migration is divided into 4 types

(1) Thermal migration is based on shared storage

(2) Thermal migration based on local storage

(3) Cold migration is based on shared storage

(4) Cold migration based on local storage

This is a hot migration based on local storage.

Dynamic Block Migration version requirements

QEMU version requires greater than or equal to 0.12.1 (centos6.7 or above is OK)

Rpm-qa|grep qemu
qemu-kvm-0.12.1.2-2.491.el6_8.1.x86_64
qemu-kvm-tools-0.12.1.2-2.491.el6_8.1.x86_64

Target host: 192.168.1.24 machine name: CQ-KVM01

SOURCE Host: 192.168.1.26 machine name: cq-kvm02

Migrate using TCP authentication method

KVM Virtual machine name, is a running nginx virtual machine: cq-nginx01

1. Configure the LIBVIRTD service source host and target host hosts to perform

vi/etc/libvirt/libvirtd.conf
listen_tls = 0  
listen_tcp = 1
tcp_port = "16509"
listen_addr = "0.0.0.0" C9/>auth_tcp = "None"
mdns_adv = 0

Explain

    • LISTEN_TLS: Turn off TLS, default is turned on
    • LISTEN_TCP: Open TCP Authentication
    • TCP_PORT:TCP port configuration, the default port is 16509
    • AUTH_TCP: Configure whether to turn on password authentication, the default does not open
    • MDNS_ADV: Open MDNs multicast, default shutdown
Sed-i ' s/^ #listen_tls = 0/listen_tls = 0/'/etc/libvirt/libvirtd.conf
sed-i ' s/^ #listen_tcp = 1/listen_tcp = 1/'/et c/libvirt/libvirtd.conf
sed-i ' s/^ #tcp_port = \ "16509\"/tcp_port = \ "16509\"/'/etc/libvirt/libvirtd.conf
Sed-i ' s/^ #listen_addr = \ 192.168.0.1\/listen_addr = \ 0.0.0.0\/'/etc/libvirt/libvirtd.conf
sed-i ' s/^ #auth_ TCP = \ "sasl\"/auth_tcp = \ none\/'/etc/libvirt/libvirtd.conf
sed-i ' s/^ #mdns_adv = 1/mdns_adv = 0/'/etc/libvirt/l Ibvirtd.conf
Cat libvirtd.conf |grep-ie "Listen_tls"
cat libvirtd.conf |grep-ie "listen_tcp"
cat libvirtd.conf |grep-ie "tcp _port "
cat libvirtd.conf |grep-ie" listen_addr "
cat libvirtd.conf |grep-ie" auth_tcp "
cat libvirtd.conf | Grep-ie "Mdns_adv"

2, configure LIBVIRTD monitoring mode, whether the TCP,SSH,TLS authentication mode needs to be configured, the source host and target host hosts are to perform

VI/ETC/SYSCONFIG/LIBVIRTD
libvirtd_args= "--listen"

3, edit/etc/libvirt/qemu.conf file source host and target host hosts have to perform

vi/etc/libvirt/qemu.conf
vnc_listen = "0.0.0.0"

Explain

    • Vnc_listen: Allows virtual machine out-of-band vnc to be monitored by default. 0.0.0.0

4, restart the LIBVIRTD service, so that the configuration takes effect, the source host and the target host hosts are to perform

/ETC/INIT.D/LIBVIRTD restart

5, check the port and process, LIBVIRTD whether listening to 16509 ports, the source host and target host hosts are to perform

NETSTAT-LNTP | grep LIBVIRTD
TCP 0 0 0.0.0.0:16509 0.0.0.0:* LISTEN 48825/LIBVIRTD

Modify the Iptables script to release Port 16509 and Port 49152

#ACCESS KVM
iptables-a input-m State--state new-m tcp-p TCP--dport 5900:5909-j ACCEPT iptables-a input-p
TCP--dport 16509-j ACCEPT
iptables-a input-p tcp--dport 49152-j ACCEPT

6, in the source host and the target hosting host IP and host analysis

#24机器上
echo "192.168.1.26 cq-kvm02" >>/etc/hosts
#26机器上
echo "192.168.1.24 cq-kvm01" >>/etc/ Hosts

7, in the source host to connect to the target host LIBVIRTD and view the virtual machine information

Virsh-c Qemu+tcp://root@192.168.1.26:16509/system
virsh-c Qemu+tcp://root@192.168.1.24:16509/system

8, in the target host to create the same size of the mirror file, the path, name the same

To add Preallocation=metadata, otherwise the virtual machine disk image becomes RAW format after the installation is completed with the Virt-install command

Qemu-img create-f qcow2-o Preallocation=metadata/data/kvmimg/cq-nginx01.qcow2 100G

9, migration, 192.168.1.26 as the target host of the intranet Ip,tcp authentication mode, the migration time is a bit long need to open a screen window, do not need a CD to the directory where the mirror files

Screen-s MIGRATEKVM
Virsh migrate--live--copy-storage-all--unsafe--persistent cq-nginx01 qemu+tcp:// Root@192.168.1.26:16509/system

10, in the target hosting host, will show paused state that is suspended state

Watch Virsh list--all

11, in the target host to perform, show the migration progress

Tailf/var/log/libvirt/qemu/cq-nginx01.log

12, in the target hosting host, the Mirror file directory for/data/kvmimg/, display the size of the virtual machine image, you will see the virtual machine image will be increased to indicate that the data is moving over

Note To use Preallocation=metadata when creating a mirrored file

cd/data/kvmimg/
Watch Du-h *

13, the virtual machine migration completed, the source host to shutdown state, the target host to become running state

Virsh list--all #源宿主机
virsh list--all #目标宿主机

14. Source host deletes XML configuration file

Virsh destroy cq-nginx01
virsh undefine cq-nginx01

Attention:

Ping will have cotton in the process of migration, sometimes lose a few packets, if there is a deployment database in the virtual machine, the application should have a heavy connection mechanism

Fetch method

It is recommended that you do not delete the mirrored files on the source host and keep the mirrored files

#在目标宿主机上执行, fetch to source host

Virsh dumpxml cq-nginx01 >~/cq-nginx01.xml virsh migrate--live--copy-storage-all--unsafe--persistent
CQ-NGINX01 Qemu+tcp://root@192.168.1.24:16509/system

Attention:

The source host and target host hosts are best to keep the hardware consistent so that the chances of migrating and fetching problems can be minimized!

Migration speed and success rate and network have a lot of relationship, host network as far as possible million or gigabit multiple network card binding, can improve migration speed and success rate

#限制迁移速度 for 600m/s
virsh migrate-setspeed cq-nginx01 600

--------------------------------------------------------------------------------

Summary of online migration issues

(If the port of SSH is not the default 22, it can be written as Qemu+ssh://target:port/system)

Question 1:

Error:internal error hostname on destination resolved to localhost, but migration-an FQDN

The solution is simple, because hostname is localhost by default, we need to change the hostname of the target, and we can do it temporarily.

#hostname Target

Question 2:
Error:internal error attempt to migrate guest to the same host 00020003-0004-0005-0006-000700080009

This is a problem with the server provider in the mail list, you can use #dmidecode-s System-uuid to view this ID, theoretically #virsh sysinfo | grep UUID and # Virsh capabilities | grep UUID

These three IDs are the same. (Before the forum to see the solution is to download a dmidecode command file to replace the system, to achieve the purpose of modification, but I just modified the Libvirt configuration file on it, may be the version of the problem)

Let's modify the LIBVIRTD configuration file.

#sed-i "/#host_uuid/ahost_uuid = \" ' Uuidgen ' \ ""/etc/libvirt/libvirtd.conf

Restart the LIBVIRTD service

#/ETC/INIT.D/LIBVIRTD Restart

And check it out again.

# Virsh Capabilities | grep UUID

Question 3:

Error:unable to set user and group to ' 107:107 '/image/vmtest/disk.img ': No such file or directory

If the smooth entry to this step, it is very simple, no directory directly create a can, no disk.img directly created a

Note: The disk created should be the same size as the disk of the source virtual machine (greater should be possible) and format (raw or QCOW2)

Qemu-img create/image/vmtest/disk.img +sizeg

Question 4:

Error:unable to resolve address ' target ' service ' 49155 ': Name or service not known

"Name or service not known" adds resolved IP and target domain names in/etc/hosts

Question 5:

Virsh migrate--live--copy-storage-all--unsafe--persistent cq-nginx01 Qemu+tcp://root@192.168.1.24:16509/system

Error:unable to read from Monitor:connection reset by peer

Possible target host and source host memory not enough

Recommendation: Disable unnecessary virtual machines on both the target host and the source host to free up memory

You can also empty the cache to free up memory.

#清除cache perform the sync command first

Sync
echo 3 >/proc/sys/vm/drop_caches

The above is the entire content of this article, I hope to help you learn, but also hope that we support the cloud habitat community.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.