HomeCentOS › Install OpenVZ — CentOS 5

Install OpenVZ — CentOS 5

We begin with preparation

yum pre-setup

If you want to use yum, you should set up OpenVZ yum repository first.

Download openvz.repo file and put it to your /etc/yum.repos.d/ repository. This can be achieved by the following commands, as root:

# cd /etc/yum.repos.d
# wget http://download.openvz.org/openvz.repo
# rpm —import http://download.openvz.org/RPM-GPG-Key-OpenVZ

Kernel installation

Run the following command

# yum install ovzkernel[-smp or -ent]

smp symmetric multiprocessor up to 4 GB of RAM 10-20 Containers
ent SMP + PAE support + 4/4GB split up to 64 GB of RAM >20-30 Containers


Configuring the bootloader

In case GRUB is used as the boot loader, it will be configured automatically: lines similar to these will be added to the /boot/grub/grub.conf file:

Make default=0 to boot vz kernel first.

Config

There are a number of kernel parameters that should be set for OpenVZ to work correctly. These parameters are stored in /etc/sysctl.conf file. Here are the relevant portions of the file; please edit accordingly.

# 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

SELinux should be disabled. To that effect, put the following line to /etc/sysconfig/selinux:
SELINUX=disabled

Rebooting into OpenVZ kernel

Installing the utilities

# yum install vzctl vzquota
on x64
# yum install vzctl.x86_64 vzquota.x86_64

Starting OpenVZ
# /sbin/service vz start

Next OS template
An OS template is basically a set of packages from some Linux distribution used to populate a container.

Creating an OS template cache

You can create an OS template cache using template utilities and OS template metadata right on your hardware node. The process is automated and will take from about 10 minutes to a few hours, depending on the network speed, and the result will be most up-to-date template cache.
Installing template utilities

You have to install a few packages in order to be able to create/update OS template cache(s).
Using yum
# yum install vzpkg vzyum vzrpm43-python vzrpm44-python vzctl-lib

Installing OS template metadata
To see which templates are available, run
# yum search vztmpl

To install some of the templates, run
# yum install vztmpl-XXX […]

Get it in http://download.openvz.org/template/precreated/
In order to use precreated template cache files, download files for chosen OS distributions and place them as-is to the /vz/template/cache directory.

Create and start a container

To create and start a container, run the following commands:
[host-node]# vzctl create 128 —ostemplate centos-5-i386-minimal
[host-node]# vzctl set 128 —ipadd 10.1.2.128 —save
[host-node]# vzctl set 128 —nameserver 10.0.2.128 —save
[host-node]# vzctl start 128

Your freshly-created container should be up and running now; you can see its processes:
[host-node]# vzctl exec 128 ps ax

Stop and destroy the container

To stop container:
[host-node]# vzctl stop 128

And to destroy container:
[host-node]# vzctl destroy 128

I’s all

Leave a Comment