KVM virtualization platform deployment (theory)

Foreword:

The US Environmental Protection EPA report once counted a set of statistics: EPA researched the energy efficiency of servers and data centers and found that in fact, servers are only working 5% of the time, and the rest of the time has been in a dormant state.

Software resources are not as high as hardware resources (stable and efficient) (same function)

1. KVM virtualization technology

通过虚拟化技术将一台计算机虚拟为多台逻辑计算机, 在一台计算机上同时运行多个逻辑计算机,
同时每个逻辑计算机可运行不同的操作系统,应用程序都可以在相互独立的空间内运行而互相不影响,从而提高计算机的工作效率。
1、在一个操作系统中(win10)模拟多个操作系统(centos、win10、suse),同时每个操作系统可以跑不同的服务(nginx和tomcat),从而实现一台宿主机搭建一个集群
2、通过软件/应用程序的方式,来实现物理硬件的功能
例:ensp以软件形式实现物理设备的功能(二层交换机、路由器、三层交换机等)、workstation等

2. Development of Virtualization Technology

Prototype

  • In 1961, the IBM709 machine implemented a time-sharing system, which divided the CPU usage into multiple extremely short time slices (1/100sec). Each time slice performed different tasks. By polling these time slices, a CPU Disguised as multiple CPUs
  • In 1972, IBM officially named the time-sharing system of the system370 machine as a virtual machine
  • In 1990, the system 390 machine introduced by IBM supports logical partitioning (a cpu is divided into multiple, independent of each other, that is, logical partitioning)

Xen

  • Coming out in 2003, an external hypervisor/VMM program (virtual machine management program) can control the host and allocate resources to multiple clients
  • Supported virtualization technology: full virtualization, para-virtualization

KVM

  • It came out in 2007 and is now built into the kernel. Supported virtualization technology: full virtualization

Three, virtualization features

1. Advantages

1. Centralized management (remote management, maintenance)
2. Improve hardware utilization (low utilization of physical resources, such as peak, virtualization solves "idle" capacity)
3. Dynamic adjustment of machine/resource configuration (virtualization reduces system Separation of application and service hardware to improve flexibility)
4. High reliability (additional functions and solutions can be deployed to improve application environments such as transparent load balancing, migration, recovery and replication)

2. Disadvantages

1. High upfront costs (initial hardware support)
2. Reduce hardware utilization (in certain scenarios, such as extremely resource-intensive applications may not be suitable for virtualization)
3. Greater error impact (local physical machine down opportunities cause virtual machines Are unavailable, and all files in the virtual machine may be damaged)
4. Complex implementation and configuration, complicated management (difficulty in operation and maintenance and troubleshooting of management personnel)
5. Certain restrictions (virtualization technology involves various restrictions and must be supported/ Compatible with virtualization-compatible servers, applications and vendors to use together)
6. Security (the security risks of virtualization technology itself)

3. Case

VMwareWorkstation: Use software to achieve virtual multi-operating systems
VirtualBox: Use software to virtualize multiple physical device functions

Take VMware
workstation as an example: workstation supports the virtualization technology of Intel and AMD.
Hardware-assisted virtualization technology Intel-VT-x, AMD-V

Intel VT-x technology mainly includes the virtualization technology of == CPU, memory and I/O ==, while providing optimized processing (in the early days to make up for the defects of X86 architecture virtualization)
AMD-V is a system architecture for x86 processors A set of hardware extensions and hardware-assisted virtualization technologies can simplify software-only virtualization solutions

Improve the design of VMM (virtual machine monitor), make full use of hardware resources, and improve the virtualization efficiency of servers and data centers.
VMM (virtual machine monitor/management program) haperivisor
VMM is a system software that can maintain multiple high-efficiency, The isolated program environment (virtual machine) can manage the real resources of the computer system and provide an interface for the virtual machine.

4. VMM function

1. Logical division of physical resources (converted into virtual resources)
2. Calling virtual resources for applications (virtual machines)

Four, KVM introduction

Generalized KVM: KVM (Kernel-based Vritual Machine) ---------- Kernel-based virtual machine

  • KVM is an open source Linux native full virtualization solution based on virtualized extended X86 hardware (requires CPU to support Intel-VT x or AMD-V)
  • KVM is embedded in the kernel module to simulate the processor and memory to support the operation of the virtual machine
    -the virtual machine is implemented as a regular Linux process, which is scheduled by the standard Linux scheduler;
    -each virtual CPU of the virtual machine is implemented as a regular Linux process. This allows KMV to use the existing functions of the Linux kernel
  • However, KVM itself does not perform any simulation, and requires a client space program (virtual machine) to pass ==/dev/kvm== (this virtual device needs to be turned on hardware-assisted virtualization to see) The interface sets a client virtual server's address space , And Qemu simulates I/O (ioctl) for resource scheduling and maintenance management
  • Libvirt: KVM management tool, in addition to managing VMMs such as KVM, it can also manage Xen, VirtualBox, and even the bottom layer of OpenStack
  • Libvirt consists of 3 components: background daemon program libvirtd, API library, command line tool virsh

Five, KVM architecture and principles

(1) KVM virtualization architecture / three modes

1、Customer model(guestOS): The OS in the VM is the
mode in which the GuestOS client runs in the operating system. The client is divided into kernel mode and user mode. The functions are as follows:
2.User mode:
Provide users with user space tools for virtual machine management and perform I/O on behalf of users. Qemu works in this mode (the main function of Qemu)
3.linux kernel mode
Simulate CPU and memory, realize the switch of client mode, deal with the launch from client mode, KVM runs in this mode

(2) Principle of KVM

1. Guest: The guest system, including CPU (vCPU), memory, drivers (Console, network card, I/O device driver, etc.),
is run in a restricted CPU mode by KVM.
2. The KVM kernel module simulates the processor and memory to support virtual machine operation
3. Qemu mainly handles I/O and provides customers with a user space /dev/kvm tool libvirt for virtual machine management

ioctl (definition): a system call dedicated to device input and output operations
libvirt: KVM management tool The
above constitutes a complete virtualization platform

Simple understanding :

The KVM driver provides processor, memory virtualization, and guest I/O interception. After guest I/O is intercepted, it is handled by Qemu.
Qemu uses the interface libkvm to call (ioctl) the virtual machine device interface /dev/kvm. Allocate resources, manage and maintain virtual machines

Six, KVM workflow

The user-mode Qemu uses the interface libkvm to enter the kernel mode through the ioctl system call. The KVM driver creates a virtual CPU and virtual memory for the virtual machine, then executes the VMLAU-NCH instruction to enter the guest mode, loads the Guest OS and runs. If an abnormality occurs during the operation of the Guest OS, the operation of the Guest OS is suspended, the current state is saved, and the kernel mode is exited to handle these abnormalities.
When the kernel mode processes these exceptions, if I/O is not required, it will re-enter the client mode after the processing is completed. If I/O is needed, then enter the user mode, then Qemu will handle the I/O, after the processing is completed, enter the kernel mode, and then enter the client mode

Guess you like

Origin blog.csdn.net/panrenjun/article/details/114868542