1, KVM introduction
1. Introduction to KVM
KVM The full name is kernel based virtual machine( Kernel-based Virtual Machine)，It's a Linux A kernel module that enables Linux Into a Hypervisor. KVM Originally by an Israeli company Qumranet(//Developed by kju'ma,net / /). KVM was officially incorporated into the Linux 2.6.20 core in February 2007 and became a part of the kernel source code. KVM Must have Intel VT or AMD-V Functional X86 Run on the platform. - It consists of Quramnet Development, the company was established in 2008 Red Hat Acquisition - It supports x86 (32 and 64 position), s390, Powerpc etc. CPU. - It from Linux 2.6.20 The first mock exam is included as a module. Linux In the kernel. - It needs to support virtualization extensions CPU. - It is completely open source.[Official website](http://www.linux-kvm.org/page/Main_Page).
2. Advantages of KVM
KVM This is an open source project KVM It has always been an open attitude, and many new virtualization technologies are the first in the world KVM And then promote it to other virtualization engines. KVM Back Linux This big tree, and Linux The system is closely combined in Linux New technologies on the can be applied immediately KVM Come on. around KVM Is an open source ecological chain, from the bottom Linux System, to the middle layer Libvirt Management tools, to cloud management platform OpenStack，That's not the case.
KVM One motivation that attracts many people is performance. Under the same hardware conditions, it can provide better virtual machine performance, mainly because KVM The architecture is simple, with only 20000 lines of code. It supports hardware virtualization from the beginning. These technical features ensure KVM Performance.
KVM Because it is an open source project, most of them KVM All solutions are free, with KVM The development of, KVM Virtual machines are becoming more and more stable and compatible, so they have been used more and more.
Extensive free technical support
Free doesn't mean KVM No technical support. stay KVM The number of open source communities is huge KVM Technical supporters can provide KVM technical support. In addition, if you need commercial support, you can also buy red hat's services.
3. PK between KVM and common enterprise virtualization products
At present, there are four common enterprise virtualization products: VMware, HyperV, Xen and KVM.
2, Evolution of virtualization technology
The evolution of virtualization technology can be divided into three stages: software simulation, virtualization layer translation and container virtualization.
Among them, virtualization layer translation can be divided into:
- Full virtualization based on binary translation, that is, full virtualization of software.
- Transform the virtual machine system kernel and add the translation of virtualization layer, that is, semi Virtualization (super virtualization or operating system assisted virtualization).
- Hardware assisted translation, that is, hardware assisted virtualization.
1. Technical mode of software simulation
Software simulation is to completely simulate CPU, chipset, disk, network card and other computer hardware through software, as shown in the figure below.
[the external chain image transfer fails. The source station may have an anti-theft chain mechanism. It is recommended to save the image and upload it directly (img-XhEyEDm0-1622158530876)(images/QEMU virtual architecture. png)]
2. CPU operation level
The X86 platform instruction set is divided into four privilege modes (ring[r) ɪŋ]): Ring0, Ring1, Ring2 and Ring3. The operating system generally uses ring0 level, the application uses Ring3 level, and the driver uses Ring1 and Ring2 levels.
[the external chain picture transfer fails, and the source station may have an anti-theft chain mechanism. It is recommended to save the picture and upload it directly (img-TpPtDsec-1622158530879)(images/X86cpu instruction level. png)]
How does the virtual machine realize Guest CPU through VMM[ ɡ est]CPU) access to hardware has three implementation technologies according to different principles:
Full virtualization of software
Hardware assisted full virtualization
3, Virtualization architecture classification
1. Sojourn structure
Sojourn architecture( Hosted Architecture [ˈɑːrkɪtektʃər] Architecture) is to install and run virtualization programs on the operating system, which depends on the support of the host operating system for devices and the management of physical resources.
2. Bare metal structure
Bare Metal Architecture ("Bare [ber] Metal [ˈmetl] " Architecture) It is to install virtualization software directly on the hardware, then install the operating system and applications on it, and rely on the virtual layer kernel and server console for management. Representative products: xen server , VMware ESXi,RHEV(Red Hat Enterprise[ˈentərpraɪz] virtualization )
4, List of functions of KVM
The functions supported by KVM include:
1.support CPU and memory Hyperfractionation( Overcommit [ˈoʊvər kəˈmɪt] Over commitment) 2.Support for semi virtualization I/O (virtio) 3.Support hot plug( cpu，Block devices, network devices, etc.) 4.Support symmetric multiprocessing( Symmetric Multi-Processing，Abbreviated as SMP，A collection of processors on a computer(many CPU)，be-all CPU Share all resources, such as bus, memory and I/O There is only one copy of the operating system or management database. One of the biggest features of this system is to share all resources. Multiple CPU There is no difference between them. They have equal access to memory, peripherals and an operating system. SMP The main problem of the server is that its expansion capacity is very limited. Experiments show that, SMP The server CPU The best utilization is 2 to 4 CPU . 5.Support real-time migration( Live Migration) 6.support PCI Equipment direct distribution and single I/O Virtualization( Single Root I/O Virtualization(SR-IOV) allow Windows Operating system and Microsoft Hyper-V or VMware of ESXi etc. hypervisor Disk to server I/O Equipment, such as now SR-IOV Encapsulate, manage and even share network card devices.) 7.Support kernel merging on the same page( KSM )( In short, it is to merge the same memory, so that the physical machine can run more virtual machines.) 8.support NUMA (Non-Uniform Memory Access，Inconsistent storage access architecture, a computer architecture technology, which consists of multiple SMP The server is connected through a certain node Internet, works together and completes the same tasks. From the perspective of users, it is a server system. Its basic feature is that it consists of multiple SMP The server ( each SMP Server called node ) Each node only accesses its own local resources ( Memory, storage, etc ) ，Is a completely shared (Share Nothing) Structure.)
5, KVM tool set
KVM main tools:
1.libvirt: Operation and management KVM Virtual machine virtualization API，use C Language, which can be written by Python,Ruby, Perl, PHP, Java And other languages. Possible operations include KVM，VMware，XEN，Hyper-v, LXC etc. Hypervisor. 2.Virsh: be based on libvirt Command line tools for( CLI) 3.Virt-Manager: be based on libvirt of GUI tool 4.virt-v2v: Virtual machine format migration tool 5.virt-* Tools: including Virt-install (establish KVM Command line tool of virtual machine), Virt-viewer - - (Tools connected to the virtual machine screen), Virt-clone(Virtual machine cloning tool), virt-top etc. 6.sVirt: Safety tools and selinux relevant