Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Virtual cloning Technology of KVM Series

2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

Background

In general, there is more than one virtual machine running on the host, so the question is, how to deploy in batches quickly? Does each one install step by step according to the system prompts from scratch? I'm going to go crazy. Is there any better way to solve it? There must be a way to make the same virtual machine through cloning technology to achieve rapid deployment of virtual machines. Now I will briefly introduce two ways to implement it.

Implementation method:

Virtual machine cloning is realized through the "virt-clone" command.

Virtual machine cloning is realized by copying disks and configuration files.

Virtual machine hosting host system:

CentOS 7.2.1511 X86_64

Command implementation

prerequisite

The disk format type of virtual machine is qcow2.

The cloned host needs to be shut down.

Clone a virtual machine

[root@controller] # virt-clone-- original windows_2k3-- name windows_2k3_01-- file / data/pool/windows_2k3_01

Description:

-- original: specify the clone system source

-- name: specify a new virtual machine name

-- file: specify the location of the new virtual machine

Modify virtual profile

[root@controller ~] # virsh edit windows_2k3_01

Change to

Or

[root@controller ~] # vim / etc/libvirt/qemu/windows_2k3_01.xml

[root@controller ~] # virsh define / etc/libvirt/qemu/windows_2k3_01.xml

Add VNC window

[root@controller ~] # cp / lib/systemd/system/vncserver@.service / lib/systemd/system/vncserver@:11.service

Start the virtual machine

[root@controller ~] # virsh start windows_2k3_01

Connect VNC

Note: if you are cloning a linux system, you need to deal with the virtual network after booting the system.

Copy implementation

Copy disk mirroring, profile

[root@controller ~] # cp / data/pool/windows_2k3 / data/pool/windows_2k3_02

[root@controller ~] # cp / etc/libvirt/qemu/windows_2k3.xml / etc/libvirt/qemu/windows_2k3_02.xml

Modify the configuration file

[root@controller ~] # vim / etc/libvirt/qemu/windows_2k3_02.xml

Changed to: windows_2k3_02

Delete: 3230baaa-88e9-4289-8c96-d6621c35cd97

Change to:

Delete:

Change to:

[root@controller ~] # virsh define / etc/libvirt/qemu/windows_2k3_02.xml

Add VNC window

[root@controller ~] # cp / lib/systemd/system/vncserver@:11.service / lib/systemd/system/vncserver@:12.service

Start the virtual machine

[root@controller ~] # virsh start windows_2k3_02

View a list of virtual machines

[root@controller] # virsh list-- all

Id name status

12 windows_2k3_01 running

13 windows_2k3_02 running

-windows_2k3 shutdown

Connect VNC

Information comparison

Network comparison

Expand content

Not familiar with the configuration file, it is difficult to modify, can you generate the configuration file automatically? Yes, you only need to copy the disk image and automatically generate the configuration file by executing the "virt-install" command, as long as you know the hardware configuration parameters (the most important thing is the disk information) when the cloned virtual host is created.

For example, the previous command to create windows_2k3 is as follows

Virt-install-n windows_2k3-r 1024-vcpus=1-c / data/iso/windows_server_2003.iso-- disk path=/data/pool/windows_2k3,format=qcow2,size=30,bus=ide-- hvm-- os-type=windows-- vnc-- vncport 5910-- network network=default-- force-- autostart

Change to

Virt-install-n windows_2k3_03-r 1024-vcpus=1-c / data/iso/windows_server_2003.iso-- disk path=/data/pool/windows_2k3_03,format=qcow2,size=30,bus=ide-- hvm-- os-type=windows-- vnc-- vncport 5913-- network network=default-- force-- autostart

Note: only three changes are needed:-n,-- disk path,-- vncport.

FQA

Q: can a clone virtual machine use a remote desktop connection?

A: yes, you need to configure a fixed IP on the cloned host, create a user password, and enable the remote feature. After the system is cloned, you can use the remote desktop to connect. To connect, you need to modify the IP address, otherwise there will be IP conflicts in the cloning of the next virtual machine.

Q: the network has a duplicate name

A: my computer-- properties-- computer name-- change-- enter a new computer name-- restart the system.

Q: clone linux system, how to deal with network problems when starting up?

A: 70-persistent-net.rules and ifcfg-eth0 files need to be processed

[root@KVM_Clinet ~] # rm-rf / etc/udev/rules.d/70-persistent-net.rules

[root@KVM_Clinet ~] # vi / etc/sysconfig/network-scripts/ifcfg-eth0

Delete MAC and UUID, and you can also manually configure static IP (not a comparison item), and then restart the system.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report