How to setup OpenVz
OpenVZ is container-based virtualization for Linux. OpenVZ creates multiple secure, isolated 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.I will explain you how to install openvz in centos server.
Please wait while we retrieve data from server .............
First we need to add the repository.
{codecitation}
cd /etc/yum.repos.d
wget http://download.openvz.org/openvz.repo
rpm --importĀ http://download.openvz.org/RPM-GPG-Key-OpenVZ
{/codecitation}
Then we need to install the kernel. For that you can check the avialable kernels using the command given below.
{codecitation}
yum search ovzkernel
{/codecitation}
Then install the kernel.
{codecitation}
yum install ovzkernel
{/codecitation}
Set the kernel paramters so that openvz works without any trouble.
{codecitation}
# 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
{/codecitation}
Make sure that SELINUX is disabled in the server in /etc/sysconfig/selinux
Now reboot the server so that server will boot with the new kernel.
Now we need to install main utilities in openvz to work properly.
{codecitation}
yum install vzctl vzquota
{/codecitation}
Now we can start the openvz
{codecitation}
/etc/init.d/vz start
{/codecitation}
Now we need some more utilities for creating OS templates and all and store is locally.
{codecitation}
yum install vzpkg vzyum vzrpm43-python vzrpm44-python vzctl-lib
{/codecitation}
To see which templates are available, run
{codecitation}
# yum search vztmpl
{/codecitation}
To install some of the templates, run
{codecitation}
# yum install vztmpl-XXX [...]
{/codecitation}
To create/update the cache of the OS templates, you can run the following.
{codecitation}
vzpkgcache centos-4-i386-minimal
{/codecitation}
If it is not properly updated you can use the following.
{codecitation}
yum install vztmpl-centos-4
{/codecitation}
Now we can create a container
{codecitation}
vzctl create 101 --ostemplate fedora-core-5-minimal
vzctl set 101 --ipadd 10.1.2.3 --save
vzctl set 101 --nameserver 10.0.2.1 --save
vzctl start 101
{/codecitation}
You can execute any commands inside it as follows
{codecitation}
vzctl exec 101 ps ax
{/codecitation}
To enter in to the container
{codecitation}
vzctl enter 101
{/codecitation}
To destroy
{codecitation}
vzctl stop 101
vzctl destroy 101
{/codecitation}
To list all nodes
{codecitation}
vzlist -a
{/codecitation}
You can change other configurations in this file and reboot the node.
{codecitation}
/etc/sysconfig/vz-scripts/101.conf
{/codecitation}