Mud: KVM uses LVM snapshots to quickly deploy virtual machines

Source: Internet
Author: User

This article is first published in the dark world.

The previous article introduced KVM's functions of using LVM snapshot to back up and recover virtual machines. This article describes how to use the LVM snapshot function to quickly deploy virtual machines for KVM.

To deploy a virtual machine, follow these steps:

1. Create an LVM Snapshot

2. Modify the xml configuration file of the VM.

3. Use the virsh define command to define a virtual machine

4. Start the VM and modify the network settings.

Since the snapshot feature of LVM is used, we should first create a snapshot. As follows:

Lvcreate-L 100 m-S-N lvmsp2/dev/vg1/lvmsp

650) This. width = 650; "Title =" clip_image001 "style =" border-left-0px; border-right-width: 0px; Background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; padding-Right: 0px; border-top-width: 0px "border =" 0 "alt =" clip_image001 "src =" http://img1.51cto.com/attachment/201408/21/526870_14086040368D9l.png "width =" 603 "Height =" 221 "/>

For more information about KVM, see my previous blog. At the same time, the directory/test mounted to the logical volume/dev/vg1/lvmsp is a KVM virtual machine that stores the hard disk and runs normally. As follows:

650) This. width = 650; "Title =" clip_image002 "style =" border-left-0px; border-right-width: 0px; Background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; padding-Right: 0px; border-top-width: 0px "border =" 0 "alt =" clip_image002 "src =" http://img1.51cto.com/attachment/201408/21/526870_1408604053wDBe.png "width =" 577 "Height =" 217 "/>

650) This. width = 650; "Title =" clip_image003 "style =" border-left-0px; border-right-width: 0px; Background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; padding-Right: 0px; border-top-width: 0px "border =" 0 "alt =" clip_image003 "src =" http://img1.51cto.com/attachment/201408/21/526870_1408604085aJMO.png "width =" 856 "Height =" 570 "/>

After the snapshot is completed, we can use the snapshot as a virtual machine. First, mount the snapshot as follows:

Mount/dev/vg1/lvmsp2/Test2/

650) This. width = 650; "Title =" clip_image004 "style =" border-left-0px; border-right-width: 0px; Background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; padding-Right: 0px; border-top-width: 0px "border =" 0 "alt =" clip_image004 "src =" http://img1.51cto.com/attachment/201408/21/526870_1408604091pwzc.png "width =" 425 "Height =" 109 "/>

After configuring the above LVM snapshot, the following section describes the KVM configuration.

We can copy the xml configuration file of any of the VMS and then modify the configuration file. The following is an example of the configuration file testlvmos. Copy the configuration file testlvmos and name it testlvmos 2.xml as follows:

CP/etc/libvirt/qemu/testlvmos. xml/etc/libvirt/qemu/testlvmos2.xml

650) This. width = 650; "Title =" clip_image005 "style =" border-left-0px; border-right-width: 0px; Background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; padding-Right: 0px; border-top-width: 0px "border =" 0 "alt =" clip_image005 "src =" http://img1.51cto.com/attachment/201408/21/526870_14086040988l3F.png "width =" 630 "Height =" 256 "/>

Now let's modify the testlvmos2.xml file. There are several parts of this file that need to be modified and the others can be kept unchanged.

First, <Name> testlvmos </Name>. Here we can change testlvmos to testlvmos2. This is the name of the VM. It is recommended to be consistent with the configuration file testlvmos2.xml.

Second, <UUID> 44a24883-9805-f679-4b3a-a443064a3ebb </UUID>. This is the uuid of the device. We can use the uuidgen command to generate. As follows:

650) This. width = 650; "Title =" clip_image006 "style =" border-left-0px; border-right-width: 0px; Background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; padding-Right: 0px; border-top-width: 0px "border =" 0 "alt =" clip_image006 "src =" http://img1.51cto.com/attachment/201408/21/526870_1408604102W1ZM.png "width =" 295 "Height =" 114 "/>

Third, <source file = '/test/testlvmos. IMG'/>, which is the hard disk path of the virtual machine. Modify the directory to which the snapshot is attached as follows:

<Disk type = 'file' device = 'disk'>

<Driver name = 'qemu' type = 'qcow2 'cache = 'none'/>

<Source file = '/Test2/testlvmos. IMG'/>

<Target Dev = 'hda' bus = 'ide '/>

<Address type = 'Drive 'controller = '0' bus = '0' target = '0' unit = '0'/>

</Disk>

650) This. width = 650; "Title =" clip_image007 "style =" border-left-0px; border-right-width: 0px; Background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; padding-Right: 0px; border-top-width: 0px "border =" 0 "alt =" clip_image007 "src =" http://img1.51cto.com/attachment/201408/21/526870_1408604115RiwR.png "width =" 549 "Height =" 135 "/>

Or we can modify it as follows:

<Disk type = 'block' device = 'disk'>

<Driver name = 'qemu' type = 'qcow2 'cache = 'none'/>

<Source Dev = '/dev/vg1/lvmsp2'/>

<Target Dev = 'hda' bus = 'ide '/>

<Address type = 'Drive 'controller = '0' bus = '0' target = '0' unit = '0'/>

</Disk>

650) This. width = 650; "Title =" clip_image008 "style =" border-left-0px; border-right-width: 0px; Background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; padding-Right: 0px; border-top-width: 0px "border =" 0 "alt =" clip_image008 "src =" http://img1.51cto.com/attachment/201408/21/526870_1408604125tlLY.png "width =" 531 "Height =" 146 "/>

Pay attention to the part marked in the figure.

Fourth, <MAC address = '52: 54: 00: 19: 57: 8c'/>. This is the network port address of the virtual machine.This address can be modified at will, but it must not be repeated with other virtual machines.. Now we change it to 52: 54: 00: 19: 50: 8D, as follows:

650) This. width = 650; "Title =" clip_image009 "style =" border-left-0px; border-right-width: 0px; Background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; padding-Right: 0px; border-top-width: 0px "border =" 0 "alt =" clip_image009 "src =" http://img1.51cto.com/attachment/201408/21/526870_1408604146yllQ.png "width =" 610 "Height =" 131 "/>

Fifth, <graphics type = 'vnc 'port = '000000' autoport = 'no' Listen = '0. 0.0.0 '>. The Port Number of the VNC client connection. Here we change it to 5880. As follows:

650) This. width = 650; "Title =" clip_image010 "style =" border-left-0px; border-right-width: 0px; Background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; padding-Right: 0px; border-top-width: 0px "border =" 0 "alt =" clip_image010 "src =" http://img1.51cto.com/attachment/201408/21/526870_1408604157EZiu.png "width =" 551 "Height =" 93 "/>

After the configuration file of the Virtual Machine testlvmos2 is modified, we can now define the virtual machine through the virsh define command. As follows:

Virsh define/etc/libvirt/qemu/testlvmos2.xml

650) This. width = 650; "Title =" clip_image011 "style =" border-left-0px; border-right-width: 0px; Background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; padding-Right: 0px; border-top-width: 0px "border =" 0 "alt =" clip_image011 "src =" http://img1.51cto.com/attachment/201408/21/526870_1408604161zzNS.png "width =" 506 "Height =" 263 "/>

After the Virtual Machine testlvmos2 is defined, start the Virtual Machine testlvmos2 and use virsh start testlvmos2, as shown below:

650) This. width = 650; "Title =" clip_image012 "style =" border-left-0px; border-right-width: 0px; Background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; padding-Right: 0px; border-top-width: 0px "border =" 0 "alt =" clip_image012 "src =" http://img1.51cto.com/attachment/201408/21/526870_1408604168LcPU.png "width =" 687 "Height =" 286 "/>

We can see that the virtual machine testlvmos2 can be started and run normally.

Note: currently, all configurations of the Virtual Machine testlvmos2 are the same as those of the Virtual Machine testlvmos.

The following operations we need to perform are related to configuring the Virtual Machine testlvmos2 network. You can also refer to my previous article "mud: adding a NIC for a KVM Virtual Machine". As follows:

VI/etc/udev/rules. d/70-persistent-net.rules

650) This. width = 650; "Title =" clip_image013 "style =" border-left-0px; border-right-width: 0px; Background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; padding-Right: 0px; border-top-width: 0px "border =" 0 "alt =" clip_image013 "src =" http://img1.51cto.com/attachment/201408/21/526870_1408604173xBXE.png "width =" 761 "Height =" 234 "/>

CP/etc/sysconfig/network-scripts/ifcfg-eth0/etc/sysconfig/network-scripts/ifcfg-eth1

Rm-r/etc/sysconfig/network-scripts/ifcfg-eth0

650) This. width = 650; "Title =" clip_image014 "style =" border-left-0px; border-right-width: 0px; Background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; padding-Right: 0px; border-top-width: 0px "border =" 0 "alt =" clip_image014 "src =" http://img1.51cto.com/attachment/201408/21/526870_1408604181iFrn.png "width =" 789 "Height =" 157 "/>

VI/etc/sysconfig/network-scripts/ifcfg-eth1

650) This. width = 650; "Title =" clip_image015 "style =" border-left-0px; border-right-width: 0px; Background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; padding-Right: 0px; border-top-width: 0px "border =" 0 "alt =" clip_image015 "src =" http://img1.51cto.com/attachment/201408/21/526870_1408604186ixXC.png "width =" 327 "Height =" 230 "/>

/Etc/init. d/network restart

650) This. width = 650; "Title =" clip_image016 "style =" border-left-0px; border-right-width: 0px; Background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; padding-Right: 0px; border-top-width: 0px "border =" 0 "alt =" clip_image016 "src =" http://img1.51cto.com/attachment/201408/21/526870_1408604190cXzx.png "width =" 780 "Height =" 251 "/>

By now, the virtual machine testlvmos2 has been fully configured, and we can also use the Virtual Machine teslvmos2 normally.

If we still need a virtual machine, we can repeat it in this way.

NOTE: If we use the above method to generate a virtual machine, the original Virtual Machine testlvmos must not be used again.

This is because the current LVM snapshot stores the status of the original Virtual Machine testlvmos. If the status of the original Virtual Machine testlvmos is used to, the cow copy function of the LVM will cause the snapshot to change.

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.