First, KVM Introduction
The KVM full name is kernel-based virtual machine (kernel-based VM), an open-source system virtualization module that is fully virtualized based on hardware, but requires hardware support (such as Intel VT Technology or AMD V technology).
Second, KVM installation configuration
1. Preparatory work
1.1 Shutting down the iptables firewall
[[Email protected] ~]# service iptables stop//Stop iptables
1.2 CPU enabled Virtualization
Need to turn on virtualization in the BIOS, which is usually turned on by default
2. Installing a KVM virtual machine
2.1 See if the CPU supports KVM full virtual machines
[Email protected] ~]# Cat/proc/cpuinfo | grep ' VMX '//intel CPU judgment method
[Email protected] ~]# Cat/proc/cpuinfo | grep ' SVM '//AMD CPU judgment method
Select the method according to the corresponding CPU model, if the information can appear, it means that the CPU supports KVM full virtual machine
2.2 Installing KVM and other virtualization-required management software packages
[Email protected] ~]#
Yum install-y KVM virt-* libvirts bridge-utils qemu-img
KVM: The package contains a KVM kernel module that provides the KVM hypervisor in the default Linux kernel
Libvirts: Installing virtual machine management tools, using commands such as Virsh to manage and control virtual machines
Bridge-utils: Setting up network card bridging
virt-*: Create, clone virtual machine commands, use the QEMU command to create disks, and so on.
QEMU-IMG: Installs the QEMU component, uses the QEMU command to create the disk, and so on.
Modprobe Kvm-intel//Load KVM module
Lsmod | grep KVM//See if the KVM module is loaded
Reboot//restart
3. Create and install a KVM virtual machine on the host host
3.1 Creating the image file directory and virtual disk storage directory
[Email protected] ~]# Mkdir/iso
[Email protected] ~]# mkdir-p/data/kvmdisk/
3.2 Copy the system ISO file to the ISO directory
This can be downloaded via FTP or by mount.
3.3 Creating a virtual machine
[Email protected] ~]# virt-install-n ubuntu-r 512-vcpus=1-s 50-c/iso/ubuntu.iso--hvm--os-type=ubuntu-f/DATA/KVM Disk/ubuntu.img--graphics vnc,listen=0.0.0.0,port=7789--force--autostart
Command explanation:
Create a virtual machine called Ubuntu, memory size of 512 memory, 1 cpu,50g hard disk, installation image is/iso/ubuntu.iso designated as full virtualization, System type for Ubuntu designated virtual machine hard disk as/data/kvmdisk/ Ubuntu.img, simultaneous configuration of VNC ports for 7789 automatic start of installation
Virt-install parameter Description:
-N--name= Virtual machine name
-R--ram= Memory allocated by the virtual machine
-U--uuid= the UUID of the virtual machine
--vcpus=2 Specify the number of 2 Vcpus
-V--HVM Full dummy He
-P--paravirt Semi-virtualized
-L--LOCATION=LOCALDIR Installation Source
--vnc using VNC
You can use "--graphics vnc,listen=listen,..."
--vncport Specify VNC monitoring port, default port is 5900, port cannot be reused
--vnclisten specifying the VNC bound IP
-C--cdrom= Optical drive or installation path
-S--file-size= uses the size of the disk image in GB
-F--file= files used as disk images
--disk= using different options as disk usage installation media
--force Prevent interactive prompts
--os-variant specifying the operating system type
--accelerate acceleration
--network network type, used here is the default, it is generally used to be bridge bridging
3.4 Creating a disk file for a KVM virtual machine
[Email protected] ~]# qemu-img create-f qcow2-o preallocation=metadata kvm_test.img 10G
Command explanation:
Create a Qcow2 virtualized image format with a size of 10G and a file name of kvm_test.img
Virsh command-line administration Tools
Command line:
Virsh List #显示本地活动虚拟机
Virsh List–all #显示本地所有的虚拟机 (active + inactive)
Virsh define Ubuntu.xml #通过配置文件定义一个虚拟机 (this virtual machine is not active yet)
Virsh start Ubuntu #启动名字为ubuntu的非活动虚拟机
Virsh Create Ubuntu.xml #创建虚拟机 (once created, the virtual machine executes immediately and becomes the active host)
Virsh suspend Ubuntu #暂停虚拟机
Virsh Resume Ubuntu #启动暂停的虚拟机
Virsh shutdown Ubuntu #正常关闭虚拟机
Virsh destroy Ubuntu #强制关闭虚拟机
Virsh undefine Ubuntu #移除ubuntu虚拟机
Virsh dumpxml Ubuntu #显示虚拟机的当前配置文件
Virsh setmem Ubuntu 512000 #给不活动虚拟机设置内存大小
Virsh setvcpus Ubuntu 4 # Set the number of CPUs for an inactive virtual machine
Build OPENSTACK,KVM Environment Preparation