Thursday, July 12, 2012

Openvz installation


1 Installing OpenVZ
In order to install OpenVZ, we need to add the OpenVZ repository to yum:
cd /etc/yum.repos.d

wget http://download.openvz.org/openvz.repo
rpm --import http://download.openvz.org/RPM-GPG-Key-OpenVZ

yum search ovzkernel
yum install ovzkernel
then place the openvz kerel in the first position of the grub.conf file

title CentOS OpenVZ (2.6.18-53.1.19.el5.028stab053.14)
root (hd0,0)
kernel /vmlinuz-2.6.18-53.1.19.el5.028stab053.14 ro root=/dev/VolGroup00/LogVol00
initrd /initrd-2.6.18-53.1.19.el5.028stab053.14.img

Install vps utilities
for 32 bit
yum install vzctl vzquota

for 64 bit
yum install vzctl.x86_64 vzquota.x86_64

Open /etc/sysctl.conf and make sure that you have the following settings in it:
[...]
net.ipv4.ip_forward = 1
net.ipv4.conf.default.proxy_arp = 0
net.ipv4.conf.all.rp_filter = 1
kernel.sysrq = 1
net.ipv4.conf.default.send_redirects = 1
net.ipv4.conf.all.send_redirects = 0
net.ipv4.icmp_echo_ignore_broadcasts=1
net.ipv4.conf.default.forwarding=1
[...]

If you need to modify /etc/sysctl.conf, run
sysctl -p

The following step is important if the IP addresses of your virtual machines are from a different subnet than the host system's IP address. If you don't do this, networking will not work in the virtual machines!

Open /etc/vz/vz.conf and set NEIGHBOUR_DEVS to all:
NEIGHBOUR_DEVS=all

SELinux needs to be disabled if you want to use OpenVZ. Open /etc/sysconfig/selinux and set the value of SELINUX to disabled:
vi /etc/sysconfig/selinux
OR
vi /etc/selinux/config

SELINUX=disabled
# SELINUXTYPE= type of policy in use. Possible values are:
# targeted - Only targeted network daemons are protected.
# strict - Full SELinux protection.
SELINUXTYPE=targeted

then reboot