Install instructions for OpenVZ available at
http://wiki.openvz.org/Quick_installation
Here is what i done to install OpenVZ on CentOS 5 32 bit OS/
cd /etc/yum.repos.d
wget http://download.openvz.org/openvz.repo
rpm --import http://download.openvz.org/RPM-GPG-Key-OpenVZ
Find if OS is 32 or 64 bit using uname -a
# uname -a
Linux server84.hosthat.com 2.6.18-92.1.18.el5 #1 SMP Wed Nov 12 09:30:27 EST 2008 i686 i686 i386 GNU/Linux
#
In this case, i686 in uname -a result means the OS is 32 bit.
Now we will find list of openvz kernal available
# yum list|grep ovzkernel
ovzkernel.i686 2.6.18-128.1.1.el5.028stab062.3
ovzkernel-PAE.i686 2.6.18-128.1.1.el5.028stab062.3
ovzkernel-PAE-devel.i686 2.6.18-128.1.1.el5.028stab062.3
ovzkernel-devel.i686 2.6.18-128.1.1.el5.028stab062.3
ovzkernel-ent.i686 2.6.18-128.1.1.el5.028stab062.3
ovzkernel-ent-devel.i686 2.6.18-128.1.1.el5.028stab062.3
ovzkernel-xen.i686 2.6.18-128.1.1.el5.028stab062.3
ovzkernel-xen-devel.i686 2.6.18-128.1.1.el5.028stab062.3
#
We need to install .686 version of the kernel. Kernel with PAE is for servers with more than 4 GB of RAM.
We check memory available in the server with free -m
# free -m
total used free shared buffers cached
Mem: 2017 1662 355 0 175 1319
-/+ buffers/cache: 167 1850
Swap: 4071 0 4071
#
Its only 2 GB, so we can install non PAE kernel. For severs with more than 4 GB of RAM, always better to get 64 bit OS.
So we install
yum install ovzkernel.i686 ovzkernel-devel.i686
After install finished, we get
Installed: ovzkernel.i686 0:2.6.18-128.1.1.el5.028stab062.3 ovzkernel-devel.i686 0:2.6.18-128.1.1.el5.028stab062.3
To boot from this kernel, we need o configure boot loader, grub.
vi /boot/grub/grub.conf
The file contains
# grub.conf generated by anaconda
#
# Note that you do not have to rerun grub after making changes to this file
# NOTICE: You have a /boot partition. This means that
# all kernel and initrd paths are relative to /boot/, eg.
# root (hd0,0)
# kernel /vmlinuz-version ro root=/dev/hde3
# initrd /initrd-version.img
#boot=/dev/hde
default=0
timeout=5
splashimage=(hd0,0)/grub/splash.xpm.gz
hiddenmenu
title CentOS (2.6.18-128.1.1.el5.028stab062.3)
root (hd0,0)
kernel /vmlinuz-2.6.18-128.1.1.el5.028stab062.3 ro root=LABEL=/1
initrd /initrd-2.6.18-128.1.1.el5.028stab062.3.img
title CentOS (2.6.18-92.1.18.el5)
root (hd0,0)
kernel /vmlinuz-2.6.18-92.1.18.el5 ro root=LABEL=/1
initrd /initrd-2.6.18-92.1.18.el5.img
title CentOS (2.6.18-92.el5)
root (hd0,0)
kernel /vmlinuz-2.6.18-92.el5 ro root=LABEL=/1
initrd /initrd-2.6.18-92.el5.img
Here default=0 means first entry in the file get booted, that is
title CentOS (2.6.18-128.1.1.el5.028stab062.3)
root (hd0,0)
kernel /vmlinuz-2.6.18-128.1.1.el5.028stab062.3 ro root=LABEL=/1
initrd /initrd-2.6.18-128.1.1.el5.028stab062.3.img
This is our new openvz kernel, so nothing to change in boot loader.
Now need to make some changes in
vi /etc/sysctl.conf
At the end of the file add
# On Hardware Node we generally need
# packet forwarding enabled and proxy arp disabled
net.ipv4.ip_forward = 1
net.ipv6.conf.default.forwarding = 1
net.ipv6.conf.all.forwarding = 1
net.ipv4.conf.default.proxy_arp = 0
# Enables source route verification
net.ipv4.conf.all.rp_filter = 1
# Enables the magic-sysrq key
kernel.sysrq = 1
# We do not want all our interfaces to send redirects
net.ipv4.conf.default.send_redirects = 1
net.ipv4.conf.all.send_redirects = 0
Disable SELinux if you have not already done.
vi /etc/sysconfig/selinux
In the file change value of SELINUX to disabled.
SELINUX=disabled
Now reboot the server, so server will boot with new openvz kernel
reboot
After reboot, we have the new kernal shown in uname -a
root@server84 [~]# uname -a
Linux server84.hosthat.com 2.6.18-128.1.1.el5.028stab062.3 #1 SMP Tue May 5 17:31:34 MSD 2009 i686 i686 i386 GNU/Linux
root@server84 [~]#
Now install
yum install vzctl vzquota
You need to do a reboot now
reboot
To create a VPS, download an OS Template from
http://download.openvz.org/template/precreated/
To create an VPS with ubuntu OS
cd /vz/template/cache
wget http://download.openvz.org/template/precreated/ubuntu-9.04-x86.tar.gz
Now you have the OS template cache, before creating VPS, i need a FREE IP
In cpanel servers, go to
Main >> IP Functions >> Show or Delete Current IP Addresses
Delete a IP that is not used.
On non Cpanel servers you need to edit the file
vi /etc/sysconfig/network-scripts/ifcfg-eth0-range0
OR
vi /etc/sysconfig/network-scripts/ifcfg-eth0:X
Here is the syntax to create a new VPS
vzctl create CTID --ostemplate osname
vzctl set CTID --ipadd a.b.c.d --save
vzctl set CTID --nameserver a.b.c.d --save
vzctl start CTID
To create VSP i run following commands
vzctl create 101 --ostemplate ubuntu-9.04-x86
vzctl set 101 --ipadd 67.159.32.134 --save
vzctl set 101 --nameserver vps2.hosthat.com --save
vzctl set 101 --nameserver 208.67.222.222 --save
vzctl set 101 --onboot yes --save
vzctl set 101 --kmemsize 60000000 --save
vzctl set 101 --privvmpages 900000 --save
vzctl set 101 --numproc 1000 --save
vzctl set 101 --numtcpsock 500 --save
vzctl set 101 --tcpsndbuf 20000000:35000000 --save
vzctl set 101 --tcprcvbuf 20000000:35000000 --save
vzctl set 101 --diskspace 10048576:10153434 --save
vzctl set 101 --cpuunits 1000 --save
vzctl start 101
Here are the results
root@server84 [~]# vzctl create 101 --ostemplate ubuntu-9.04-x86
Unable to get full ostemplate name for ubuntu-9.04-x86
Creating container private area (ubuntu-9.04-x86)
vzquota : (error) Quota on syscall for id 101: File exists
vzquota on failed [3]
vzquota : (error) Quota is not running for id 101
Performing postcreate actions
Container private area was created
root@server84 [~]# vzctl set 101 --ipadd 67.159.32.134 --save
Saved parameters for CT 101
root@server84 [~]# vzctl set 101 --nameserver vps2.hosthat.com --save
Saved parameters for CT 101
root@server84 [~]# vzctl set 101 --nameserver 208.67.222.222 --save
Saved parameters for CT 101
root@server84 [~]# vzctl set 101 --onboot yes --save
Saved parameters for CT 101
root@server84 [~]# vzctl set 101 --kmemsize 60000000 --save
Saved parameters for CT 101
root@server84 [~]# vzctl set 101 --privvmpages 900000 --save
Saved parameters for CT 101
root@server84 [~]# vzctl set 101 --numproc 1000 --save
Saved parameters for CT 101
root@server84 [~]# vzctl set 101 --numtcpsock 500 --save
Saved parameters for CT 101
root@server84 [~]# vzctl set 101 --tcpsndbuf 20000000:35000000 --save
Saved parameters for CT 101
vzctl set 101 --tcprcvbuf 20000000:35000000 --save
root@server84 [~]# vzctl set 101 --tcprcvbuf 20000000:35000000 --save
Saved parameters for CT 101
root@server84 [~]# vzctl set 101 --diskspace 10048576:10153434 --save
Saved parameters for CT 101
root@server84 [~]# vzctl set 101 --cpuunits 1000 --save
Saved parameters for CT 101
root@server84 [~]#
Now lets start VSP
root@server84 [~]# vzctl start 101
Starting container ...
vzquota : (error) Quota on syscall for id 101: File exists
vzquota on failed [3]
root@server84 [~]#
The error was due to quota was not enabled in the hard disk.
This error was fixed by adding usrquota in /etc/fstab for / partition
root@server84 [/]# cat /etc/fstab
LABEL=/1 / ext3 defaults,usrquota 1 1
LABEL=/boot1 /boot ext3 defaults 1 2
tmpfs /dev/shm tmpfs defaults 0 0
devpts /dev/pts devpts gid=5,mode=620 0 0
sysfs /sys sysfs defaults 0 0
proc /proc proc defaults 0 0
LABEL=SWAP-hde2 swap swap defaults 0 0
/usr/tmpDSK /tmp ext3 defaults,noauto 0 0
/tmp /var/tmp ext3 defaults,bind,noauto 0 0
root@server84 [/]#
To start VSP
root@server84 [/]# vzctl start 101
Starting container ...
Container is mounted
Adding IP address(es): 67.159.32.134
Setting CPU units: 1000
Configure meminfo: 900000
File resolv.conf was modified
Container start in progress...
root@server84 [/]#
To set root password
vzctl enter 101
passwd
root@server84 [/]# vzctl enter 101
entered into CT 101
root@server84:/# cat /etc/*issue
Ubuntu 9.04 \n \l
root@server84:/# passwd
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully
root@server84:/#
Now VPS is ready, i am able to connect to VPS from my computer with SSH.
4 Responses to Installing OpenVZ