Article directory
1. Introduction to KVM
KVM (Kernel-based Virtual Machine) is an open source virtualization technology that allows multiple virtual machines to run on the same physical host. KVM is a modular function provided by the Linux kernel. It realizes the sharing and management of hardware resources by dividing the physical host into multiple virtual machines and assigning independent resources to each virtual machine.
KVM is based on the processor-based virtualization technology (Intel VT or AMD-V), which can directly use the processor's virtualization extension instruction set to improve the performance of the virtual machine. KVM provides a complete virtualization environment, including virtualized CPU, memory, disk, and network devices, so that virtual machines can run various operating systems and applications like independent physical machines.
KVM is an open source Linux-native full virtualization solution for X86 hardware based on virtualization extensions (Intel VT or AMD-V) . In KVM, 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 enables KVM to use existing features of the Linux kernel. However, KVM itself does not perform any hardware emulation, requiring a guest space program to set up a guest virtual server's address space via the /dev/kvm interface, provide it with simulated I/O, and map its video display back to the host's display Screen. Currently this application is QEMU.
2. Install the KVM virtualization platform
Note: To install the KVM virtualization platform, the CPU needs to support virtualization, and it needs to be set in the BIOS. This is generally enabled by default. If it is in VMware Workstation, the virtualization function of the CPU also needs to be enabled, as shown in the figure below:
1. Method 1: When installing the operating system, add the virtualization function
1. Check the following three options when installing the operating system, as shown in the figure below:
2. Install the autocompletion command
yum install bash-completion libvirt-bash-completion -y
2. Method 2: Based on the existing system, install the virtualization function
yum groupinstall "GNOME 桌面" -y # 安装GNOME桌面环境
yum install qemu-kvm -y # KVM核心模块
yum install qemu-kvm-tools -y # KVM调试工具,可以选择性安装
yum install qemu-img -y # 允许你创建、转换和修改镜像,能处理被qemu支持的所有镜像格式
yum install libvirt -y # 管理虚拟机的工具包
yum install virt-install -y # virt-install是一个使用libvirt库构建新虚拟机的命令行工具
yum install virt-manager -y # 图形界面管理虚拟机
yum install bridge-utils -y # 配置linux以太网桥
yum install bash-completion libvirt-bash-completion -y # 安装自动补全命令
3. Verify that the KVM installation is correct
1. Verify whether the CPU supports the virtualization function, and return non-zero to indicate support
egrep -c "(vmx|svm)" /proc/cpuinfo
2. Check whether the KVM module is installed
lsmod | grep kvm
systemctl status libvirtd
The following figure indicates support:
3. Create a virtual machine
1. Environment preparation before creating a virtual machine
1. Turn off the firewall
systemctl stop firewalld
systemctl disable firewalld
setenforce 0
sed -i 's/SELINUX=[e|p].*/SELINUX=disabled/g' /etc/sysconfig/selinux
2. Create two directories for storing the disk and ISO image of the virtual machine
mkdir /root/kvm/{
iso,vm} -p
3. Upload the ISO system image to /root/kvm/iso
the directory. I take the CentOS7.5 system as an example, as shown in the figure below:
2. Create a CentOS7.5 system virtual machine
1. Open the virt-manager management page
virt-manager
2. Create two storage pools
Create another mirrored storage pool in the same way, name it as qinzt-test-iso
, and place the directory as /root/kvm/iso
, which is used to store the iso CD image file used by the KVM virtual machine in the future.
3. Create a storage volume (virtual machine disk)
4. Create a new virtual machine
virt-manager
Select the ISO system image file:
The resource configuration of the virtual machine is planned according to the demand:
Select the disk volume for the virtual machine:
Specify the virtual machine name and resource confirmation:
After the completion, start to install the virtual machine, as shown below: