KVM virtualization platform installation and creation of virtual machines

1. Introduction to KVM

KVM official website

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:

[External link image transfer failed, the source site may have an anti-leeching mechanism, it is recommended to save the image and upload it directly (img-UV25yANt-1693024166455) (D:\MD Archives\IMG\image-20230826093654954.png)]

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:

insert image description here

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:

[External link image transfer failed, the source site may have an anti-leeching mechanism, it is recommended to save the image and upload it directly (img-XXOC6QA5-1693024166456) (D:\MD Archives\IMG\image-20230826095144884.png)]

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/isothe directory. I take the CentOS7.5 system as an example, as shown in the figure below:

[External link picture transfer failed, the source site may have an anti-leeching mechanism, it is recommended to save the picture and upload it directly (img-QCDDqEYE-1693024166456) (D:\MD Archives\IMG\image-20230826100222344.png)]

2. Create a CentOS7.5 system virtual machine

1. Open the virt-manager management page

virt-manager

2. Create two storage pools

[External link image transfer failed, the source site may have an anti-theft link mechanism, it is recommended to save the image and upload it directly (img-QI3ukfaw-1693024166456) (D:\MD Archives\IMG\image-20230826101237091.png)]

[External link picture transfer failed, the source site may have an anti-theft link mechanism, it is recommended to save the picture and upload it directly (img-PXOb0Zh8-1693024166456) (D:\MD Archives\IMG\image-20230826102507829.png)]

[External link image transfer failed, the source site may have an anti-leeching mechanism, it is recommended to save the image and upload it directly (img-mFVHCRbA-1693024166456) (D:\MD Archives\IMG\image-20230826102545135.png)]

[External link picture transfer failed, the source site may have an anti-leeching mechanism, it is recommended to save the picture and upload it directly (img-dXP5AVSi-1693024166456) (D:\MD Archives\IMG\image-20230826102531910.png)]

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.

[External link image transfer failed, the source site may have an anti-leeching mechanism, it is recommended to save the image and upload it directly (img-mAMLIxej-1693024166457) (D:\MD Archives\IMG\image-20230826103739821.png)]

[External link picture transfer failed, the source site may have an anti-theft link mechanism, it is recommended to save the picture and upload it directly (img-rdY9MpY9-1693024166457) (D:\MD Archives\IMG\image-20230826103752010.png)]

3. Create a storage volume (virtual machine disk)

[External link image transfer failed, the source site may have an anti-theft link mechanism, it is recommended to save the image and upload it directly (img-eYOTijJn-1693024166457) (D:\MD Archives\IMG\image-20230826103904647.png)]

[External link picture transfer failed, the source site may have an anti-theft link mechanism, it is recommended to save the picture and upload it directly (img-DvBX6B7A-1693024166457) (D:\MD Archives\IMG\image-20230826103911870.png)]

4. Create a new virtual machine

virt-manager

[External link picture transfer failed, the source site may have an anti-theft link mechanism, it is recommended to save the picture and upload it directly (img-Ch9CxXbd-1693024166457) (D:\MD Archives\IMG\image-20230826104117541.png)]

[External link image transfer failed, the source site may have an anti-leeching mechanism, it is recommended to save the image and upload it directly (img-mMmpPXaJ-1693024166458) (D:\MD Archives\IMG\image-20230826104122903.png)]

Select the ISO system image file:

[External link image transfer failed, the source site may have an anti-leeching mechanism, it is recommended to save the image and upload it directly (img-O2Mf4UrN-1693024166458) (D:\MD Archives\IMG\image-20230826104128338.png)]

The resource configuration of the virtual machine is planned according to the demand:

[External link image transfer failed, the source site may have an anti-leeching mechanism, it is recommended to save the image and upload it directly (img-WpD0CZJb-1693024166458) (D:\MD Archives\IMG\image-20230826104132882.png)]

Select the disk volume for the virtual machine:

[External link picture transfer failed, the source site may have an anti-theft link mechanism, it is recommended to save the picture and upload it directly (img-7dHOczbP-1693024166459) (D:\MD Archives\IMG\image-20230826104137291.png)]

Specify the virtual machine name and resource confirmation:

[External link picture transfer failed, the source site may have an anti-leeching mechanism, it is recommended to save the picture and upload it directly (img-2qWup9pk-1693024166459) (D:\MD Archives\IMG\image-20230826104142036.png)]

After the completion, start to install the virtual machine, as shown below:

[External link picture transfer failed, the source site may have an anti-theft link mechanism, it is recommended to save the picture and upload it directly (img-ZHY5lxcy-1693024166459) (D:\MD Archives\IMG\image-20230826104146063.png)]

Guess you like

Origin blog.csdn.net/weixin_45310323/article/details/132510255