Install OpenVZ on CentOS

Install OpenVZ on CentOS

OpenVZ is container-based virtualization for Linux. OpenVZ creates multiple secure, isolated Linux containers (otherwise known as VEs or VPSs) on a single physical server enabling better server utilization and ensuring that applications do not conflict. Each container performs and executes exactly like a stand-alone server; a container can be rebooted independently and have root access, users, IP addresses, memory, processes, files, applications, system libraries and configuration files.

OpenVZ Official Website openvz.org

About install CentOS please reference to Install CentOS 6.4 in Text Mode

Installation can be divided into two ways, the first is more complex, use the rpm installation, you need to manually download and install the package; second relatively simple, is through YUM to install. Here is through YUM to install.

Host Operating System: CentOS Release 6.4 Final
Kernel Version: 2.6.32-358.e16.x86_64

Install OpenVZ

  • Configuration YUM source

Download openvz.repo file to /etc/yum.repos.d/ directory, use the following command to complete

$ cd /etc/yum.repos.d
$ sudo wget http://download.openvz.org/openvz.repo
$ sudo rpm --import  http://download.openvz.org/RPM-GPG-Key-OpenVZ
  • Install OpenVZ Kernel and vzctl, vzquota

Note: For RHEL6 or CentOS6 or later, use vzkernel, for other versions ovzkernel

$ sudo yum install vzkernel
$ sudo yum install vzctl vzquota
  • Configuration CentOS kernel parameters and SELinux properties

Configure the OS kernel parameters, enter /etc/sysctl.conf file, modify the following two parameters

$ sudo vi /etc/sysctl.conf
net.ipv4.ip_forward = 1
kernel.sysrq = 1

SELinux is the 2.6 version of the Linux kernel provides mandatory access control system, install OpenVZ need to disable it, enter /etc/sysconfig/selinux file, in accordance with the following settings:

$ sudo vi /etc/sysconfig/selinux
SELINUX=disabled
  • Reboot System
  • Start OpenVZ

Before starting OpenVZ can first check the service status

$ service vz status
$ service vz start
  • VE Template Installation

Download a template needs to be installed to /vz/template/cache directory (If the host is Debain, you need to download to /var/lib/vz/template/cache/ directory), Install VC needs according to their different requirements of the VE will vary. We can go to http://download.openvz.org/template/precreated/ download already installed templates, there centos, debian, ubuntu, fedora, suse, etc. you can choose several templates.

$ cd /vz/template/cache
$ sudo  wget http://download.openvz.org/template/precreated/centos-6-x86.tar.gz

Create an ID of 1 Virtual Environment (VE)

$ sudo vzctl create 1 --ostemplate ubuntu-10.04-x86

$ sudo vzctl set 1 --onboot yes --save
$ sudo vzctl set 1 --ipadd 172.16.82.129 --save
$ sudo vzctl set 1 --nameserver 8.8.8.8 --save
$ sudo vzctl set 1 --hostname vps01.vpsee.com --save
$ sudo vzctl set 1 --diskspace 10G:10G --save

$ sudo vzctl start 1
$ sudo vzctl exec 1 passwd

Start, restart, shutdown and power off ID 1 VE/VPS

$ sudo vzctl start 1
$ sudo vzctl restart 1
$ sudo vzctl stop 1
$ sudo vzctl destroy 1

View the running VE/VPS

$ sudo vzlist

Computing ID 1 VE/VPS resources used

$ sudo vzcalc -v 1

Enter and Exit the Guest

VE can enter the system after successful startup, the equivalent of the xen xm console, command exit to exit the guest.

$ sudo vzctl enter 1
$ sudo exit
0.00 avg. rating (0% score) - 0 votes