The installation of OpenVZ containers on CentOS (or RHEL5) is very simple. The following steps were performed on a default installation of CentOS 5.2. In my case I use a virtual machine in a VMware environment.
The OpenVZ installation
$ setup
First you need to disable SELinux and the firewall.
$ cd /etc/yum.repos.d
$ wget http://download.openvz.org/openvz.repo
$ rpm --import http://download.openvz.org/RPM-GPG-Key-OpenVZ
$ yum -y install ovzkernel
$ vi /etc/sysctl.conf
In this file change the following lines:
net.ipv4.ip_forward = 1
kernel.sysrq = 1
net.ipv4.conf.default.proxy_arp = 0
In this same file add the following lines:
net.ipv4.conf.default.send_redirects = 1
net.ipv4.conf.all.send_redirects = 0Install the OpenVZ service and have it start at boot:
$ yum install vzctl vzquota
$ chkconfig --add vz
$ reboot
Container configuration
After this, you need to create or download an OS template. For keeping this post easy, I use a precreated template:
$ cd /vz/template/cache
$ wget http://mirror.proserve.nl/openvz/contrib/template/precreated/centos-5-i386-default.tar.gz
Now you can create your first OS container from this template. The information we need is an IP address, hostname and nameservers.
$ vzctl create 101 --ostemplate centos-5-i386-default --conf vps.basic --ipadd 10.73.11.150 --hostname c1.survion.net
$ vzctl set 101 --name c1 --nameserver "10.73.11.1 10.73.11.2 10.73.11.3" --diskspace 10G:10G --save
$ vzctl set 101 --userpasswd root:password --save
Each container instance is represented by an CTID. In the previous steps we used id 101 the identify the container. The configured information can now be found in the file /etc/vz/conf/101.conf. Be sure to use your own secret password for the last command.
You can now start this container and list processes
$ vzctl start 101
$ vzctl exec 101 ps ax
You can also issue an enter command:
$ vzctl enter 101
You would then authenticate as root inside the container. On the console you can perform commands as if you would on a normal machine.
That's it! You now have a CentOS container running on top of your CentOS installation.
Links and additional information
Information on how to create a template can be found on http://wiki.openvz.org/OS_template_cache_preparation
OS Templates can be found at:
- http://forum.openvz.org/index.php?t=msg&goto=15905
- http://mirror.proserve.nl/openvz/contrib/template/precreated/
You can read more detailed information about the installation on the following websites:
Edit: An interesting experiment performed by Scott Dowdle can be found on his blog called 'How many containers?'.
