amuck-landowner

Installing, configuring & deploying KVM VPS on your dedicated server manually through command line

Shoaib_A

Member
This tutorial will guide you how to install, configure & deploy KVM VPS on your dedicated server with using IPv4. I recommend  this only for learning, testing, personal or non-commercial use only. For commercial purposes, you should use a good control panel like SolusVM or Virtualizor. You need to have an Intel or AMD CPU which supports virtualization. Also, please do not try network interface settings in this tutorial with OVH or Hetzner servers as they will not work because with both these companies you need to use different settings for network interfaces. For configuring network interfaces on OVH's network you should go through my other tutorial:

 



 

Just use that for setting up interfaces only as rest of the steps to install & deploy KVM servers are same as in this tutorial.

 

 

Following assumptions have been made to make it easy for you to understand:


1.1.1.1 = Primary IPv4 of your server

 

2.2.2.1/29 = /29(8 IP addresses & also minimum recommended but it does not matter what subnet you have e.g /26, /25, /24 etc)IPv4 subnet assigned to your server

 

CentOS = Operating System

 

First of all, we should update our OS with following command using SSH:

 

Code:
# yum update
 

Once done, please reboot your server:

 


Code:
# yum reboot

 

Type the following using SSH:

 


Code:
# nano /etc/sysconfig/network-scripts/ifcfg-eth0

 

Remove everything which is there & type or paste the following:


DEVICE="eth0"

BOOTPROTO="none"

HWADDR="00:19:BB:24:9D:68"

ONBOOT="yes"

TYPE="Ethernet"

UUID="d6d38d7b-5936-4093-be64-3336c677bg89"

BRIDGE="br0"

 

Note: Please replace HWADDR & UUID with that of your server.

 

Once done, type Ctrl + X, select YES & Enter

 


Code:
# nano /etc/sysconfig/network-scripts/ifcfg-br0


DEVICE="br0"

BOOTPROTO="none"

DNS1="127.0.0.1"

GATEWAY="1.1.1.62"

HWADDR="00:19:BB:24:9D:68"

IPADDR="1.1.1.1"

IPV6INIT="yes"

NETMASK="255.255.255.192"

ONBOOT="yes"

TYPE="Bridge"

UUID="d6d38d7b-5936-4093-be64-3336c677bg89"

 

Note: Replace HWADDR, UUID, GATEWAY & NETMASK with that of your server. If you feel any difficulty, use ifconfig or contact your host & ask them the GATEWAY & NETMASK for your server.

 

Once done, type Ctrl + X, select YES & Enter

 

 


Code:
# nano etc/sysconfig/network-scripts/ifcfg-br0:1


DEVICE=br0:1

TYPE=Bridge

BOOTPROTO=static

IPADDR=2.2.2.2

NETMASK=255.255.255.248

ONBOOT=yes

DELAY=0

STP=off

 

You may use http://www.gestioip.net/cgi-bin/subnet_calculator.cgi to calculate netmask of your subnet & for knowing other details.

 

Check if following is present:

 


Code:
# nano /etc/sysconfig/network-scripts/route-br0


ADDRESS0=0.0.0.0

NETMASK0=0.0.0.0

GATEWAY0=1.1.1.62

 

Now we have to enable IP forwarding:

 

 


Code:
# nano /etc/sysctl.conf 


net.ipv4.ip_forward = 1

net.ipv6.conf.all.forwarding= 1

net.ipv6.conf.br0.forwarding = 1

net.ipv6.conf.default.forwarding = 1

 

Next step is disabling the redirect messages:

 


Code:
#nano /etc/sysctl.d/10-no-icmp-redirects.conf


net.ipv4.conf.all.send_redirects=0

net.ipv4.conf.default.send_redirects=0

net.ipv4.conf.br0.send_redirects=0

net.ipv4.conf.virbr0.send_redirects=0

 

 

Restart the network:

 


Code:
# /etc/init.d/network restart

 

Now we will install KVM, virt manager & some other tools:

 


Code:
# yum install qemu-kvm python-virtinst virt-top virt-viewr virt-manager libvirt libvirt-client


# lsmod|grep kvm


# modprobe kvm

 

Next step is downloading the ISO we are going to use with our KVM VPS that we are going to create later:

 


Code:
# cd /tmp


# wget http://mirror.ovh.net/ftp.centos.org/6.5/isos/x86_64/CentOS-6.5-x86_64-minimal.iso

 

Note: I have downloaded CentOS 6.5 from OVH mirror for demonstration purpose only. You may choose whatever mirror & OS you wish.

 

It is now better to remove virsh's default network flush iptables & restart libvirtd:

 


Code:
# virsh net-destroy default
# virsh net-undefine default
# service libvirtd restart
# iptables --flush 
# service iptables save
# service itpables restart

 

After this, please reboot the server:

 


Code:
# reboot

 

Now we are ready to create our first KVM VPS:

 


Code:
# virt-install --name=vps01 --disk path=/var/lib/libvirt/images/vps01.img,size=25 --vcpus=2 --ram=1024 --nographics --network bridge:br0:1 --cdrom=/tmp/CentOS-6.5-x86_64-minimal.iso --os-type=linux --os-variant=rhel6

 

This will create a KVM vps with 1 GB RAM, 2 CPU cores & 25 GB disk space. You may change the name of VPS according to your wishes, I have chosen vps01 in the above example.

 

Next you will see virsh console. Quickly press TAB + SPACE & configure console in the following way

 

                                       

Code:
 console=ttyS0
 

Note: You have to do the above step real quick.

 

Next you will see configuration options for your OS install. Go through the steps & complete the install in your desired way. I chose reinitialize all, use entire disk, write changes to disk to get done with options quickly.

 

After installation is complete, next is using vi text editor to configure interfaces & nameservers so that our VPS is able to connect to internet. Some of useful commands for vi are as follows:

 

:wq= save

:q = quit

i= insert text before cursor until ESC is hit(Edit)

 

In your VPS type the following in virsh screen:

 


Code:
# vi /etc/resolv.conf
nameserver 8.8.8.8

nameserver 8.8.4.4

 

Save & Exit

 

Note: I have used google public DNS as nameservers, you may use others if you wish.

 


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


DEVICE=eth0

HWADDR=52:54:00:97:A5:D8

TYPE=Ethernet

UUID=4cbebd65-83be-464e-a745-8d0bd0ab413g

ONBOOT=yes

BOOTPROTO=static

IPADDR=2.2.2.3

NETMASK=255.255.255.248

GATEWAY=2.2.2.2

 

Note: Replace HWADDR & UUID with that of your VPS.

 

After that reboot the VPS. After this network should work perfectly on VPS & you may connect to it using an SSH client.

 

Some useful virsh commands are as follows:

 

virsh console vpsname

virsh suspend vpsname

virsh start vpsname

virsh reboot vpsname

virsh stop vpsname

 

If you wish to terminate/destroy a VPS, you may do so using the following commands:

 


Code:
# virsh destroy vps01
# virsh undefine vps01
# cd /var/lib/libvirt/images
# rm vps01.img

 

Note: Replace vps01 with whatever the name of your vps is.

 

I have tried to cover everything briefly in this tutorial, you may PM me if you experience any problems.
 
Last edited by a moderator:

devonblzx

New Member
Verified Provider
Why did you include a br0:1 alias?  I don't see that serving a purpose in this install.

To make the networking more simple, you could just do this, as recommended on the CentOS Howto:

Code:
cp -p /etc/sysconfig/network-scripts/ifcfg-{eth0,br0}
sed -i -e'/HWADDR/d' -e'/UUID/d' -e's/eth0/br0/' -e's/Ethernet/Bridge/' \
/etc/sysconfig/network-scripts/ifcfg-br0
echo DELAY=0 >> /etc/sysconfig/network-scripts/ifcfg-br0
echo 'BOOTPROTO="none"' >> /etc/sysconfig/network-scripts/ifcfg-eth0
echo BRIDGE=br0 >> /etc/sysconfig/network-scripts/ifcfg-eth0
 
Top
amuck-landowner