KVM Virtualization 2-QEMU-KVM

Source: Internet
Author: User

KVM only supports x86 64 hardware virtualization requires that the CPU must support hardware virtualization HVM

KVM Two components:

1 Kvm.ko module after loading for/DEV/KVM work for hypervisor, in user space through the system call LOCTL () and the core of the KVM module interaction, to complete the creation of virtual machine, start

2QEMU-KVM process: Used in user space for IO device emulation to implement a virtual machine instance

KVM Architecture

Virtio: A semi-virtualized solution for open source

KSM: Scan memory, if there is a common data memory space for memory with multiple virtual machine instances, make it unique (not much)

KVM Management Tools

1 managing KVM with QEMU-KVM

Qemu:

Processor Simulator

Simulation of each IO device

Physical device that connects the emulation device to the host

Provide user interface

Want to command to create a link using qemu ln-sv/usr/libexec/qemu-kvm/usr/bin

Qemu-kvm

-machine [Type=]name:-machine Help to get a list that specifies the type of host to impersonate;

-cpu CPU:-CPU Help to get the list; Specify the CPU model to simulate;

-SMP N[,maxcpus=cpus][,cores=cores][,threads=threads][,sockets=sockets]: Indicates the number and topology of Vcpus on the virtual machine;

-boot [Order=drives][,once=drives][,menu=on|off] [, Splash=sp_name][,splash-time=sp_time][,reboot-timeout=rb_time ][,strict=on|off]

Order: The boot order of each device: C represents the first hard drive, and D represents the first optical drive device;-boot Order=dc,once=d

-M Megs: The memory size of the virtual machine;

-name Name: The current virtual machine names, to be unique;

Block device-related options:

-hda/-hdb file: Indicates the path of the IDE bus type disk mapping files; No. 0 and 1th;

-HDC/-HDD file: 2nd and 3rd;

-cdrom file: Specifies that you want to use disc image files;

-drive [file=file][,if=type][,media=d][,index=i][,cache=writethrough|writeback|none|directsync|unsafe][,format= F]:

File=/path/to/some_image_file: Image file path;

If=type: Block device bus type, IDE, SCSI, SD, floppy, Virtio,...

Media=type: Media type, cdrom and disk;

Index=i: Sets the number of devices of the same type device;

Cache=writethrough|writeback|none|directsync|unsafe: Cache mode;

FORMAT=F: The format of the disk image file;

Display options:

-display Type: Displays the types of SDL, curses, none, and VNC;

-nographic: Do not use graphical interface;

-VGA [Std|cirrus|vmware|qxl|xenfb|none]: Model of the analog card;

-vnc display[,option[,option[,...]] : Initiates a VNC server to display the virtual machine interface, allowing the QEMU process to listen to a VNC interface;

Display

(1) host:n

The nth desktop number of the host hosts outputs VNC;

5900+n

(2) Unix:/path/to/sock_file

(3) None

Options

Password: the password required to connect to this service;

-monitor stdio: Displays the monitor interface on the standard output;

CTRL-A, c: Switch between console and monitor;

Ctrl-a, H

Simulation:

Network options:

-net Nic[,vlan=n][,macaddr=mac][,model=type][,name=str][,addr=str][,vectors=v]

Create a network interface for the virtual machine and add it to the specified VLAN;

Model=type: Indicates the model number of the emulated NIC, Ne2k_pci,i82551,i82557b,i82559er,rtl8139,e1000,pcnet,virtio

To create a disk image file:

Qemu-img create-f Qcow2-o perallocation=metadate,size=80g/vms/centos/centos.img

To create a virtual network:

Create a virtual network card, all paired up one on the virtual machine and the other on the bridge so you can communicate.

IP link Add vethm.1 type Veth peer name vethm.2

IP link Show Show

IP link del vethx.1 type Veth peer name vethx.2 Delete

Here you can simulate a space and put a network card in it.

IP netns Add router1 Create

IP Netns List View

IP link Set dev vethm.2 netns router1 vethm.2 Add router1

View in Router1

IP netns exec router1 ifconfig-a

After you configure the IP, you can communicate by activating.

A generic virtual machine will add another NIC to the bridge

Brctl Show display

Create a bridge: Brctl ADDBR br-int

Ifconfig Br-int up activation

Script:

#!/bin/bash

Bridge=br-int

If [-N "$"]; Then

Ip Link Set up

Sleep 1

Brctl AddIf $bridge

[ $?  -eq 0] && Exit 0 | | Exit 1

Else

Echo "No Interface Specified"

Exit 2

Fi

To start a virtual machine instance:

#qemu-kvm-name c1-m 256-smp 2-drive file=/vms/cirros1.img,media=disk,if=virtio,format=qcow2-net Nic,model =virtio,macaddr=52:54:00:00:00-net tap,script=/etc/qemu-ifup-vnc:0-daemonize

One more

~]# qemu-kvm-name c2-m 256-smp 2-drive file=/vms/cirros/cirros1.img,media=disk,if=virtio,format=qcow2-net Nic,model=virtio,macaddr=52:54:00:00:01-net Tap,script=/etc/qemu-ifup-vnc:2-daemonize

At this point, we see two NICs associated with the bridge TAP01 TAP02

# vncviewer:0 & Enter virtual machine

NET-based interaction with outside

Turn on core forwarding: Sysctl-w net.ipv4.ip_forward=1

In the virtual machine, specify the Gateway: route add default GW 10.1.1.254

Iptables-t NAT–VNL

Ping to catch packet discovery is a host in the access

Tcpdump-i ens33 ICMP

How to connect an outside server to a virtual machine, add a Dnat rule

Iptables-t nat-a preroutung-d 172.16.0.67-p tcp--dport 22922-j DNAT--to Destination 10.1.1.1:22

#ssh-P 22922 [email protected]

DNSMASQ is a lightweight DNS and DHCP server

#dnsmasq-I br-int-f 10.1.1.11,10.1.1.100-o 3,10.1.1.254

KVM Virtualization 2-QEMU-KVM

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.