Greetings Habr!
In this small how-to, I would like to share with you my experience of using the utility lvmsync.
This utility allows you to solve the problem of transferring a virtual machine from one KVM server to another, with minimal downtime of the virtual machine, without using shared storage (non-shared storadge).
We will transfer the entire LVM partition on which the virtual machine is installed. Well, the magic of LVM snapshot, which you can easily find on the Internet, can help reduce downtime.
')
Here's what a virtual machine transfer looks like in brief:
- Take a snapshot of the LVM section.
- We transfer the main LVM partition over the network without stopping our VM.
- When the transfer of the main section is finished, we stop the VM.
- Run lvmsync to transfer the snapshot over the network. Not the whole picture is transferred, but only the changed blocks.
- Prepare and run the VM on the new server.
As a result, when using lvmsync, the idle time of the virtual machine will be equal to the transfer time of the changed blocks in the snapshot of the main section.
More information about the work of lvmsync, and additional buns you can read on the
project page .
Further, it is assumed that we have sudo rights in the system, ssh access is configured by keys, and the input is denied under root.
Let's start VM migration:
Installation:
For lvmsync, we need Ruby 1.8 (or later), ssh, and dmsetup.
Download lvmsync to the local computer:
wget https://github.com/mpalmer/lvmsync.git
Copy lvmsync to root PATH, for example in / usr / bin /
Preparing a remote server (server2):
1) Download and install lvmsync.
2) Create an LVM partition for the copied VM.
server2
The size of the partition must be equal to the original partition (in principle, it may be larger than the original, but this option has not been tested by me).
Prepare local server and migrate VM.
Further, all commands must be executed on the server from which we want to move the virtual machine (server1).
1) Create a definition xml:
server1
2) Take a snapshot of the section:
server1
Warning!Please note that the size of the snapshot should be selected depending on the intensity of use of the VM. Since All data, while we transfer the main section, will be “saved” to the snapshot.
And when the image is full, it is automatically
deactivated .
3) Without stopping the VM, transfer the primary partition using dd:
server1
Here is added compression of the transmitted data in zip, and the display of the progress of data transmission using pv.
4) When the transfer is complete, stop the virtual machine:
server1
5) And after a full stop of the machine, run lvmsync to transfer the snapshot:
server1
This operation will not only transfer the snapshot to a new server, but also merge it immediately with the main LVM partition.
6) Copy the definition xml to a remote server:
server1
Preparing and running a virtual machine on a new server:
1) Change the definition xml if necessary.
2) Create a virtual machine based on xml:
server2
3) We start our virtual machine, and register it in autostart:
server2
That's all, the virtual machine transfer is over!
Notes
The utility was tested on Centos 6.4. It’s difficult to say anything about the transfer time, because It all depends on the intensity of working with the virtual machine during its transfer, and, accordingly, the size of the snapshot.