To implement Linux-based services in any modern infrastructure it is required that you have at least one available hypervisor to virtualize the workloads. If you're unclear as to what the role of a hypervisor is, please see the following video for further explanation:
In regards to linux-based Type I Hypervisors, there are two platforms that dominate the market; Xen and KVM. For this tutorial I am going to be focusing on the installation and configuration of KVM and QEMU on Ubuntu 16.04 LTS. While RHEL/CentOS are the most common choice of distribution for implementing a Hypervisor of this type (and there are numerous tutorials out there covering the process), I'm choosing to use Ubuntu because it is a favorite of many developers. By running KVM on your development machine instead of a more taxing Type II hypervisor like Virtualbox, you can improve overall performance and resource utilization.
Before we get started, there are several items of importance that you will need to note:
- Your processor will have to be capable of virtualization, and if it is you will need to verify the capability is enabled in BIOS prior to installing/configuring your hypervisor.
- You'll need adequate resources for running your virtual machines. Generally you will want the hardware you are installing your hypervisor on to have at least 8GB of memory, 4 CPU cores, and adequate storage for your hypervisor and virtual disks.
- For reliability you will want to consider implementing some sort of redundancy on the physical volumes that store your virtual machines. This may be going as far as implementing hardware/software RAID, or at the very least backing up the storage to an external source.
For this tutorial I am using a Lenovo TS440 Thinkserver with a single quad core 3.4GHz Intel Xeon E3-1245 v3 processor and 24GB of ECC DDR3 memory. Storage on the server is configured in two RAID 1 arrays across four disks using the installed LSI SAS RAID controller. The first array is a pair of 250GB 7200rpm HDDs (/dev/sda), and the second array is a pair of 2 TB 7200rpm HDDs (/dev/sdb).
I am not going to cover the specifics on creating RAID volumes/arrays using the LSI controller. However, I will link information on doing so in the REFERENCES section at the bottom of this page. Also note that it is common practice to install to and boot your Hypervisor from either a USB drive or SD card. For this tutorial I am going to be installing the Hypervisor OS to the 250GB "sda" drive instead. I already have these drives installed and do not have another use planned for them at this time. In a regular production environment I would implement a different configuration that more closely follows and conforms to best practices.
Install and Configure Ubuntu 16.04 LTS Server
Installing Ubuntu 16.04 LTS Server edition is not a difficult process and I'll not go into great detail on specifics. If you need a detailed tutorial please see the following video:
You're going to be doing a basic installation, choosing "use entire disk and setup LVM" when you get to the choice of installation target, and make sure you select your installation drive as the target for installing the GRUB boot loader.
For my system I'll be installing Ubuntu to /dev/sda and also selecting /dev/sda from the list of options as the target for the GRUB boot loader installation. My user account that will be used for this tutorial is going to be "Demo Administrator", with the login name of "dadmin".
Other than that, as a time saver, you should also go ahead and install OpenSSH Server whenever you get to the portion of the installation that allows you to add additional tasks/services to base install.
Once you're finished follow the final prompts and remove the installation media and reboot into your fresh installation. Do a quick package update/upgrade to get all default packages and services to the latest and greatest build, and then we'll move on to installing and configuring KVM-QEMU.
dadmin@kvm-host:~$ sudo apt-get update && sudo apt-get dist-upgrade -y
Install and Configure KVM-QEMU
At this point you should have Ubuntu 16.04 Server installed with all packages up-to-date. We'll move forward by installing all the necessary packages to make the server a fully functioning KVM Hypervisor.
First, lets double check that our server is capable of running KVM.
dadmin@kvm-host:~$ egrep -c 'vmx' /proc/cpuinfo
If the command returns 0, you will not be able to install KVM on the system. In that case double check BIOS settings and ensure you've got virtualization capabilities enabled.
Assuming your system passes the above check, we'll require the following packages to properly configure/run our KVM Hypervisor:
- qemu-kvm <-- KVM hypervisor and QEMU hardware emulation
- libvirt-bin <-- libraries used to interface with KVM
- bridge-utils <-- facilitates the creation and management of the bridged network interface used by KVM virtual machines.
dadmin@kvm-host:~$ sudo apt-get install qemu-kvm libvirt-bin bridge-utils ubuntu-vm-builder
You should now have all of the necessary components in place to start creating KVM virtual machines. However, before we do that we'll want to setup a bridged network interface so your newly created virtual machines can be accessed directly from your network.
Configure a Bridged Network Interface
For this example I'm going to use the eno1 interface, configuring it with bridge br0. First, we need to open the network interface file. To edit this file I am going to use VI text editor, please feel free to use whatever text editor you are most comfortable using.
dadmin@kvm-host:~$ sudo vi /etc/network/interfaces
Your interfaces file should look a lot like the following:
# This file describes the network interfaces available on your system # and how to activate them. For more information, see interfaces(5). source /etc/network/interfaces.d/* # The loopback network interface auto lo iface lo inet loopback # The primary network interface auto eno1 iface eno1 inet dhcp
We will need to set eno1 in manual mode, and then create an entry that defines bridge br0. After the changes your file should closely resemble the following, with your respective unique network configuration entries (DNS, Gateway, IP Addresses, etc...).
# This file describes the network interfaces available on your system # and how to activate them. For more information, see interfaces(5). source /etc/network/interfaces.d/* # The loopback network interface auto lo iface lo inet loopback # The primary network interface auto eno1 iface eno1 inet manual # The bridged network interface on eno1 auto br0 iface br0 inet static address 10.10.1.20 netmask 255.255.0.0 network 10.10.1.0 broadcast 10.10.1.255 gateway 10.10.1.1 dns-nameservers 10.10.1.3 10.10.1.4 126.96.36.199 dns-search yourdomain.com bridge_ports eno1 bridge_stp off bridge_maxwait 5
Once you have made the above changes take the eno1 interface down, bring it back up, and then bring up the newly created br0 bridged interface. verify connectivity by pinging a known host/ip address. (If you haven't established connectivity doublecheck your interfaces file for a syntax error and/or reboot the server and try again)
dadmin@kvm-host:~$ sudo ifdown eno1 && sudo ifup eno1 && sudo ifup br0 dadmin@kvm-host:~$ ping google.com dadmin@kvm-host:~$ ping 188.8.131.52
And that's it! You've now got a fully functioning Type I Hypervisor. In the next article I'll cover the basics of creating and managing virtual machines.
Configure RAID with LSI RAID Controller