Wednesday, 20 August 2014

Getting started with KVM- Installation and Configuration

Getting Started with KVM
Part 1: Installation and Configuration

In this set of tutorial, I'll be walking you through simple steps to setup your own Virtualization Platform using KVM (Kernel-based Virtual Machine)

NOTE: before we begin, make sure that your host system has a functional Intel VT or AMD-V flag set. This is essential for creating Virtual Machines on your Host system. 

To check if your hardware supports virtualization capability run the following command in the terminal of your Linux Host:

# grep -E "vmx|svm" /proc/cpuinfo

If you get a positive result for the above grep command, you are good to go. 

In this tutorial, Ill be installing KVM on a CentOS 6.5 Host. The host has 2 NIC cards attached to it, both having static IP Addresses. One NIC is going to be used as a Public Interface (Meant for providing Internet access to the VMs), and the other a Private (Meant for running the VMs on an isolated network)

Public Interface (eth0):
Private Interface (eth1):

You will need at least 20-30GB of free HDD Space on your KVM Host. This will be used to by the VMs deployed on KVM.

There are two ways to install the required KVM packages on your CentOS Host. You can use either of the two commands to get started:

1) Using groupinstall - Installs a large group of packages specifically required for KVM

# yum groupinstall "Virtualisation Tools" "Virtualization Platform"

2) Using individual package names: Kind of tedious method, but gets KVM installed never the less

# yum install kvm qemu-kvm python-virtinst libvirt libvirt-python virt-manager libguestfs-tools

Once the packages are installed, the nest thing to do is to start up the libvirtd service. libvirtd program is the server side daemon component of the libvirt virtualization management system. Type the following to start the service:

# service libvirtd start

# chkconfig libvirtd on

You can verify the libvirtd service has started or not by typing the following commands:

# service libvirtd status

# virsh -c qemu:///system list

NOTE: If you get any errors at this stage then it means that something went wrong with your KVM installation. Kindly go back and check. DO NOT PROCEED without rectifying the errors at this point.

Next, we install bridge-utils. This package contains utilities for configuring the Linux Ethernet bridge. The Linux Ethernet bridge can be used for connecting multiple Ethernet devices together.

# yum install bridge-utils

IMP: Now in my case, I will be designing the Network Bridge in such as way that the br0 (Bridge Interface connected to eth0) provides my VMs with Internet access and br1 (Bridge interface connected to eth1) provides the VMs internal access to all the other VMs connected on the LAN. 

A small representation of the setup is shown below:

Next, edit the /etc/sysconfig/network and add the GATEWAYDEV parameter as shown. In my case, I'm routing all my Internet based traffic via br0.

# cat /etc/sysconfig/network

Next, update /etc/sysconfig/network-scripts/ifcfg-eth0 as shown:

# vi /etc/sysconfig/network-scripts/ifcfg-eth0


Save the file and exit the editor

# vi /etc/sysconfig/network-scripts/ifcfg-eth1


Save the file and exit the editor

Next, create/edit the /etc/sysconfig/network-scripts/ifcfg-br0 file to setup br0 (Public Interface)

# vi /etc/sysconfig/network-scripts/ifcfg-br0

Save the file and exit the editor

Similarly, create/edit the /etc/sysconfig/network-scripts/ifcfg-br1 file to setup br1 (Private Interface)

# vi /etc/sysconfig/network-scripts/ifcfg-br1

Save the file and exit the editor

Restart the Network. Make sure ou do not get any errors on the Interface.

# service network restart

You can check whether the changes have taken effect, run an ifconfig and make sure the Bridged Interfaces have obtained the correct IPs

You can further verify the Bridge connections using the following commands:

# brctl show

# ip route

If you got it till this far then kudos!! You are now ready to create and launch your VMs!!

Next Post: Getting Stated with KVM: Part 2- Creating VMs

No comments :

Post a Comment

Note: only a member of this blog may post a comment.