KVM is a kernel-based hypervisor which grows quickly in maturity and popularity in the Linux server market. Red Hat officially dropped Xen in favor of KVM since RHEL. With KVM being officially supported by Red Hat, installing KVM on RedHat-based systems should be a breeze.
In this tutorial, I will describe how to install and configure KVM and VirtManager on CentOS. To use this tutorial, it is not required to have CentOS desktop environment. This tutorial was in fact tested on CentOS 7 server.
Check Hardware Virtualization Supoort
KVM requires hardware virtualization support such as Intel VT or AMD’s AMD-V, which are instruction set extensions for hardware-assisted virtualization. Check if hardware virtualization support is available on CentOS host machine:
If CPU flags contain „vmx“ or „svm“, it means hardware virtualization support is available.
Disable SELinux
Before installing KVM, be aware that there are several SELinux booleans that can affect the behavior of KVM and libvirt. In this tutorial, I’m going to set SELinux to „disable“ for demonstration purpose. If you do not wish to change SELinux mode, refer to the documentation on KVM SELinux booleans.
To disable SELinux on CentOS:
Edit this line
Reboot the machine for the change to take effect.
Install KVM, QEMU and user-space tools
Install KVM and virtinst (a tool to create VMs) as follows:
Start libvirtd daemon, and set it to auto-start:
Check if KVM has successfully been installed. You should see no error as follows.
Configure Linux Bridge for VM Networking
Installing KVM alone does not allow VMs to communicate with each other or access external networks. You need to configure VM networking separately. In this tutorial, I am going to set up „bridged networking“ via Linux bridge.
Install a package needed to create and manage bridge devices:
Disable Network Manager service if it’s enabled, and switch to default net manager as follows.
To configure a new bridge, you have to pick an active network interface (e.g., eth0), and enslave it to the bridge. Depending on whether the network interface is assigned an IP address via DHCP or statically, there are two different ways to configure a new bridge.
To configure bridge br0 with a static IP address:
edit /etc/sysconfig/network-scripts/ifcfg-eth0
edit /etc/sysconfig/network-scripts/ifcfg-br0
Note that the configuration for the enslaved interface (eth0) does not have „BOOTPROTO“ field, but „BRIDGE“ field added.
Once configuration files are generated accordingly, run the following to activate the change.
You should now see br0 bridge interface with a proper IP address as follows.
Install VirtManager
The final step is to install a desktop UI called VirtManager for managing virtual machines (VMs) through libvirt.
To install VirtManager:
If you are using CentOS desktop, you should be able to launch VirtManager locally at this point, by simply running:
However, if you are using CentOS server without desktop UI, follow these steps to launch VirtManager.
Enable X11 forwarding on SSH server:
Next list xauth
and finally add the result
Then connect to your CentOS server from a separate desktop machine, and run the wrapper script vm to launch VirtManager remotely.
In the end it is necessary to add the following rule :
Install monitoring