Install OpenVZ and a CentOS Container

OpenVZ (Open Virtuozzo) is an operating system-level virtualization technology based on the Linux kernel and operating system. OpenVZ allows a physical server to run multiple isolated operating system instances, called containers, virtual private servers (VPSs), or virtual environments (VEs). OpenVZ is similar to FreeBSD jails and Solaris Containers.

Download the OpenVZ repo.

wget -P /etc/yum.repos.d/ http://ftp.openvz.org/openvz.repo

Import OpenVZ GPG key.

rpm --import http://ftp.openvz.org/RPM-GPG-Key-OpenVZ

Install OpenVZ

yum install -y ovzkernel vzctl vzquota ploop

Modify the /etc/sysctl.conf file

# 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

Set SELinux to permissive mode by modifying /etc/selinux/selinux

sed -i --follow-symlinks 's/\(^SELINUX=\)\(.*\)/permissive/g' /etc/selinux/config
setenforce 0

Download a template

cd /vz/template/cache
wget http://download.openvz.org/template/precreated/centos-5-x86_64.tar.gz

Reboot to the default OpenVZ kernel.

Create a new container

vzctl create 1001 --ostemplate centos-5-x86_64
# Modify
vzctl set 1001 --hostname myhost.my.domain --ipadd 192.168.1.2 --userpasswd root:[newpasswd] --save
# Boot with system
vzctl set 1001 --onboot yes --save

Start / stop the container

vzctl start 1001
vzctl stop 1001
vzctl stop 1001 --fast

Enter the container

vzctl enter 1001

Run commands from within vzctl

vzctl exec 1001 service sshd status

List containers

vzlist 1001
vzlist -a

Create a computer name

vzctl set 1001 --name computer1 --save
vzctl stop computer1

Source(s)