OpenVZÂ installation easy on CentOS 5
To start, you need to have your kernel compiled with openVZ. Check that using
#uname -a
The output should look something like Linux … 2.6.188.1.8.
el5.028stab038.1 ..
The most important part is 028stab038, if you do not have this (the numbers might be
different on your machine) you need to update your kernel using yum. So, make sure you
are connected to the Internet. To update the kernel you need first to update your yum
repository.
#cd /etc/yum.repos.d
#wget http://download.openvz.org/openvz.repo
#cd
Till now you have just updated your repository so as to use it for yum.

#yum -y install ovzkernel

After this step is done, you several things will change beside the kernel update. One of
them is the boot loader. I am using Centos 5, so my boot loader is GRUB. What happens
is that the yum installer will add extra entry to /boot/grub/grub.con looks like
title Cenros (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
Note the “stab” in the entry
I believe you know how to edit GRUB configuration file to make this entry the default
boot option.
After this step we have to make some changes on some configuration files to make our
virtualization runs with no problem.
First file to be edited is the system control file. /etc/sysctl.conf

disble the service like dahdi on startup.

# vi /etc/sysctl.conf

Now add the following parameters.

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

3.5. SELinux

SELinux should be disabled.

# vi /etc/sysconfig/selinux

Add the following line to this file.

SELINUX=disabled

3.6. Conntracks

In the stable OpenVZ kernels (those that are 2.6.8-based) netfilter connection tracking for VE0 is disabled by default. If you

have a stateful firewall enabled on the host node you should either disable it, or enable connection tracking for VE0.

To enable conntracks for VE0 please edit the file /etc/modprobe.conf

# vi /etc/modprobe.conf

Now add the following.

options ip_conntrack ip_conntrack_enable_ve0=1

In kernels later than 2.6.8, connection tracking is enabled by default.
3.7. Rebooting Into VPS

Now reboot the server. If it is loaded successfully we can proceed to installing the user-level tools for OpenVZ
3.8. Install Utilities

Now we need to install three basic utility packages .

vzctl: it is used to perform different operations on the OpenVZ VPS (eg : create, destroy, start, stop, set parameters etc.)
vzquota: This package is used to manage the VPS quotas.
vzpkg: this package is used to work with OpenVZ templates
Let us install this packages as follows

# yum install vzctl

# yum install vzquota

# yum install vzpkg

Now check the virtual ethernet device

# ifconfig

If it is not there use the following command to make it up.

# ifconfig venet0 up

Now reboot the server

# reboot

#/etc/init.d/vz start
or
#service vz start

3.9. Install OS Templates

yum search vztmpl

vztmpl-centos-4.i386 2.0-2
openvz-utils
Matched from:
vztmpl-centos-4
vztmpl-fedora-7.i386 1.1-1
openvz-utils
Matched from:
vztmpl-fedora-7
vztmpl-fedora-core-6.i386 1.2-1
openvz-utils
Matched from:
vztmpl-fedora-core-6
vztmpl-fedora-core-3.i386 2.0-2
openvz-utils
Matched from:
vztmpl-fedora-core-3
vztmpl-fedora-core-

Now you need to install at leaset one OS template Like.

now you pick the operating system of your interest and download it using yum. In my
case I prefer to use centos 4.5. The name of the tempalte usually looks like vztmplnameOfDistroversion.
machine
#yum -y vztmpl-centos-4.i386
if you want to download another one you just need to change the name of the operating
system after vztmpl like
#yum -y vztmpl-fedora-7.i386

# yum install vztmpl-fedora-core

Also you need to download a template package for creating vps .

# cd /vz/template/cache/

# wget http://download.openvz.org/template/precreated/centos-4-i386-default.tar.gz

In order to be able to run the system you have to have a file that
ends with .tar.gz. something like centos-4-i386-default.tar.gz saved in
/vz/template/cache/
To have this file you can use yum or download it manually

Once you have this file or others, you can start the virtualization. Before that, let’s list
what openVZ templates we have. use

#vzpkgls
the output would look like
centos-4-i386-default

To start the virtualization we need to create virtual private server VPS

# vzctl create 101 –ostemplate centos-4-i386-default

4. Usages

4.1. Create VPS

First you need to select a vps id. The id 0 is used for the hardware node itself.

# vzlist -a

This command list all the vps in the host. You can create a vps using the default template or you can define a template package

and a configuration. The default creation is as follows,

# vzctl create 101

If you want to create a vps using a OS template as follows

# vzctl create 101 –ostemplate centos-4-i386-default

101: is the vp id
fedora-core-4: is the OS template
vps.basic: is the configurations defined in vps.basic.conf
4.2. Configure VPS

Now we need to configure our vps. In this process we need to set up the following parameters.

i) Set the startup parameters
ii) Set the network parameters
iii) Set the root(user) password
So do the following commands in the host server.

# vzctl stop 101

# vzctl set 101 –onboot yes –save

# vzctl set 101 –hostname example.com –save

# vzctl set 101 –ipadd 192.168.2.50 –save

# vzctl set 101 –nameserver 192.168.2.1 –save

vzctl set 101 –userpasswd root:t3mp

vzctl exec 101 service sshd start

# vzctl start 101

Now our vps will automatically start at the boot time with assigned hostname, ipaddress etc192.168.1.9.

#vzlist -a
CTIDÂ Â Â Â Â NPROC STATUSÂ IP_ADDRÂ Â Â Â Â Â Â Â HOSTNAME
102Â Â Â Â Â Â Â Â 14 running 192.168.2.50Â Â Â -

Now you need to do the following operations in your vps

i) start
ii)stop
iii)restart
iv)status
So run the following commands.

# vzctl stop 101
# vzctl start 101
# vzctl restart 101
# vzctl status 101

To delete a vps node we use the “destroy” command.

# vzctl stop 101
# vzctl destroy 101

Turning on/off per vps disk quota:Now to turning on per vps disk quota do the following.
Edit the separate configuration file

# vi /etc/sysconfig/vz-scripts/101.conf

Add the following,

DISK_QUOTA=yes