Complete Guide: Installation & Configuration of KVM Server

Overview

This tutorial providing you KVM introduction, Installation and Configuration steps and how to run a virtual machine on KVM. Everyone knows about the Virtualisation but most of the virtual applications are paid you will only have 30 days of the free period to work on that application. But KVM is an exception for this, You will have it for free to setup as well as you will work on it without any limitations.

Today, I will share you some important points about the KVM server and steps to install & configure same on a Linux system.

KVM Server :

KVM stands for Kernal-based virtual Machine. It is a virtualization software which is used to setup multiple guest machine or virtual machines. You can use it from the command line as well as in graphical view. It will work on 64 Bit hardware like intel 64 or AMD 64. In simple words, it is a Linux kernel module that gives access to the hardware virtualization features of AMD & Intel.

Features of KVM:

You will find many new features of KVM when you start working on this. I share some them which I experienced while working on KVM.

1. Easy To Use
2. Good Graphical Interface
3. Live snapshots and Live Storage Migration
4. Lower Costs
5. Open to all
6. Advanced Security

System details which I used to install and configure KVM:

1. OS : Ubuntu 14.04.5
2. RAM : 8GB
3. CPU : 8CORE

Software Package needs for KVM:

1. webvirtmgr
2. supervisor
3. libvirt-bin
4. nginx

Steps To Install KVM Server:

1. Update Repository

Before start with the actual installation run apt-get update command to update repository.

$ apt-get update

2. Check System is compatible for Virtualization

Before start installation of KVM server make sure the system on which your installing KVM is compatible with virtualization or not. To check compatibility run below command. This command produces output with two values,

If the output is 0 then the system is not compatible for KVM.
If output is 1 or higher value then system is compatible for KVM

$ egrep -c '(vmx|svm)' /proc/cpuinfo

Another way to check compatibility, install cpu-checker which provide you "kvm-ok" command. when you run this command and output is like given below then you will start with the next step to install KVM server.

$ apt-get install cpu-checker
$ kvm-ok
Output : INFO: /dev/kvm exists
KVM acceleration can be used

3. Install KVM Packages

After checking compatibility you need to install below-mentioned dependency packages. This package will help to run KVM on the system.

$ apt-get install git python-pip python-libvirt python-libxml2 novnc supervisor nginx

4. Install WebVirMgr

Webvirmgr :

WebVirtMgr is a libvirt-based Web interface for managing virtual machines. It allows you to create and configure new domains, and adjust a domain's resource
allocation. A VNC viewer presents a full graphical console to the guest domain. KVM is currently the only hypervisor supported.

Technology:

The application logic is written in Python & Django. The LIBVIRT Python bindings are used to interacting with the underlying hypervisor.

Steps to Install WebVirtMgr:

1. Download the source from git

$ cd /var/www/
$ git clone git://github.com/retspen/webvirtmgr.git

2. Install & configure webvirtmgr

$ cd /var/www/webvirtmgr/
$ pip install -r requirements.txt

$ ./manage.py syncdb


Enter the user information:
You just installed Django's auth system, which means you don't have any superusers defined.
Would you like to create one now? (yes/no): yes (Put: yes)
Username (Leave blank to use 'admin'): admin (Put: your username or login)
E-mail address: username@domain.local (Put: your email)
Password: xxxxxx (Put: your password)
Password (again): xxxxxx (Put: confirm password)
Superuser created successfully.

$ ./manage.py collectstatic

You have requested to collect static files at the destination
location as specified in your settings.

This will overwrite existing files!
Are you sure you want to do this?

Type 'yes' to continue, or 'no' to cancel: yes [put: yes]

3. Nginx Configuration

Now create "webvirtmgr.conf" file under the nginx directory and add below mentioned lines.

vim /etc/nginx/sites-available/webvirtmgr.conf
server {
listen 80 default_server;

server_name $hostname;
#access_log /var/log/nginx/webvirtmgr_access_log;

location /static/ {
root /var/www/webvirtmgr/webvirtmgr; # or /srv instead of /var
expires max;
}

location / {
proxy_pass http://127.0.0.1:8000;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-for $proxy_add_x_forwarded_for;
proxy_set_header Host $host:$server_port;
proxy_set_header X-Forwarded-Proto $remote_addr;
proxy_connect_timeout 600;
proxy_read_timeout 600;
proxy_send_timeout 600;
client_max_body_size 1024M; # Set higher depending on your needs
}
}

Enable the configuration:

$ ln -s /etc/nginx/sites-available/webvirtmgr.conf /etc/nginx/sites-enabled/

check nginx user and apply user rights to webvirtmgr directory

$ ps -aux |grep nginx
$ chown -R www-data:www-data /var/www/webvirtmgr
$ /etc/init.d/nginx restart

4. Setup Supervisor

Create a file "/etc/supervisor/conf.d/webvirtmgr.conf" and add below configuration to this file.

vim /etc/supervisor/conf.d/webvirtmgr.conf

[program:webvirtmgr]
command=/usr/bin/python /var/www/webvirtmgr/manage.py run_gunicorn -c /var/www/webvirtmgr/conf/gunicorn.conf.py
directory=/var/www/webvirtmgr
autostart=true
autorestart=true
stdout_logfile=/var/log/supervisor/webvirtmgr.log
redirect_stderr=true
user=www-data

[program:webvirtmgri-novnc]
command=/usr/bin/python /var/www/webvirtmgr/console/webvirtmgr-novnc
directory=/var/www/webvirtmgr
autostart=true
autorestart=true
stdout_logfile=/var/log/supervisor/webvirtmgr-nonvc.log
redirect_stderr=true
user=www-data

Restart supervisor service:

$ service supervisor stop
$ service supervisor start

5. Stop and Remove novnc if available

$ service novnc stop
$ update-rc.d -f novnc remove
$ rm /etc/init.d/novnc

6. Create libvirt user

This user and password use when you open the webvirtmgr graphical console on the browser.

$ saslpasswd2 -a libvirt admin
$ sasldblistusers2 -f /etc/libvirt/passwd.db


7. Check Below values enable or available in libvirtd.conf file

$ grep listen_ /etc/libvirt/libvirtd.conf
listen_tls = 0
listen_tcp = 1
auth_tcp = "sasl"

vim /etc/default/libvirt-bin
libvirtd_opts="-d -l"

8. Restart libvirt-bin service

$ /etc/init.d/libvirt-bin restart

9. Check libvirtd running with netstat and ps command

netstat -lntp | grep libvirtd

tcp 0 0 0.0.0.0:16509 0.0.0.0:* LISTEN 28878/libvirtd
tcp6 0 0 :::16509 :::* LISTEN 28878/libvirtd

ps aux | grep libvirtd

root 28878 0.0 2.3 372720 12028 ? Sl 08:35 0:00 /usr/sbin/libvirtd -d -l

10. virsh command to confirm system is connected with qemu/tcp and running properly

$ virsh -c qemu+tcp://System-IP/system nodeinfo

11. Open Graphical Console in Browser

Run below url to open graphical console which helps you to add remove instance and storage or new virtual machine in KVM.

http://System-IP/
kvm server

I hope you like the article if you find any difficulties then please do comment your queries or problem via the comment section, till then stay tuned to techthings.org for more such valuable articles. 

Latest Comments
  1. Kumar Nikhil November 25, 2016
  2. Andrey February 12, 2017

Leave a Reply

Your email address will not be published. Required fields are marked *