KVM platform deployment and simple application of virtualization technology

Source: Internet
Author: User
Tags network function svm

preface KVM introduction


KVM Architecture

650) this.width=650; "src=" Http://www.178linux.com/ueditor/php/upload/image/20150718/1437232040137706.jpg "alt=" 1437232040137706.jpg "/>

The KVM architecture is very simple, is a module of the kernel, user space through the QEMU simulation hardware provided to the virtual machine to use, a virtual machine is a normal Linux process, through the management of this process, you can complete the management of the virtual machine.


KVM Platform Deployment

Detecting hardware

To detect whether virtualization is supported:

# egrep--color ' (VMX|SVM) '/proc/cpuinfo# if it contains VMX or SVM, it means hardware support virtualization, VMX represents INTEL,SVM on behalf of amd# load module # modprobe kvm# modprobe kvm_intel# Lsmod | grep kvmkvm_intel 54285 0 KVM 333172 1 kvm_intel

Install the Management software
KVM Native management software QEMU-KVM

# yum-y Install QEMU-KVM qemu-kvm-tools # ln-s/usr/libexec/qemu-kvm/usr/sbin/


QEMU-KVM command Explanation

Standard options for QEMU-KVM:

The standard options for QEMU-KVM mainly involve specifying the host type, CPU mode, NUMA, floppy drive device, optical drive device, and hardware device-name name: Setting the virtual machine name;-m machine: Specify the type of host to impersonate, such as standard  PC, isa-only pc, or Intel-mac-m megs: Sets the ram size of the virtual machine;-cpu model: Set the CPU model, such as Coreduo, qemu64, etc.-smp  n[,cores=cores][,threads=threads][,sockets=sockets][,maxcpus=maxcpus]: Set the number of CPUs in the analog SMP architecture, etc., The core number of each CPU and the number of sockets on the CPU; you can simulate up to 255 cpu;maxcpus on a PC to specify the maximum number of CPUs for hot insertion;-numa opts: Specifies a NUMA device that emulates multiple nodes;-fda  File:-fdb file: Using the specified file as the floppy image, file for/dev/fd0 indicates the use of the physical floppy drive;-HDA FILE-HDB FILE-HDC FILE-HDD  file: Use the specified file as the hard disk image;-cdrom file: Using the specified file as the CD-ROM image, it is important to note that-cdrom and-HDC cannot be used at the same time; specify file as/dev/ CDROM can use the physical optical drive directly;-drive option[,option[,option[,...]] : Defines a hard disk device with many available sub-options.     file=/path/to/somefile: Hardware image file path;     if=interface: Specifies the type of interface to which the hard drive device is connected, That is, the controller type, such as IDE, SCSI, SD, MTD, Floppy, Pflash and Virtio, etc.     index=index: Set the index number of different devices in the same controller type, namely the identification number;     media=media: Defines whether the media type is hard disk or disc (CDROM);    &nbspSnapshot=snapshot: Specifies whether the current hard drive device supports the snapshot feature: On or Off;    cache=cache: defines how the physical machine cache is used to access block data with a free value of none, Writeback, unsafe and writethrough four;     format=format: Specifies the format of the image file, which can be found in the qemu-img command;-boot [ Order=drives][,once=drives][,menu=on|off]: Defines the boot order of the boot device, each device is represented by one character, and the devices supported by different architectures and their presentation characters vary, on the x86 pc architecture, A, b means the floppy drive, C for the first hard drive, D for the first optical drive device, N-P for the network adapter, and the default for the hard disk device;-boot order=dc,once=d

Network options:

-NET NIC[,VLAN=N][,MACADDR=MAC][,MODEL=TYPE][,NAME=NAME][,ADDR=ADDR][,VECTORS=V]: Create a new NIC device and connect to vlan  n; macaddr is used to specify the MAC address for which the name is used to specify an online device names to be displayed during monitoring; EMU can simulate multiple types of NIC device-net tap[,vlan=n][,name=name][,fd=h][, Ifname=name][,script=file][,downscript=dfile]: Connect to vlan n with the TAP network interface of the physical machine, using the script specified by script=file (default =/etc/ QEMU-IFUP) To configure the current network interface and use the script specified by downscript=file (default =/etc/qemu-ifdown) to undo the interface configuration; use Script=no and downscript=no to disable script execution respectively ;-net user[,option][,option][,...] : Configure the network stack in user mode, which does not depend on administrative rights; valid options are:     vlan=n: Connect to Vlan n, default n=0;    name= Name: Specifies the display name of the interface, commonly used in monitoring mode;     net=addr[/mask]: Set guestos visible IP network, mask optional, default to 10.0.2.0/8;     HOST=ADDR: Specifies the IP address of the physical machine seen in Guestos, which defaults to the second in the specified network, that is, the x.x.x.2;    dhcpstart= Addr: Specifies the starting IP of 16 addresses in the DHCP service address pool, which defaults to 16th through 31st, which is x.x.x.16-x.x.x.31;    dns= Addr: Specifies the Guestos visible DNS server address, the default is the third address in the Guestos network, namely X.x.x.3;    tftp=dir: Activates the built-in TFTP server, and uses the specified dir as the default root directory for the TFTP server;NBSP;   BOOTFILE=FILE:BOOTP file name used to implement network boot Guestos, such as: Qemu -hda linux.img -bootn  -net user,tftp=/tftpserver/pub,bootfile=/pxelinux.0


To manage disk images using qemu-img:

QEMU-IMG is a tool component that QEMU uses to implement disk image management, which has a number of subcommands for implementing different management functions, and each subcommand has a range of different options. It uses the syntax format "QEMU-IMG subcommand [Options]", which supports the following subcommands. Create: Creates a new disk image file; Check: Checks the disk image file for errors; Convert: Format the converted disk image; Info: Displays information about the specified disk image; Snapshot: Managing Snapshots of disk images Commit: Commit all changes to the disk image; Rbase: Create a new image file based on a disk image; Resize: increase or decrease the size of the disk image file;


Case (1): the command format for creating a disk image with the CREATE subcommand is "create [-F FMT] [-o options] filename [size]";

For example, the following command creates a 50G disk image file in the format Qcow2.

# mkdir-pv/kvm/images/centos/# qemu-img create-f qcow2/kvm/images/centos/demos.img-o size=50G,preallocation= " Metadata "# ll-h/kvm/images/centos/demos.img-rw-r--r--. 1 root root 51G Dec 16:33/kvm/images/centos/demos.img#-f: Specify Virtual Disk file Format-o: Specify options

Case (2): Configure the bridge device to facilitate client virtual host communication with the outside world-install the bridge tool and create a bridging network card:

# yum-y Install bridge-utils# brctl ADDBR br0# cd/etc/sysconfig/network-scripts# cp ifcfg-eth0 ifcfg-br0# Cat Ifcfg-br0 Ifcfg-eth0 Device=br0bootproto=noneipv6init=noonboot=yestype=bridgeipaddr=172.16.100.104netmask=255.255.0.0dns2 =8.8.4.4gateway=172.16.0.2dns1=8.8.8.8userctl=nodevice=eth0bootproto=nonebridge=br0ipv6init=noonboot=yestype= Ethernetuserctl=no

Restart Network device effective configuration:

# Service Network Restart


case (3): If we join the network card device, we need to enable the system to start the rear axle connection network to BR0, we use the script to start and stop the system when the bridge network and delete the automatic operation of the bridge:

# cat/kvm/script/{qemu-ifdown,qemu-ifup}#!/bin/bashswitch=br0if [-N "$"];then brctl delif $switch IP link Set    Down Exit 0else echo "Error:no Interface." Exit 1fi#!/bin/bashswitch=br0if [-N "$"];    Then IP link set the UP Sleep 1 brctl addif $switch exit 0else echo "Error:no Interface." Exit 1fi# chmod +x/kvm/script/{qemu-ifdown,qemu-ifup}

Case (4): Create virtual Host and Virtual host system installation

# yum-y Install Tigervnc tigervnc-server--use VNC to display virtual host running status # qemu-kvm-name "centos6.5" >-M 512-SMP 2 >-drive file=/kvm/images/centos/demos.img,media=disk,format=qcow2,if=virtio,index=0 >-net nic,model=virtio >-net tap , Ifname=vnet0,script=/kvm/script/qemu-ifup,downscript=/kvm/script/qemu-ifdown >-boot order=dc,once=dVNC Server Running on ':: 1:5900 ' # vncviewer:5900--as shown:

650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M00/8B/08/wKiom1hCOAbyXyFsAAAbVx4NI6o946.png "title=" kvm_ PXE boot. png "alt=" Wkiom1hcoabyxyfsaaabvx4ni6o946.png "/>

Case (5): Verify that the network settings script is in effect:

# ifconfig vnet0vnet0     link  encap:ethernet  hwaddr aa:b6:2e:11:b5:53             inet6 addr: fe80::a8b6:2eff:fe11:b553/64 Scope:Link           UP BROADCAST RUNNING MULTICAST  MTU:1500   metric:1          rx packets:0 errors:0  dropped:0 overruns:0 frame:0          tx  packets:0 errors:0 dropped:0 overruns:0 carrier:0           collisions:0 txqueuelen:500            RX bytes:0  (0.0 b)   TX bytes:0  (0.0 b) 


Implementing virtual machine management based on Libvirt


Because the management of the process is very cumbersome, Redhat released an open source project Libvirt,libvirt API, there is a set of command-line tools to complete the management of the virtual machine, most of the management platform through the Libvirt to complete the management of the KVM virtual machine, Let's introduce the virtual machine management based on Libvirt.


To install the required management components:

# yum-y Install libvirt virt-manager virt-viewer python-virtinst# yum-y upgrade Device-mapper-libs--Upgrade dependency package processing fails to start

Start the service:

# service LIBVIRTD startstarting libvirtd daemon: [OK] #使用libvirt创建网桥无需再手动修改配置文件, one command Can be solved # Virsh Iface-bridge eth0 br0

Virt-instal-tools Tool Application:

Virt-install is a command-line tool that can create a virtual machine for KVM, Xen, or other LIBVRIT API-enabled hypervisor and complete the Guestos installation, in addition to the serial console, VNC or SDL supports text or graphical installation interfaces. #一般选项: Specify the name of the virtual machine, memory size, number of vcpus and features, etc.-n name, --name=name: Virtual machine name, need global unique;-r memory, --ram= MEMORY: Virtual machine within the size of the number of units MB;--VCPUS=VCPUS[,MAXVCPUS=MAX][,SOCKETS=#][,CORES=#][,THREADS=#]:VCPU and related configuration;--cpu= Cpu:cpu mode and features, such as Coreduo, can be used qemu-kvm -cpu ? To obtain the supported CPU mode; Installation method: Specify installation method, Guestos type, etc.-c cdrom, -- Cdrom=cdrom: CD installation media,-l location, --location=location: Install Source URL, support FTP, HTTP and NFS, such as Ftp://172.16.0.1/pub --PXE: Complete installation based on PXE;--livecd:  CD as Livecd;--os-type=distro_type: Operating system type, such as Linux, UNIX, or Windows;--os-variant= Distro_variant: Variants of a type of operating system, such as RHEL5, FEDORA8, etc.-x extra, --extra-args=extra: When--location is installed according to the Guestos-specified mode, Additional options for passing to the kernel, such as specifying the location of the Kickstart file,--extra-args  "Ks=http://172.16.0.1/class.cfg"--boot= Bootopts: Specifies configuration options after the installation process is complete, such as specifying the boot device order, booting the system using the specified instead of the installed KERNEL/INITRD, etc.  ; such as:--BOOT  CDROM,HD, Network: Specify the boot order;--boot kernel=kernel,initrd=initrd,kernel_args= "CONSOLE=/DEV/TTYS0": Specify the kernel and initrd file to boot the system, #存储配置: Specify storage Type, location and properties,--disk=diskopts: Specify storage device and its properties; Format--disk / Some/storage/path,opt1=val1,opt2=val2 and so on; common options are:     device: Device type, such as CDROM, disk or floppy, default to disk;     bus: The disk summary type, whose value can be IDE, SCSI, USB, Virtio, or xen;    perms: access rights such as RW, Ro or sh (shared readable and writable), default to Rw;    size: The size of the new disk image, in Gb;    cache: Cache model with a value of none, Writethrouth (cached reads) and writeback (cache read and write),     format: Disk image formats such as raw, Qcow2, VMDK;     sparse: The disk image uses sparse format, that is, does not immediately allocate space of the specified size;     --nodisks: Do not use local disk, commonly used in LIVECD mode; Network configuration: Specifies the network type and interface properties of the network interface, such as MAC address, drive mode, etc.-w network, --network=network,opt1=val1,opt2=val2: Connect the virtual machine to the host's network, Where network can be:     bridge=bridge: connected to a bridge device named "Brideg";     network= Name: Connect to a network named "name", and other commonly used options are: Network device models seen in     model:guestos, such as e1000, rtl8139, or Virtio;     MAC: Fixed MAC address; The random address is used when this option is omitted--nonetwoRks: Virtual machine does not use network function, #其它:--autostart: Specifies whether the virtual machine starts automatically after physical boot;--print-xml: If the virtual machine does not require the installation process (--import 、--boot), the generated XML is displayed instead of creating this virtual machine By default, this option still creates a disk image;--force: Disable commands from entering interactive mode, and if you need to answer yes or no, the answer is Yes;--dry-run: Perform the entire process of creating a virtual machine, but not actually creating a virtual machine, Change the device configuration information on the host and notify the libvirt;-d, --debug of the need to create it: Display debug information;


To install a virtual machine using Virt-install:

# qemu-img create-f qcow2/kvm/images/centos/centos.img-o size=120g,preallocation= "metadata" # virt-install-n "Centos6 "--vcpus=2-r--disk path=/kvm/images/centos/centos.img,bus=virtio,size=50,sparse--network bridge=br0,model= Virtio--force--pxe

650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M02/8B/05/wKioL1hCb0HAhOoJAAApRZfQLqs483.png "title=" kvm_ V.png "alt=" Wkiol1hcb0hahoojaaaprzfqlqs483.png "/>

Virt-manager
Virt-manager is a virtual machine management graphical interface written in Python that allows users to intuitively manipulate different virtual machines, and Virt-manager is implemented using Libvirt APIs.

To install a virtual machine using Virt-manager:

# Virt-manager &

The configuration process is as follows:

650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M01/8B/05/wKioL1hCciSD3523AABCoWT4ONo753.png "title=" Vmanager.png "alt=" Wkiol1hccisd3523aabcowt4ono753.png "/>

650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M02/8B/05/wKioL1hCciWA14YBAACcBzTo9tM444.png "title=" Intall--1.png "alt=" Wkiol1hcciwa14ybaaccbzto9tm444.png "/>

650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M00/8B/09/wKiom1hCciXxk2W8AACGXuR2h-M232.png "title=" Intall--2.png "alt=" Wkiom1hccixxk2w8aacgxur2h-m232.png "/>

650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M00/8B/05/wKioL1hCciXh3j6_AAB5fAmB0Ro646.png "title=" Intall--3.png "alt=" Wkiol1hccixh3j6_aab5famb0ro646.png "/>

650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M02/8B/09/wKiom1hCcibjtJHqAACSlahY150986.png "title=" Intall--4.png "alt=" Wkiom1hccibjtjhqaacslahy150986.png "/>

650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M01/8B/09/wKiom1hCciaRYsHSAACP7wGzEu8820.png "title=" Intall--5.png "alt=" Wkiom1hcciaryshsaacp7wgzeu8820.png "/>

650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M01/8B/05/wKioL1hCcifwKRd6AACNriKsysc920.png "title=" Intall--6.png "alt=" Wkiol1hccifwkrd6aacnriksysc920.png "/>

650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M02/8B/09/wKiom1hCcieCU795AABR7-84v0o954.png "style=" float: none; "title=" Intall--7.png "alt=" Wkiom1hcciecu795aabr7-84v0o954.png "/>

The above is the virtualization technology of the KVM platform deployment and simple application of all content.

This article is from the "Opensamlee" blog, make sure to keep this source http://gzsamlee.blog.51cto.com/9976612/1879147

KVM platform deployment and simple application of virtualization technology

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.