The construction of KVM virtualization platform

Article directory

1, Introduction to KVM principle

  • The generalized KVM actually consists of two parts, one is the KVM kernel module based on LINUX kernel support, the other is Qemu after simplification and modification.
    • KWM core module simulates processor and memory to support the operation of virtual machine. Qemu mainly deals with I/0 and provides users with a user space tool to manage virtual machine. They combine with each other to form a complete virtualization platform.
  • Note: Qemu itself is not a part of KVI. Qemu is a complete set of virtualization solution, which is realized by pure software, including processor virtualization, memory virtualization and Simulation of various virtual devices. However, because it is simulated by pure software, the performance of Qemu is relatively low.

2, Three modes of KVM runtime

Customer mode: it can be simply understood as the mode of the client running in the operating system. The customer mode can be divided into kernel mode and user mode.

User mode: provide user space tools for virtual machine management and execute I/0 on behalf of users. Qem runs in this mode.

Kernel mode: simulate CPU and memory, realize the switch of customer mode, and handle the exit from customer mode. KVI kernel module runs in this mode.

The hierarchical diagram of the three modes is shown in the figure below.

3, kvm deployment process

3.1 kvm deployment topology

3.2 environment deployment before KVM installation

1. Create a new virtual machine in VMware software and install centos7 system

  • Be careful:
    • Number of processors: 2 cores per processor: 2 total cores per processor: 4
    • Virtualization Intel VT-X option √
    • Memory size is 16G network NAT mode sound card and printer remove mounting CD-ROM hard disk 1TG
    • Install GNOME desktop development tools partition auto assign install operating system
      The specific installation of CentOS 7 is not detailed here. There are many articles on the Internet.

2. centos7 system start optimization and KVM environment preparation

1,Configuration static IP Address, guarantee and nat Consistent network segments in mode
vi /etc/resolv.conf
//Ensure Internet access

2,Mounted CD
vi /etc/fstab
/dev/sr0   /mnt   iso9660  defaults   0   0
mount -a

3,Turn off firewall
systemctl stop firewalld
systemctl disable firewalld
setenforce 0

4,Turn off core protection
sed -i '7s/enforcing/disabled/' /etc/sysconfig/selinux
cat /etc/sysconfig/selinux 

5,To configure yum Local source
[root@localhost ~]# cd /etc/yum.repos.d/
[root@localhost yum.repos.d]# mkdir backup
[root@localhost yum.repos.d]# mv C* backup/
[root@localhost yum.repos.d]# ls
[root@localhost yum.repos.d]# vim local.repo
//Enter the following information
[root@localhost yum.repos.d]# yum clean all	   #Empty yum warehouse
[root@localhost yum.repos.d]# yum makecache	#Load yum data

3.3. Install KVM and network configuration

1. Install some required software

yum groupinstall -y "GNOME Desktop"   #To install GNOME desktop environment, if the GUI is installed, you don't need to install it
yum -y install qemu-kvm               #Install KVM module
yum -y install qemu-kvm-tools         #Install KVM debugging tools
yum -y install virt-install           #Command line tools for building virtual machines
yum -y install libvirt                #Virtual machine management tools
yum -y install virt-manager            #Graphical interface management virtual machine

2. Check

Check if the CPU supports virtualization
cat /proc/cpuinfo | grep vmx          

Check whether KVM module is installed
lsmod | grep kvm  

ln -sf /lib/systemd/system/ /etc/systemd/system/ 
Change the default running target of the system to

Turn on libvirtd service and set power on and self start
systemctl start libvirtd
systemctl enable libvirtd 

Restart system

3. Set up KVM network
After the host server is installed with KVM, the network must be set first. There are two ways to run the KVM network in libvirt:
NAT and Bridge, the default is NAT.

User mode, that is, NAT mode. This mode is the default network. Data packets are sent through the host interface in NAT mode
Transfer, you can access the external network, but you cannot access the virtual machine network from the external.
Bridge mode, which allows the virtual machine to own the network as an independent host, and the external machine can directly
Access to the virtual machine, but need network card support, general cable network card support.
Take Bridge for example.
Modify the ens33 network card

[root@localhost ~]# vim /etc/sysconfig/network-scripts/ifcfg-ens33
BRIDGE=br0   #Comment out the IP address, gateway and mask, and add br0
[root@localhost ~]# vim /etc/sysconfig/network-scripts/ifcfg-br0
IPADDR=   #Add IP address of NAT network segment

//Restart the network
systemctl restart network     

3.4 create kvm storage

1. Create image folder and upload image

mkdir -p /data_kvm/iso   
mkdir -p /data_kvm/store    #Directory stored by virtual machine

//Mount local shared folder
mount.cifs // /opt
cp CentOS-7-x86_64-DVD-1810.iso /data_kvm/iso/

[root@localhost Linux]# ls /data_kvm/iso/

//Click the following command in the GUI to open the virtual system manager
  • Create two storage pools iso and store
    Double click to open QEMU/KVM - storage - add (plus sign) - fill in the name - move forward - browse - other location - Computer - Data - KVM - store - Open - finish. Use the same method to create the image storage pool. The selected folder is / data - KVM / ISO.

  • Create storage volume
    Add storage volumes to the storage pool, with the maximum capacity of 20G
  • Create virtual machine
    Open virtual system manager - right click QEMU/KVM - select new

Default local installation media - forward

Select ISO image - browse to select the image you just created - forward

Select the configuration of CPU: 2G, memory: 2048M

Select the location of the storage volume

Click Customize configuration before installation - select network (bridge) - Finish

Click the boot option - check the start virtual machine when the host Boots - start the installation - the default is

Change the partition and remove the home directory.

DHCP is required to automatically assign an IP address, so in virtual machine configuration, select nat mode and open the network,
Note: to remember the assigned IP address, use it later

Choose minimize installation

After that, set the root password and wait for installation.
Here our KVM has been completed!!!

85 original articles published, 34 praised, 5865 visited
Private letter follow

Tags: network yum CentOS vim

Posted on Sun, 15 Mar 2020 06:29:48 -0400 by md7dani