I. Install OpenVZ
Prepare filesystem
The OpenVZ contains will be stored in folder /vz. At the very list, create a separate partitioner that mounts onto /vz with ample disk space.
yum pre-setup
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
Install CentOS kernel for OpenVZ
- Find out the kernel flavor you will need from http://wiki.openvz.org/Kernel_flavors
-
Run the following command
# yum install ovzkernel[-flavor]
Here [-flavor] is optional, and can be -smp or -enterprise.
Configure the bootloader (grub.conf)
When a new kernel is installed, lines for booting into the new kernel should have been added to the /boot/grub/grub.conf file automatically. Open this file and make sure the OpenVZ kernel is in the default position (first section).
Configure kernel parameters
Follow the section for "Configuring" in http://wiki.openvz.org/Quick_installation to configure sysctl, disable SELinux, and enable contnracks.
Now reboot into the OpenVA kernel.
Install OpenVZ user-level tools
# yum install vzctl vzquota
Start OpenVZ
# /sbin/service vz start
# /sbin/chkconfig --list vz
The chkconfig command should tell that vz will be automatically started during the next reboot.
II. OS template cache preparation
Installing template utilities
# 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 [...]
Running vzpkgcache
Run the vzpkgcache utility; see the vzpkgcache(8) man page for details. It will create or update the caches of all the templates for which the corresponding metadata exist.
# vzpkgcache centos-4-i386-minimal
III. Create Container
Follow http://wiki.openvz.org/Container_creation to create contains.
IV. Networks
sysctl
When I restart the network in the container, it complained about some settings in the file /etc/sysctl.conf. I had to comment out these lines:
#net.ipv4.conf.default.accept_source_route = 0
#kernel.sysrq = 0
#kernel.core_uses_pid = 1
Firewall and iptables
Reference Setting up an iptables firewall.
References
This is a good article to start before you install the OpenVZ on CentOS: Installing and using OpenVZ on CentOS 5.
After you have read the above article, here are some additional ones: