Install OpenVZ and a CentOS container

PDF

A brief installation guide how to install OpenVZ. I recommend to use a separate partition for the containers and to use the filesystem type EXT3 for it. I assume you have CentOS already running and yum is available.

First we need to setup the OpenVZ repository. As root type:

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

Next install the OpenVZ kernel and the OpenVZ tools:

yum install ovzkernel.x86_64 vzctl.x86_64 vzquota.x86_64
Before rebooting into the OpenVZ kernel we have to change some kernel parameters and disable SElinux. The kernel parameters should be changed or added in /etc/sysctl.conf. Open /etc/sysctl.conf and change or add the lines:
 # Enables the kernel magic-sysrq key
kernel.sysrq = 1

# Not all the network interfaces should send redirects
net.ipv4.conf.default.send_redirects = 1
net.ipv4.conf.all.send_redirects = 0

# Enables source route verification
net.ipv4.conf.all.rp_filter = 1

# 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
To disable SELinux change the file /etc/sysconfig/selinux and add the line
SELINUX=disabled

Now you can reboot your machine to boot up with the OpenVZ kernel.

Once rebooted we can install a new virtual machine. Easy way to do so is to use a pre created OS template from the OpenVZ website. Let's take a CentOS 5 x86_64 template and store it into the template directory /vz/template/cache

cd /vz/template/cache/
wget http://download.openvz.org/template/precreated/centos-5-x86_64.tar.gz
Create a new container (VPS) based on this template using container-id 1001, we need to run:
vzctl create 1001 --ostemplate centos-5-x86_64
On your terminal you see the status:
Creating container private area (centos-5-x86_64)
Performing postcreate actions
Container private area was created
Using the vzctl command you can change the settings of the container. Don't forget to set the root password immediately. To set the root password and change the ip-address and host-name of this container, type:
vzctl set 1001 -hostname myhost.my.domain --ipadd 192.168.1.2 --userpasswd root:[newpasswd]
 --save
(Read the man-page of vzctl for more options and instructions.)

To start your newly created VPS you should run:

vzctl start 1001
You can now enter your container directly from the hardware-node itself using:
vzctl enter 1001
or using a remote ssh connection. To stop the VPS you should run
vzctl stop 1001
 

Search






You are here: Home Howtos and FAQs Virtualization Install OpenVZ and a CentOS container