LVM + NBD realize VM backup and data migration

In a high availability cloud systems, high availability is particularly critical VM layer, which also involves the issue of migration of VM backup and data itself. On an existing platform, each VM data on a separate LV (logical volume), the backup VM data may be accomplished by the LV its backup, migration is required other physical servers can access the VM data, that LV content. For backup, you can use the snapshot function LVM (Logical Volume Manager) to complete, remote access can be accomplished by NBD (Network Block Device).

LVM belong to the software layer, under the management of the hard disk partition, which advantage can be dynamically resized LV dynamically increase PV (physical volume) to VG (volume group) to increase the capacity of VG, LV create snapshots, so that the user LV It can be adjusted directly with the case where the capacity is not enough to meet the size of LV, without the need to re-partition the underlying physical disk. Here we mainly use LVM snapshots to back up VM data, as follows:

Suppose the physical servers named Server1, on which a virtual machine named VM1, VM1 data stored in the LV-VM1 logical volume, the logical volumes belonging to the group named VgVm. At some point, VM1 data is intact, we need to back up data this moment, in case VM1 data can be restored to the moment in time when a future state to be destroyed. First, create a logical volume snapshot command is as follows:

lvcreate –L 1G –s –n LV-VM1Snapshot /dev/VgVm/LV-VM1

Where the "1G" is to create a snapshot of the size of this size based on the need to develop. Note that, if the specified value is too small snapshot overflow occurs during its life cycle, then the snapshot will be invalid, so the need for the amount of data to be written to the snapshot there is a reasonable estimate of the time of creation. "LV-VM1Snapshot" is a snapshot name, other parameters can be found in the corresponding help files.

LVM snapshots using the Copy-on-write (copy-on-write) mechanism after the snapshot is created, when there is data to be written to a volume on LV-VM1 position, this position will LVM data copied to the LV on -VM1Snapshot snapshot logical, then new data is written LV-VM1, so that played a role in backup of the old data. In an actual implementation, the LVM might not to copy data, a new open position but writing new data, and then adjusts the pointer values ​​of the data block to achieve the object, the speed quickly. Here, we only need to know enough to copy-on-write, do not have to go into the implementation details.

After more than a snapshot is created, we need a way to remotely access the snapshot, so NBD come in handy. NBD block as a network device, which is a source of content servers on the network, consisting of Server / Client model. Client machines like access local disk to access the data, but the real content stored on the Server. Client needs to be installed on the machine NBD kernel module, when the data to be accessed on the Client Server, which sends the requests to the kernel module Server, Server end has a daemon called nbd-server, is responsible for parsing the received request to read the data and then returned to the Client.

It should be two physical servers, one of which Server1 as mentioned above, we treat it as Server end of NBD, NBD another as the Client-side, assuming the name Server2. NBD now need to install on Server1 and Server2, the following steps were mounted on two servers:

Download the latest installation package: nbd-3.2.tar.bz2, into the installation package directory, execute the following command:

tar jxf nbd-3.2.tar.bz2

This command will extract the build directory nbd-3.2. Then execute the command:

cd nbd-3.2

./configure // this step if the prompt "missing glib", you need to run apt-get install libglib2.0-dev

make && make install

This, are installed on Server1 and Server2 the NBD service.

Execute commands on Server1:

nbd-server 1234 /dev/VgVm/ LV-VM1Snapshot

1234 is the port number, the flexibility to specify, followed by NBD to export logical volume name, here is the snapshot volume created above.

Client-side NBD Server2 as the need to install kernel module, performs the following command to install:

insmod  /lib/modules/xxx/kernel/drivers/block/nbd.ko

Wherein xxx vary by system.

After installing the kernel module, whereas the command "ls / dev", you can see the / dev directory and more nbd0, nbd1 and other equipment.

Execute commands on Server2:

nbd-client Server1-IP 1234 /dev/nbd0

Wherein Server1-IP is the IP address NBD Server end, the port number 1234, / dev / nbd0 represented mirror device, access to / dev / nbd0 snapshot volume is equivalent to the access Server1 "/ dev / VgVm / LV-VM1Snapshot". If you need to copy the contents of the snapshot Server2, only need to / dev / nbd0 can be dd, you can mount the device / dev / nbd0 then access the files.

Original Address:
LVM + NBD realize VM backup and data migration

Published 218 original articles · won praise 165 · Views 1.03 million +

Guess you like

Origin blog.csdn.net/x_i_y_u_e/article/details/104616367