Detailed explanation of KVM virtualization technology theory

1. Virtualization technology

Insert picture description here

  • Virtualize a computer into multiple logical computers through virtualization technology, and run multiple logical computers on one computer at the same time.
  • At the same time, each logical computer can run different operating systems, and application programs can run in mutually independent spaces without affecting each other, thereby improving the work efficiency of the computer.
  • The various physical resources of the computer (CPU, memory, disk space, network adapter, etc.) are abstracted, transformed and presented and can be partitioned and combined into one or more computer configuration environments.
  • As a result, the inseparable barriers between physical structures are broken, and users can use these computer hardware resources in a better way than the original configuration. The new virtual part of these resources is not restricted by the way existing resources are erected, geographical or physical configuration.
  • Generally referred to as virtualized resources include computing power and data storage.

1. Commonly used virtualization software

VMwar Workstation

  • Multiple operating systems (such as centos, win10, suse) can be simulated in one operating system (win10), and each operating system can run different services (nginx+tomcat), thereby realizing a host to build a cluster .
  • Realize the functions of physical hardware by means of software/applications.

ensp

  • Realize the functions of physical devices in the form of software (such as: Layer 2 switches, routers, Layer 3 switches, etc...)

2. Development of virtualization technology

  • 1963: IBM 709 machine implements a time-sharing system, which divides the CPU usage into multiple extremely short time slices (1/100sec). Each time slice performs different tasks. By polling these time slices, one CPU disguised as multiple CPUs
  • 1972: IBM officially named the time-sharing system of the system370 machine as a virtual machine
  • 1990: The system390 machine launched by IBM supports logical partitioning (divide a CPU into multiple copies, independent of each other, that is, logical partitioning)
  • 2003: Xen came out, which is an external hypervisor/VMM program (virtual machine management program) that can control the host and allocate resources to multiple clients
  • 2007: KVM came out and is now built into the Kernel kernel
  • Virtualization technologies supported by Xen: full virtualization, para-virtualization
  • Virtualization technology supported by KVM: full virtualization

3. Type

Full virtualization

  • Full Virtualization (Full Virtualization) is also known as the original virtualization technology
  • All physical hardware resources are abstracted by software (virtualization), and finally a unified allocation call is made
  • Use a virtual machine to coordinate the Guest operating system and the original hardware. VMM is used for work coordination between the Guest operating system and the bare hardware. Some protected instructions must be captured and processed by the Hypervisor.
  • That is, use hypervisor (VMM) software to establish an abstraction layer between the underlying hardware and the server
  • Full virtualization runs faster than hardware simulation, but the performance is not as good as bare metal, because Hypervisor takes up some resources

Paravirtualization

  • Para Virtualization (Para Virtualization) is another technology similar to full virtualization. It uses Hypervisor to share access to the underlying hardware, but its Guest operating system integrates virtualization code
  • This method does not need to be recompiled or cause traps, because the operating system itself can cooperate well with the virtual process
  • Para-virtualization requires some modifications to the guest operating system to make the guest operating system aware that it is in a virtualized environment, but para-virtualization provides performance similar to the original operating system

Through

  • Ability to directly call hardware resources
  • From the current point of view, the development is not perfect due to too many constraints

4. Classification of virtualization technologies

Platform Virtualization

  • Virtualization for computers and operating systems.

Resource Virtualization

  • Virtualization of specific system resources, such as memory, storage, network resources, etc.

Application Virtualization

  • Including simulation, simulation, interpretation technology, etc.

5. Advantages of virtualization

1. Reduce operating costs

  • Server virtualization reduces the operating cost of IT infrastructure, frees system administrators from the heavy management of physical servers, OS, middleware, and compatibility, reduces the frequency of manual intervention, and makes management more powerful and convenient.

2. Reduce energy consumption

  • By reducing the number of physical servers in operation and reducing the power consumption of units other than the CPU, the goal of energy saving and emission reduction is achieved.

3. Dynamic resource scheduling

  • In server virtualization technology, the data center has changed from a traditional single server to a unified resource pool. Users can instantly adjust virtual machine resources. At the same time, data center management programs and data center administrators can flexibly use the internal resources of the virtual machine. Flexible allocation and adjustment of resources to virtual machines.

4. Speed ​​up application deployment

  • The server virtualization technology only needs to enter the activation configuration parameters, copy the virtual machine, start the virtual machine, and activate the virtual machine to complete the deployment, which greatly reduces the deployment time, eliminates manual intervention, and reduces deployment costs.

5. Improve resource utilization

  • Through the integration of server virtualization, the utilization rate of CPU, memory, storage, network and other equipment is improved, while ensuring the availability of original services, so that their security and performance are not affected.

6. Improve application compatibility

  • The encapsulation and isolation provided by server virtualization enable a large number of applications to run independently in various environments. Managers do not need to frequently adjust applications according to the underlying environment, but only need to build an application version and publish it to different types of platforms after virtualization Just go on.

7. Improve service availability

  • Users can easily back up the virtual machine. After the virtual machine is dynamically migrated, the backup can be easily restored, or the backup can be run on other physical machines, which greatly improves the availability of services.

6. Disadvantages of virtualization

1. High upfront expenses

  • Initial hardware support, virtualization still has high performance requirements

2. Reduce hardware utilization

  • Certain scenarios such as extremely resource-intensive applications may not be suitable for virtualization. After all, virtualization will reduce performance somewhat.

3. Greater error impact

  • When the local physical machine is down, none of the virtual machines will be available. At the same time, all the files in the virtual machine may be damaged, a single point of failure

4. Complex implementation configuration and complex management

  • Difficulty in operation and maintenance and troubleshooting of management personnel, which consumes a lot of manpower and material resources

5. Certain restrictions

  • Virtualization technology involves various restrictions and must be used in conjunction with servers, applications, and vendors that support/compatible virtualization, and involves the development of underlying/company source code.

6. Security

  • The hidden dangers of virtualization technology itself

Two. KVM

A brief history of virtualization
Insert picture description here
KVM stands for Kernel-based Virtual Machine (Kernel-based Virtual Machine), which is a kernel module of Linux, which makes Linux a Hypervisor

1 Overview

  • Developed by Quramnet, the company was acquired by Red Hat in 2008.
  • KVM is open source software
  • It is a Linux full virtualization solution with x86 architecture and hardware support virtualization technology (such as intel VT or AMD-V)
  • Contains the loadable core module kvm.ko (kvm-intel.ko or kvm-AMD.ko) that provides the underlying virtualization for the processor
  • The modified QEMU software (qemu-kvm) is required as the upper-level control and interface of the virtual machine
  • Can run multiple virtual machines at the same time without changing the linux or windows image (it means that multiple virtual machines use the same image) and configure a personalized hardware environment for each virtual machine (network card, disk, graphics adapter... …) At the same time, KVM can also use ksm technology to help the host server save memory.

2.KVM architecture

User space, kernel space, and virtual machine on Linux

  • 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.
  • KVM: Runs in the kernel space, provides virtualization of CPU and memory, as well as client I/O interception. After guest's I/O is intercepted by KVM, it is handed over to QEMU for processing.
  • QEMU: The modified QEMU code for KVM virtual machines, which runs in user space, provides hardware I/O virtualization, and interacts with KVM through IOCTL /dev/kvm devices.

3. KVM support function list

  • Support CPU and memory overcommit (Overcommit)
  • Support para-virtualized I/O (virtio)
  • Support hot plug (cpu, block device, network device, etc.)
  • Support Symmetric Multi-Processing (Symmetric Multi-Processing, abbreviated as SMP)
  • Support Live Migration
  • Support PCI device direct allocation and single-root I/O virtualization (SR-IOV)
  • Support Kernel Same Page Merge (KSM)
  • Support NUMA (Non-Uniform Memory Access, non-uniform memory access structure)

4. KVM tools

tool Explanation
libvirt The virtualization API for operating and managing the KVM virtual machine is written in C language and can be called by Python, Ruby, Perl, PHP, Java and other languages. Can operate Hypervisors including KVM, vmware, XEN, Hyper-v, LXC, etc.
Virsh Command line tool (CLI) based on libvirt
Virt-Manager GUI tool based on libvirt
virt-v2v Virtual machine format migration tool
virt-* tools Including Virt-install (a command-line tool for creating KVM virtual machines), Virt-viewer (a tool for connecting to the virtual machine screen), Virt-clone (virtual machine cloning tool), virt-top, etc.
sVirt Security tools

4. Work flow

  • 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 exception occurs during the operation of the Guest OS, suspend the operation of the Guest OS, save the current state, and exit to the kernel mode to handle these exceptions.
  • When the kernel mode handles these exceptions, if I/O is not required, then 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

3. Build a KVM virtualization platform

1. Prepare the virtual machine

CPU RAM hard disk Network card operating system
Dual-core dual-thread-CPU virtualization enabled 8G 300G Single network card Centos 7.6 (1810)

Insert picture description here

2. Experimental environment

1、修改主机名
hostnamectl set-hostname kvm 
su -

2、环境优化
#设置DNS反向解析
#是否反解DNS,设置为NO可以让客户端连接服务器更快
vim /etc/ssh/sshd_config 
#115行取消DNS注释,改为NO

3、制作本地YUM仓库
mkdir /abc
cd /etc/yum.repos.d/
ls
mkdir bak
mv CentOS-* bak
ls

vim local.repo
[local]
name=kvm
baseurl=file:///abc
gpgcheck=0
enabled=1

yum clean all 
yum repolist

4、关闭防火墙、核心防护
systemctl stop firewalld
systemctl disable firewalld
setenforce 0

Insert picture description here

Insert picture description here
Insert picture description here

3. Install KVM

1.安装KVM基本组件
yum groupinstall -y "GNOME Desktop"       #安装 GNOME 桌面环境  如果装了图形界面可以不需要装
yum -y install qemu-kvm                   #KVM 模块
yum -y install qemu-kvm-tools             #安装KVM 调试工具,可不安装
yum -y install virt-install               #构建虚拟机的命令行工具
yum -y install qemu-img                   #qemu 组件,创建磁盘、启动虚拟机等
yum -y install bridge-utils               #网络支持工具
yum -y install libvirt                    #虚拟机管理工具
yum -y install virt-manager               #图形界面管理虚拟机	

#以下是安装的内容
yum groupinstall -y "GNOME Desktop"
yum -y install qemu-kvm
yum -y install qemu-kvm-tools
yum -y install virt-install
yum -y install qemu-img
yum -y install bridge-utils
yum -y install libvirt
yum -y install virt-manager

# 检测CPU是否支持虚拟化
cat /proc/cpuinfo | grep vmx          

# 查看KVM模块是否已安装
Lsmod:显示已载入的系统模块
lsmod | grep kvm

2. 设置开启启动界面的显示模式
ln -sf /lib/systemd/system/graphical.target 

Insert picture description here
Insert picture description here

4. Set up the KVM network

KVM网络的两种模式:
1.NAT: 默认设置,数据包由 NAT 方式通过主机的接口进行
传送,可以访问外网,但是无法从外部访问虚拟机网络
2.网桥:这种模式允许虚拟机像一台独立的主机一样拥有网络,外部的机器可以直接访问到虚拟机内部,但需要网卡支持(一般有线网卡都支持)

使用Bridge网桥模式进行部署
vim /etc/sysconfig/network-scripts/ifcfg-ens33

TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=none
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=no
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
NAME=ens33
UUID=d233fa1b-ad26-4a85-b731-414adce23447
DEVICE=ens33
ONBOOT=yes
BRIDGE=br0			     #删除原先地址,设置为网桥模式,关联br0网卡

#创建、编辑桥接网卡
vim /etc/sysconfig/network-scripts/ifcfg-br0
TYPE=Bridge
BOOTPROTO=static
DEFROUTE=yes
PEERDNS=yes
PEERROUTES=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_PEERDNS=yes
IPV6_PEERROUTES=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
NAME=br0
DEVICE=br0
ONBOOT=yes
IPADDR=192.168.222.10
NETMASK=255.255.255.0
GATEWAY=192.168.222.2

service network restart
#重启网卡

Insert picture description here
Insert picture description here

5. KVM deployment and management

#创建KVM存储和镜像数据的目录、上传centos7镜像
mkdir -p /data_kvm/iso
mkdir -p /data/_kvm/store
smbclient -L //192.168.222.1	
mount.cifs //192.168.222.1/LMX /mnt
cp -p CentOS-7-x86_64-DVD-1806.iso /data_kvm/iso/
#查看镜像
ll /data_kvm/iso/
总用量 4481024
-rwxr-xr-x. 1 root root 4588568576 2月  20 2019 CentOS-7-x86_64-DVD-1810.iso
# 使用虚拟系统管理器管理虚拟机
创建思路:
1.创建存储池(ISO、STORE)
2.添加存储卷
3. 创建虚拟机
virt-manager

Guess you like

Origin blog.csdn.net/LI_MINGXUAN/article/details/114576382