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

    51
    28
    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:

     

    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:


     

    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

    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

     

    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

     

    Now we have to enable IP forwarding:

     

     


    Code:
    # nano /etc/sysctl.conf 

     

    Next step is disabling the redirect messages:

     


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

     

     

    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
     

    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

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

    DomainBop Dormant VPSB Pathogen

    2,260
    2,190
    Oct 11, 2013
  3. devonblzx

    devonblzx New Member Verified Provider

    259
    119
    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:

    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
    
     
  4. Shoaib_A

    Shoaib_A Member

    51
    28
    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