CentOS 6.5 Installation of KVM virtualization

Source: Internet
Author: User
Tags svm

First, KVM Introduction

KVM (kernel-basedvirtual machine), a kernel-based VM, is a virtualized infrastructure used in the Linux kernel to transform the Linux kernel into a hypervisor. KVM was introduced into the Linux 2.6.20 core in February 2007 and ported to FreeBSD and Illumos in a way that can load core modules.

KVM runs on an x86 platform with Intel VT or AMD-V capabilities. It is also ported to the S/390,POWERPC and IA-64 platforms. In Linux kernel version 3.9, support for the ARM architecture was added.

About KVM:

    • KVM is open source software, the full name is kernel-based virtual machine (kernel-based VMS).

    • Linux full virtualization solution with x86 architecture and hardware support for virtualization technologies such as Intel VT or AMD-V.

    • It contains a core module Kvm.ko (Kvm-intel.ko or Kvm-amd.ko) that provides the underlying virtualization loadable for the processor.

    • KVM also requires a modified QEMU software (QEMU-KVM) as the upper control and interface of the virtual machine.

    • KVM can run multiple virtual machines at the same time without changing Linux or Windows mirroring (meaning that multiple virtual machines use the same mirror) and configuring a personalized hardware environment for each virtual machine (NIC, disk, graphics adapter ...). )。

    • In the mainstream Linux kernel, such as 2.6.20 above the kernel has already included the KVM core.

KVM Memory Management

KVM inherits many of the features of Linux system management memory, such as the memory allocated to virtual use can be swapped to swap space, the ability to use large memory pages for better performance, and the support of NUMA allows virtual machines to efficiently access larger memory spaces.

The KVM Intel-based EPT (Extendedpage Table) or AMD's RVI (Rapid virtualization Indexing) technology can support updated memory virtual functions, which reduces CPU occupancy and provides better of throughput.

In addition, KVM also uses the KSM (Kernel same-pagemerging) This kernel feature to achieve memory page sharing. KSM scans the memory of each virtual machine to find the same memory pages among the virtual machines and merges them into a separate page shared by the respective virtual machines. When a virtual machine attempts to modify the data on this page, KSM will re-provide it with a new copy of the page. In practice, the probability that the same memory pages will appear between virtual machines with the same guestos on the same physical host, such as shared libraries, kernels, or other memory objects, may be the same memory pages, so KSM technology can reduce memory consumption and improve overall performance.

KVM Components

KVM consists of two main types of components:

◇/DEV/KVM: The device node of the virtual machine is managed, and the program of user space can complete the management of the virtual machine's creation and startup through its IOCTL () system call set; it is a character device; Its main operations include:

Create a virtual machine;

Allocating memory for the virtual machine;

Registers for reading and writing Vcpus;

Injecting an outage into the vcpus;

Run Vcpus;

◇QEMU Process: A component that works in user space and is used to emulate the I/O class hardware Device of PC;

QEMU full name Quick Emulator. is a standalone virtual software that can run virtual machines independently (KVM is not required at all). Kqemu is the software's acceleration software. KVM does not require QEMU to perform virtual processing, but it requires virtual machine control on its upper management interface. The virtual machine is still powered by KVM.


Semi-virtualized Virtio components

650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M02/79/1E/wKioL1aJ4m_gHtXgAAB2JYuZmrU358.jpg "title=" Picture 1.jpg "alt=" Wkiol1aj4m_ghtxgaab2jyuzmru358.jpg "/>

Virtio is a semi-virtualized drive that achieves good I/O performance and can achieve almost the same I/O performance as native (i.e., native systems in non-virtualized environments). Therefore, when using KVM, it is generally recommended to use Virtio for better performance if both the host kernel and the client support Virtio. Of course, Virtio also has shortcomings, it must be the client to install a specific virtio driver so that it is running in a virtualized environment, and in accordance with the virtio of the specified format for data transmission, However, there may be some older Linux systems in the client that do not support virtio and mainstream Windows systems need to install specific drivers to support virtio. However, some newer Linux distributions, such as Rhel 6.3, Fedora 17, and so on, are compiled as modules by default for Virtio related drivers and can be used directly as clients virtio, and Virtio drivers for mainstream Windows systems are available for download.

Virtio is an abstraction of a set of generic analog devices in a semi-virtualized hypervisor. This setting also allows hypervisor to export a common set of emulated devices and make them available through a common Application interface (API). With semi-virtualized hypervisor, The guest operating system is able to implement a common set of interfaces that are emulated by a specific device after a set of back-end drivers. Back-end drivers do not need to be generic because they only implement the behavior required by the front end.

KVM Tool Stack

650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M02/79/20/wKiom1aJ4mXiC26oAAEjoQk443c231.jpg "title=" Picture 2.jpg "alt=" Wkiom1aj4mxic26oaaejoqk443c231.jpg "/>

Second, KVM virtualization platform Construction

1. Installation Preparation

Check to see if your hardware supports virtualization. Command:

Egrep ' (VMX|SVM) '/proc/cpuinfo

Attention:

    • The identity of the VMX or SVM will be the only line. In general, AMD has done a better job of virtualization.

    • I'm using VMware Workstation 10, and I've opened the virtualization engine in the CPU settings in the virtual machine's settings and selected the Intel vt-x/ept or Amd-v/rvi (V) option, such as:

650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M00/79/1F/wKioL1aJ5SrhvuNpAADHq9wY-1s547.jpg "title=" Qq20160104111616.jpg "alt=" Wkiol1aj5srhvunpaadhq9wy-1s547.jpg "/>

2. Installing KVM

Since the Linux kernel has already included KVM in the installation system, we only need to enable KVM in command line mode:

[[email protected] ~]# modprobe kvm_intel[[email protected] ~]# lsmod |grep kvmkvm_intel 54285 0 KVM 333172 1 Kvm_intel

3. Introduction to the components on which KVM virtual machine creation and management depends

The creation of a KVM virtual machine relies on QEMU-KVM:

Although the technology of KVM is quite mature and can isolate a lot of things, in some respects it is impossible to virtual the real machine. For example, the virtual network card, that time requires additional technology to complement, and QEMU-KVM is such a technology. It complements the lack of KVM technology and optimizes KVM performance.

We can also use Virt-manager, virt-viewer to manage virtual machines;

We also need to libvirt this important component when creating and managing a KVM virtual machine:

It is a series of library functions provided for other technical calls to manage virtual machines on the machine. Including a variety of virtual machine technologies, KVM, Xen and LXC, can call the Libvirt provides the API to manage the virtual machine. With so much virtual machine technology, why does it provide so much management functionality that. Because of its design concept, it is a drive-oriented architecture design. Any kind of virtual machine technology is developed to design the driver relative to this technology. In this way, different virtual machine technologies can use different drivers, and they will not affect each other directly, so it is easy to expand. Furthermore, LIBVIRT provides a programming interface for multiple languages, which can be programmed directly to invoke the external interface provided by Libvirt to implement the operation of the virtual machine. The IaaS in today's popular cloud computing is very closely related to the library. The idea of architecture design can be seen through it.

650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M01/79/21/wKiom1aJ53uxzIvkAACEOQphDxo665.jpg "title=" Picture 1.jpg "alt=" Wkiom1aj53uxzivkaaceoqphdxo665.jpg "/>

As you can see from this graph, there are many driver on the LIBVIRTAPI, and there is a driver for each virtual machine technology that serves as the wrapper interface between the virtual machine technology and the Libvirt. This design avoids the need for libvirt to design various interfaces for different virtual machine technologies, focusing primarily on the underlying implementation and providing external interface calls, while different virtual machine technologies do what they need by invoking the interface provided by Libvirt.

4. Install the required components for KVM

Yum install-y QEMU-KVM Libvirt Virt-manager

After the installation is complete, start the LIBVIRTD service:

Service LIBVIRTD Start

A bridge device is automatically started, which is equivalent to the HOST-ONLY host-only network device in VMware Workstation;

650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M01/79/21/wKiom1aJ6onwQ5YqAAGL0E-dHvQ836.jpg "title=" Qq20160104114355.jpg "alt=" Wkiom1aj6onwq5yqaagl0e-dhvq836.jpg "/>

Use the Bridge Management command to view:

# brctl Showbridge Namebridge IDSTP enabledinterfacesvirbr08000.5254006d26bbyesvirbr0-nic

Like the VMware Workstation we need to create a physical bridging device, you can use Virsh to create the Bridge Device Association NIC to the bridging device:

You need to shut down the NetworkManager service, boot up, and then create the bridging device and the associated NIC to the bridging device:

Virsh Iface-bridge eth0 br0

To view the operation of the bridging device and other network devices:

650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M01/79/22/wKiom1aJ62KwA8V2AAILlQPUpiE282.jpg "title=" Qq20160104114732.jpg "alt=" Wkiom1aj62kwa8v2aaillqpupie282.jpg "/>

Now that we've built our virtualization platform, we've started to create and manage virtual machines on the KVM virtualization platform, and we'll start by using QEMU-KVM to create and manage virtual machines.

Iii. using QEMU-KVM to manage KVM virtual machines

1, QEMU-KVM introduction

Qemu is a widely used open source computer emulator and virtual machine. When acting as an emulator, you can run operating systems and programs under another architecture (such as ARM) under one architecture, such as a PC. With the dynamic transformation, it can achieve high efficiency of operation. When used as a virtual machine, QEMU can enable virtual systems to achieve performance near physical machines by directly using the system resources of the real machines. QEMU supports virtualization in Xen or KVM mode. When using KVM, QEMU can be virtual x86, servers and embedded PowerPC, as well as s390 systems.

QEMU can use KVM when running the same target schema as the host schema. For example, when running qemu-system-x86 on an x86 compatible processor, KVM acceleration can be leveraged-providing better performance for host and client computers.

Qemu is composed of the following parts:

    • Processor Simulators (x86, PowerPC, and SPARC);

    • Simulation Equipment (video card, network card, hard disk, mouse, etc.);

    • A generic device used to connect an emulation device to a host device (a real device);

    • Description information of the simulator;

    • debugger;

    • User interface to interact with the simulator;

Libvirt-based tools such as Virt-manager and Virt-install provide a very convenient virtual machine management interface, but they have in fact been developed over two times to encapsulate QEMU-KVM tools. Therefore, the direct use of the QEMU-KVM command can also accomplish previous tasks.

2, the use of QEMU-KVM help

On RHEL6/CENTOS6, QEMU-KVM is located in the/usr/libexec directory. Because this directory is not part of the PATH environment variable, it cannot be used directly, which also prevents the ability to use QEMU directly to create and manage virtual machines. If you want to use a QEMU virtual machine, you can do so by linking/USR/LIBEXEC/QEMU-KVM to/USR/BIN/QEMU-KVM.

Ln-sv/usr/libexec/qemu-kvm/usr/bin/qemu-kvm

The QEMU-KVM command uses a format of "QEMU-KVM [options] [Disk_image]" with many options, but it can be broadly divided into the following categories.

Standard options;

USB option;

Display options;

I386 platform-specific options;

Network options;

character device options;

Bluetooth related options;

Linux system boot-specific options;

Debug/Expert mode options;

PowerPC special option;

SPARC32 special option;

Standard options for QEMU-KVM

The standard options for QEMU-KVM include the specified host type, CPU mode, NUMA, floppy drive device, optical drive device, and hardware device.

-name name: Set the virtual machine name,-m machine: Specifies the type of host to impersonate, such as STANDARD PC, isa-only pc, or INTEL-MAC, you can use the QEMU-KVM  -m ? " Get all supported types;-m megs: Set the RAM size of the virtual machine;-cpu model: Set the CPU model, such as Coreduo, qemu64, etc., you can use "QEMU-KVM -CPU ?" Get all supported models;-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: Sets the index number of the different devices in the same controller type, namely the identification number;   media=media: Defines the media type as hard disk or CD-ROM (CDROM);   snapshot=snapshot: Specifies the current hard drive deviceWhether snapshot is supported: On or Off;  cache=cache: defines how the physical machine cache is used to access block data with a usable 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 uses a character, and the devices supported by different architectures and their representation characters are not the same, on the X86 PC architecture, A, b means the floppy drive, C for the first drive, D for the first optical drive device, and the N-P for the network adapter; The default is the hard disk device ;-boot order=dc,once=d


















This article is from the "Little Water Drop" blog, please make sure to keep this source http://wangzan18.blog.51cto.com/8021085/1731324

CentOS 6.5 Installation of KVM virtualization

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.