Clone and copy files of KVM virtual machines installed on centos

Source: Internet
Author: User

Centos 6.5 x86_64 system installation KVM Virtual Machine-clone and copy XML files to install new Virtual Machine

1. clone a new virtual machine through the template Virtual Machine

IP address planning:

HOST: 10.0.1.149

Template VM: 10.0.1.228

Clone VM: 10.0.1.100

  1. Shut down or pause the template virtual machine, and then clone and install the new virtual machine.

[[email protected] ~]# virt-clone -o kvm_mode_5566 -n mysql-server -f /data/kvmdisk/mysql-server.qcow2ERROR    Domain with devices to clone must be paused or shutoff.

Cause of error: Because the template host is not disabled, we disable the template Host and try again.

In the KVM environment, you can use the shutdown command to shut down the VM, but it does not take effect.

[[email protected] ~]# yum install -y acpid[[email protected] ~]# virsh Welcome to virsh, the virtualization interactive terminal.Type:  ‘help‘ for help with commands       ‘quit‘ to quitvirsh # list --all Id    Name                           State---------------------------------------------------- 1     kvm_mode_5566                  runningvirsh # shutdown kvm_mode_5566Domain kvm_mode_5566 is being shutdownvirsh # list --all             Id    Name                           State---------------------------------------------------- -     kvm_mode_5566                  shut off

2. Use the virt-clone command to clone the virtual machine.

[[email protected] ~]# virt-clone -o kvm_mode_5566 -n mysql-server -f /data/kvmdisk/mysql-server.qcow2Cloning kvm_mode.img                                                                                         |  10 GB     03:43     Clone ‘mysql-server‘ created successfully.

650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M00/46/35/wKioL1PvCi7TcmkvAACflP5vido436.jpg "Title =" 222333.jpg" alt = "wkiol1pvci7tcmkvaacflp5vido436.jpg"/>

3. Manually change the VNC port in the XML configuration file and restart the libmongod service.

[[email protected] ~]# more /etc/libvirt/qemu/mysql-server.xml | grep vnc    <graphics type=‘vnc‘ port=‘7789‘ autoport=‘no‘ listen=‘0.0.0.0‘>[[email protected] ~]# /etc/init.d/libvirtd restartStopping libvirtd daemon:                                  [  OK  ]Starting libvirtd daemon: 2014-08-16 02:08:44.921+0000: 3112: info : libvirt version: 0.10.2, package: 29.el6_5.11 (CentOS BuildSystem 


4. Start the newly cloned virtual machine.

[[email protected] ~]# virsh start mysql-serverDomain mysql-server started

5. Configure the eth0 Nic through the VNC client link.

650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M02/46/34/wKiom1PvCUqjE4m2AAGVTBW_yME667.jpg "Title =" Nic restart error .. Jpg "alt =" wkiom1pvcuqje4m2aagvtbw_yme667.jpg "/> solution:

Rm-RF/etc/udev/rules. d/70-persistent-net.rules

Modify the MAC address and UUID:

650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M02/46/35/wKioL1PvCrTDCib7AAE_MEQE5ko116.jpg "Title =" 20.0.jpg" alt = "wkiol1pvcrtdcib7aae_meqe5ko116.jpg"/>

Then reboot the new VM.

650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M02/46/35/wKioL1PvCvyzHf0GAAK9ZTRHTNQ020.jpg "Title =" .jpg "alt =" wkiol1pvcvyzhf0gaak9ztrhtnq020.jpg "/>


Ii. install a new Virtual Machine by copying an XML file

  1. Create a virtual machine image.

[[email protected] ~]# cd /data/kvmdisk/[[email protected] kvmdisk]# cp mysql-server.qcow2 cache-server.qcow2[[email protected] kvmdisk]# lltotal 1878560-rwxr-xr-x 1 root root 10739318784 Aug 15 22:24 cache-server.qcow2-rwxr-xr-x 1 qemu qemu 10739318784 Aug 15 22:25 mysql-server.qcow2

2. Create an XML file.

[[email protected] kvmdisk]# cd /etc/libvirt/qemu[[email protected] qemu]# lsautostart  kvm_mode_5566.xml  mysql-server.xml  networks[[email protected] qemu]# cp mysql-server.xml cache-server.xml

3. Modify the corresponding parameters.

UUID Mac VNC hard drive file location VM Host Name

UUID and Mac: can be changed at will, but the format is consistent

VNC: Specifies the port and cannot conflict with other virtual machines.

Virtual Disk File Location:/data/kvmdisk/cache-server.qcow2

[[email protected] qemu]# vim cache-server.xml<uuid>d779256d-b82d-0ce6-520f-c4dda1596da9</uuid><mac address=‘52:54:00:9c:b8:0a‘/><source file=‘/data/kvmdisk/cache-server.qcow2‘/><graphics type=‘vnc‘ port=‘7790‘ autoport=‘no‘ listen=‘0.0.0.0‘>

4. Create a virtual machine.

[[email protected] qemu]# virsh define cache-server.xml Domain cache-server defined from cache-server.xml

5. Start the VM.

[[email protected] qemu]# virsh start cache-serverDomain cache-server started

6. Set the VM to automatically restart.

[[email protected] qemu]# virsh autostart cache-serverDomain cache-server marked as autostarted

7. view all virtual machines.

[[email protected] ~]# virsh Welcome to virsh, the virtualization interactive terminal.Type:  ‘help‘ for help with commands       ‘quit‘ to quitvirsh # list --all Id    Name                           State---------------------------------------------------- 1     kvm_mode_5566                  running 2     mysql-server                   running 3     cache-server                   running

So far, the experiment has ended.

This article is from the blog "the years are past and the glory is still there". For more information, please contact the author!

Related Article

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.