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

Discussion in 'Tutorials and Guides' started by Shoaib_A, Aug 7, 2014.

  1. Shoaib_A

    Shoaib_A Member

    Dec 15, 2013
    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:


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


    # yum update

    Once done, please reboot your server:


    # yum reboot

    Type the following using SSH:


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

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


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


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


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

    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



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


    You may use to calculate netmask of your subnet & for knowing other details.


    Check if following is present:


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


    Now we have to enable IP forwarding:



    # nano /etc/sysctl.conf 


    Next step is disabling the redirect messages:


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



    Restart the network:


    # /etc/init.d/network restart

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


    # 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:


    # cd /tmp
    # wget

    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:


    # 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:


    # reboot

    Now we are ready to create our first KVM VPS:


    # 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




    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:


    # vi /etc/resolv.conf

    Save & Exit


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


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

    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:


    # 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: Aug 7, 2014
    drmike, HalfEatenPie and MannDude like this.
  2. DomainBop

    DomainBop Dormant VPSB Pathogen

    Oct 11, 2013
  3. devonblzx

    devonblzx New Member Verified Provider

    Oct 31, 2013
    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:

    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/' \
    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
  4. Shoaib_A

    Shoaib_A Member

    Dec 15, 2013
     To not confuse those who followed my previous tutorials(here as well as on other forums). What do you think of that kind of setting on OVH's network?
    Last edited by a moderator: Aug 9, 2014