What is OpenVZ ?
OpenVZ is an open source container-based virtualization solution built on Linux. OpenVZ creates isolated, secure containers (otherwise known as VEs or VPSs) on a single physical server enabling better server utilization and ensuring that applications do not conflict. Each container performs and executes exactly like a stand-alone server; containers can be rebooted independently and have root access, users, IP addresses, memory, processes, files, applications, system libraries and configuration files.
Preparing Anything
1. Server With Centos 5 ( You can also choose other distro linux fedora, RHEL, etc ) in this tutorial we are using Centos 5 with 4 GB memory and 40 GB harddrive
2. Configure YUM to have a OpenVZ repository
3. Install OpenVZ Kernel
4. Configure Boot loader
5. Configure Sysctl
6. Disabled SELinux
7. Configure Conntracks
8. Installing OpenVZ utilities
9. Starting OpenVZ
10. Installing OS Template Cache & Template Utilities
11. Alternative Use Precreated Template Cache
12. Create a Container/VPS Machine
We start with Configure YUM to have a OpenVZ repository
Login as root into your server
$cd /etc/yum.repos.d
$wget http://download.openvz.org/openvz.repo
$rpm –import http://download.openvz.org/RPM-GPG-Key-OpenVZ
Download & Install OpenVZ Kernel
$cd /root
$wget http://download.openvz.org/kernel/branches/rhel5-2.6.18/028stab053.6/ovzkernel-2.6.18-53.1.6.el5.028stab053.6.i686.rpm
$wget http://download.openvz.org/kernel/branches/rhel5-2.6.18/028stab053.6/ovzkernel-devel-2.6.18-53.1.6.el5.028stab053.6.i686.rpm
$rpm -ivh ovzkernel*
You can download other kernel from this URL http://openvz.org/download/kernel/
Note : if your server have memory > 4GB, you need to using PAE kernel
Configure Boot Loader
$cd /etc/
$vi grub.conf
### change the title so your new kernel will not mixed up with non-OpenVZ kernel
Example :
title Fedora Core (2.6.8-022stab029.1)
root (hd0,0)
kernel /vmlinuz-2.6.8-022stab029.1 ro root=/dev/sda5 quiet rhgb vga=0×31B
initrd /initrd-2.6.8-022stab029.1.img
### Change it To
title OpenVZ (2.6.8-022stab029.1)
root (hd0,0)
kernel /vmlinuz-2.6.8-022stab029.1 ro root=/dev/sda5
initrd /initrd-2.6.8-022stab029.1.img
## save and exit
$
Configure Sysctl
$vi /etc/sysctl.conf
### Change your sysctl look like below ###
# On Hardware Node we generally need
# packet forwarding enabled and proxy arp disabled
net.ipv4.ip_forward = 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
# TCP Explict Congestion Notification
#net.ipv4.tcp_ecn = 0
# we do not want all our interfaces to send redirects
net.ipv4.conf.default.send_redirects = 1
net.ipv4.conf.all.send_redirects = 0
$
Disabled SELinux
$vi /etc/sysconfig/selinux
### Make sure you have disabled SELinux like below
SELINUX=disabled
$
Configure Conntracks
$vi /etc/modprobe.conf
## add the following line into modprobe.conf
options ip_conntrack ip_conntrack_enable_ve0=1
NOTE : In kernels later than 2.6.8, connection tracking is enabled by default.
Rebooting into your new OpenVZ Kernel
$reboot
Installing OpenVZ Utilities
OpenVZ need 2 utilities below :
vzctl
A utility to control OpenVZ containers (create, destroy, start, stop, set parameters etc.)
vzquota
A utility to manage quotas for containers. Mostly used indirectly (by vzctl).
Using Yum to install vzctl and vzquota
$yum install vzctl vzquota
Starting OpenVZ
$/etc/init.d/vz start
or
$service vz start
Next Step is Installing OS Template cache and Template Utilities
Installing Template Utilites
$yum install vzpkg vzyum vzrpm43-python vzrpm44-python vzctl-lib
Installing OS Template Metadata
$yum search vztmpl
Note : you will see few OS Template Metadata such as vztmpl-Fedora-core6-default, etc.
$yum install vztmpl-fedora-core6-default
Alternative Use Precreated Template Cache
$cd /vz/template/cache
$wget http://download.openvz.org/template/precreated/centos-4-i386-default.tar.gz
Note : You can download other Precreated Template from this URL http://download.openvz.org/template/precreated/
After we have a precreated Template Cache, Next we can create a container or VPS Machine.