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

How qemu-kvm creates a virtual machine and sets up the network

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

Share

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

This article mainly introduces qemu-kvm how to create a virtual machine and set up the network, which has a certain reference value. Interested friends can refer to it. I hope you will gain a lot after reading this article. Let's take a look at it.

One: introduction

Hypervisor: a "virtual machine monitor (VMM)", a component between bare metal hardware and an operating system that allows multiple operating systems to be installed on a physical server.

VNC: is an open source program for remote control on UNIX and Linux platforms, including: vncserver,vncviewer,vncpasswd, and vncconnect.

Kernel modules added in KVM:Linux version 2.6X, divided into two: kvm.ko and kvm_intel.ko / kvm_amd.ko

QEMU-KVM:KVM is a module that can virtualize CPU and memory, but it can not, so it draws lessons from QEMU and forms a tool of QEMU-KVM. With it, users can easily operate the KVM kernel, virtual virtual machines, virtual disks and so on.

Virtualization is divided into:

Paravirtualization: completely simulated by software, without hardware support, slow speed = > xen

Full Virtualization: hardware support is required, with high speed = > KVM

Second: create a virtual machine

1. Check whether cup supports virtual reality.

Grep-E-o 'vmx | svm'-- color / proc/cpuinfo

Note: if you want to use KVM in the virtual machine of vmwareWorkstation

You need to enable VT-X technology in the settings, as shown in the figure:

2. Check whether the kvm module is loaded in the Linux kernel

Lsmod | grep kvm

3. Load KVM module

Modprobe kvm modprobe kvm_intel

4. Install qemu-kvm. / usr/libexec/qemu-kvm will be generated after installation, which is the interface for user space to operate the kvm kernel. After installation, the above KVM module will be loaded automatically.

Yum install-y qemu-kvm

5. Upload ISO image files through the network

Just open the ftp client to upload via Alt + p of CRT.

6. Generate an 8G image file as the disk of the virtual machine

Qemu-img create-f raw / root/hadoop.img 8G generates raw format by default, and divides qemu-img create-f qcow2 / root/hadoop.img 8G into qcow2 format as much as you give.

7. Use qemu-kvm to create a virtual machine (parameter description-m specifies memory size-smp specifies the number of cup-boot boot sequence)

/ usr/libexec/qemu-kvm-m 2048-smp 1-boot order=cd-cdrom / iso/CentOS-6.6-x86_64-minimal.iso-hda / cloud/CentOS.img-vnc: 1 Parameter description:-m specifies the client memory size, and the default unit MB-smp specifies the number of client cpu. SMP: (symmetric [s metrics] Multi-processing) symmetric multiprocessing-boot specifies the boot sequence of the client system. Order=cd refers to the CD first and then the hard disk. C:CD-ROM d:Hard Disk-hda specifies the client's IDE hard disk (that is, the image file created earlier)-cdrom specifies the client's optical drive

8. Install vnc or use vnc tools to connect to the virtual machine, and install the system for the virtual machine

9. Shut down the virtual machine and start the virtual machine again, specifying vnc port 5901 (there is no need to specify cdrom, because the operating system has already been installed on disk, of course, it doesn't matter, because it will detect whether the operating system is installed!)

/ usr/libexec/qemu-kvm-m 2048-smp 1-boot order=cd-hda / cloud/CentOS.img-vnc: 1

3: configure the network (brigde, nat, host-only) Note: brctl and tunctl are only created temporarily and will not modify the ifcfg-eth0 information under network-scripts, so open the opportunity to restore.

Description: bridge-utils and tunctl support is required.

Brctl is used to create and manage Ethernet bridge under Linux. The command tunctl for establishing, maintaining and checking bridge configuration in the kernel is used to create bridge ports for tap and tun mode.

In the computer network, TUN and TAP are virtual network devices in the operating system kernel. Different from the ordinary devices realized by hardware network cards, these virtual network devices are all implemented by software and provide the same functions as the hardware network devices to the software running on the operating system.

TAP is equivalent to an Ethernet device that operates layer 2 packets such as Ethernet data frames. TUN simulates network layer devices, operating layer 3 packets such as IP data packets.

Bridge bridging configuration

1. To install bridge-utils tunctl

Yum install-y bridge-utils tunctl

2. Add a br0 bridge (bridge type)

Brctl addbr br0 ifconfig br0 up

3. The etho of hypervisor also needs to be bound to bridge and completed in one step (please change it to your own IP)

Brctl addif br0 eth0 & brctl stp br0 on & & ifconfig eth0 0.0.0.0 & & ifconfig br0 192.168.33.250 netmask 255.255.255.0 & & route add default gw 192.168.33.1

4. Create a virtual network card device of TAP type, which is used to bind the virtual machine.

Tunctl-t vnet0 ifconfig vnet0 up brctl addif br0 vnet0 brctl show

5. Create a virtual machine and associate the network card (you can have multiple vnet in a row)

/ usr/libexec/qemu-kvm-m 2048-smp 1-boot order=cd-cdrom / kvmhost/iso/centos-6.7.iso-hda / kvmhost/kvms/test.img-net nic-net tap,ifname=vnet0,script=no,downscript=no-net nic-net tap,ifname=vnet1,script=no,downscript=no-vnc: 1

6. Start the virtual machine and associate the network card (with multiple vnet in succession) and add the mac address

/ usr/libexec/qemu-kvm-m 2048-smp 1-boot order=cd-hda / cloud/Centos.img-net nic,macaddr=52:54:00:12:34:57-net tap,ifname=vnet0,script=no,downscript=no

7. Edit ifcfg-eth0 configuration

Static ip (on the same network segment as the physical machine) configuration subnet mask configuration dns1 configuration default gateway (same gateway as the physical machine)

8. Restart network service network restart.

Host-only configuration

1. To install bridge-utils tunctl

Yum install-y bridge-utils tunctl

2. Add a hostonlybr0 bridge (bridge type)

Brctl addbr hostonlybr0 ifconfig hostonlybr0 up

3. Set a random ip address to the bridge (there is no need to bind eth0 to this bridge, that is, isolated from eth0)

4. Create a virtual network card device of TAP type, which is used to bind the virtual machine.

Tunctl-t vnet0 ifconfig vnet0 up brctl addif hostonlybr0 vnet0 brctl show

5. Create a virtual machine and associate the network card

/ usr/libexec/qemu-kvm-m 4096-smp 1-boot order=cd-hda / cloud/Centos.img-net nic-net tap,ifname=vnet0,script=no,downscript=no

6. Start the virtual machine, associate the network card and add the mac address

/ usr/libexec/qemu-kvm-m 2048-smp 1-boot order=cd-hda / cloud/Centos.img-net nic,macaddr=52:54:00:12:34:57-net tap,ifname=vnet0,script=no,downscript=no

7. Edit ifcfg-eth0 configuration

Static ip (any network segment, everyone can be together) configure subnet mask, configure dns1, configure default gateway (same gateway as physical machine)

8. Restart network service network restart.

4. Qemu-img is an important tool and a disk management tool of QEMU.

1. View help information

Qemu-img-h

2. View image file information

Qemu-img info / cloud/CentOS.img

3. Create a disk image file

Qemu-img create-f qcow2 / cloud/itcast.img 10G

4. Convert raw format to qcow2 format

Qemu-img convert-O qcow2 / cloud/itcast.raw / cloud/itcast.qcow2

5. Modify the image size

Qemu-img resize / cloud/test.img + 2G

6. Check the image

Qemu-img check / cloud/itcast.qcow2

7. Image format

Qemu-img supports a variety of image formats, which can be viewed through the qemu-img-h command. The common ones are qcow2,raw raw: the original disk image format, which is the default file format of the qemu-img command. The advantage of this format is that it is very simple and easy to transplant to other simulators. The feature allows the mirror to actually take up the allocated space from the start, but the write speed is slightly faster. Qcow2: this format is currently recommended by QEMU. It is the most versatile format. It supports sparse files to save storage space, and supports encryption, compression, snapshot and other functions.

QEMU monitor is a console for QEMU to interact with users, which is generally used to provide more complex functions for QEMU simulators.

Switching of QEMU monitor

"Ctrl + Alt + 2"-- > QEMU monitor status "Ctrl + Alt + 1"-- > client standard display window

Display system command status: info

View the version information of QEMU

Info versions

Check whether the current QEMU is supported by KVM

Info kvm info name info status

View the information of each vCPU of the client

Info cpus

View block device information, such as hard disk, floppy disk, optical drive, etc.

Info block

View the network configuration information of the client

Info network

Displays the saved client snapshot information in the current system

Info snapshots

View the migration status of the current client

Info migrate

Displays the VNC status of the current client

Info vnc

View the history of command execution in QEMU monitor

Info history

Create a snapshot

Savevm snap20150406

Restore snapshot

Loadvm snap20150406

Delete snapshot

Delvm snap20150406

Thank you for reading this article carefully. I hope the article "how to create a virtual machine and set up a network in qemu-kvm" shared by the editor will be helpful to everyone. At the same time, I also hope that you will support and pay attention to the industry information channel. More related knowledge is waiting for you to learn!

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