All new Registrations are manually reviewed and approved, so a short delay after registration may occur before your account becomes active.
Installing, configuring & deploying KVM VPS on your dedicated server manually through command line
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:
http://lowendtalk.com/discussion/32361/installing-configuring-kvm-on-ovh-with-solusvm#latest
Just use that for setting up interfaces only as rest of the steps to install & deploy KVM servers are same as in this tutorial.
Special thanks to my friend @overtake for helping me with everything Linux, virtualization & technology related over the years & @MCHPhil for helping me with lot of hosting related things especially related to KVM.
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:
# yum update
Once done, please restart 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:
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
# 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
# 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:
# 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:
# 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:
#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:
# /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 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:
`# 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
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:
# 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.
# 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:
# 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 to tried to cover everything briefly in this tutorial, you may PM me if you experience any problems.
Comments
One question that I have: Is it possible to change the CPU model via virsh command line ? I've already tried to find it but no success...
I have never found anything like that myself despite going through tons of documentation regarding virsh but you can increase/decrease number of CPUs using the following command:
virsh setvcpus vpsname numberofcpus
Changing cpu affinity is also possible but if I manage to find anything related to changing cpu model via virsh command line, I will let you know for sure.
virsh edit follow by this (http://libvirt.org/formatdomain.html#elementsCPU)?
We already know that, @shrubbles might know it as well but what he wanted to ask was "changing cpu model with virsh command line" by using a simple command, for example it could be :
virsh vpsname cpumodel passthrough
There is no such thing AFAIK.
On qemu, I think, there is a command to change CPU model:
http://superuser.com/questions/390941/how-do-i-use-the-cpu-option-in-qemu
http://libvirt.org/formatdomain.html#elementsCPU
http://wiki.gentoo.org/wiki/QEMU/Options
qemu -cpu "model name" ?
Well only well known way is this:
http://docs.fedoraproject.org/en-US/Fedora_Draft_Documentation/0.1/html/Virtualization_Deployment_and_Administration_Guide/sect-libvirt-dom-xml-cpu-model-top.html
You have to edit.xml file from that domain(vps)
Humm, thanks. I will try this at home.
Thanks!!! I'm looking for something like this.
In Server4You's dedicated servers, you don't find br0 configurations. Any alternatives or solutions to this?
It is the bridge configuration file which you have to create yourself, when you type
# nano /etc/sysconfig/network-scripts/ifcfg-br0
it gets created but to make it stay permanently, save it after editing by pressing CTRL + X
It's all saved and I followed exactly your step. When I restart network, it gets stuck in shutting down eth0, and then connection timed out. Then, I can't log in the server to had to re-format it.
What subnet do you have and are you sure HWADDR & UUID are correct for both your primary & secondary interfaces(they have to be different)?
Are you sure they have normal routing at server4you unlike OVH & Hetzner?(Someone confirm it please)?
All are correct. I think I must've messed up somewhere in the gateway, will re-do this steps with documentation and will let you know.