Centos 6.5 - Install OpenVZ


OpenVZ has a couple of advantages over Xen. It has proved easier to set up the host so far and pretty quick to set up each virtual machine (no need to run an install process and worry about who/where/how the domU’s kernels are booting). The main advantage that I have read about so far is the ability to set allocated memory on openvz and not allow clients to spill out into swap space which kills disk IO for everyone else (which can happen in Xen). It is not a ‘true’ hypervisor (and thus cannot run windows), but has less overheads and is extremely fast and efficient.

Install Script

Copy and paste the following script into a file and execute it. Read all the output/echo statements if you want to know what it's doing.


# BASH guard
if ! [ -n "$BASH_VERSION" ];then
    echo "this is not bash, calling self with bash....";
    SCRIPT=$(readlink -f "$0")
    /bin/bash $SCRIPT

echo 'Installing OpenVZ...'

echo "updating..."
yum update -y

echo 'installing wget...'
yum install wget -y

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

echo 'Installing OpenVZ Kernel...'
yum install -y vzkernel

echo 'Installing additional tools...'
yum install vzctl vzquota ploop -y

echo 'Changing around some config files..'
sed -i 's/kernel.sysrq = 0/kernel.sysrq = 1/g' /etc/sysctl.conf

echo "Setting up packet forwarding..."
sed -i 's/net.ipv4.ip_forward = 0/net.ipv4.ip_forward = 1/g' /etc/sysctl.conf

# With vzctl 4.4 or newer there is no need to do manual configuration. Skip to #Tools_installation.
# source: http://openvz.org/Quick_installation
#echo 'net.ipv4.conf.default.proxy_arp = 0' >> /etc/sysctl.conf
#echo 'net.ipv4.conf.all.rp_filter = 1' >> /etc/sysctl.conf
#echo 'net.ipv4.conf.default.send_redirects = 1' >> /etc/sysctl.conf
#echo 'net.ipv4.conf.all.send_redirects = 0' >> /etc/sysctl.conf
#echo 'net.ipv4.icmp_echo_ignore_broadcasts=1' >> /etc/sysctl.conf
#echo 'net.ipv4.conf.default.forwarding=1' >> /etc/sysctl.conf

echo "Allowing multiple subnets to reside on the same network interface..."
sed -i 's/#NEIGHBOUR_DEVS=all/NEIGHBOUR_DEVS=all/g' /etc/vz/vz.conf
sed -i 's/NEIGHBOUR_DEVS=detect/NEIGHBOUR_DEVS=all/g' /etc/vz/vz.conf

echo "Setting container layout to default to ploop (VM in a file)..."
sed -i 's/#VE_LAYOUT=ploop/VE_LAYOUT=ploop/g' /etc/vz/vz.conf

echo "Setting Ubuntu 12.04 64bit to be the default template..."
sed -i 's/centos-6-x86/ubuntu-12.04-x86_64/g' /etc/vz/vz.conf

echo 'Purging your sys configs...'
sysctl -p

echo "Disabling selinux..."
sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/sysconfig/selinux

echo "disabling iptables..."
/etc/init.d/iptables stop && chkconfig iptables off


echo "OpenVZ Is now Installed. "
echo "Please reboot into the openvz kernel to start using it."
echo "Programster"
This script was last tested on the 15th August 2014

Start Your First Container

    Create a virtual machine with a command like such (I build command in an sh file before running)
    vzctl create $unique-id-for-vm \ --ostemplate $template-name-here \ --conf $configuration-name-here \ --ipadd $ip-address-of-vm \ --onboot yes \ --hostname $hostname-of-vm
    Here is an example already filled out:
    vzctl create 101 \
    --ostemplate centos-6-x86_64 \
    --conf basic \
    --ipadd \
    --hostname centos1
    vzctl create 101 \
    --ostemplate ubuntu-14.04-x86_64 \
    --conf basic \
    --ipadd \
    --hostname ubuntu1
    The root password will be the same as the host machine unless you change it using passwd inside the machine, or by issuing the following command:
    vzctl set {CTID} --userpasswd {user}:{password} --save
    To start the virtual machine that you have created, run:
    vzctl start
    The machine could automatically connect to google dns ( but had to manually set nameserver.
    echo nameserver > /etc/resolv.conf
    Restart the network for the nameserver to take effect:
    service network restart



  1. hi, can i have your email address, we need support on centos and openvz

    1. If you post details of your issue in the comments on this post (if it relates to this post) then I will try and address your issue.

  2. This comment has been removed by the author.

    1. Thank you for responding. Let me start by saying that I have no experience with VMware as I try to study only Opensource products/tools, so any help I can give is limited to the realm of OpenVZ. OpenVZ is a "container" based virtualization rather than a full-blown Virtual Machine hypervisor such as Xen/KVM. This is why OpenVZ containers will not show an eth0 NIC, but you will see Venet 0:0 instead. This is why KVM/Xen may be more appropriate for you.

      Personally, I have "given up" on studying OpenVZ and moved to concentrating on KVM. [ http://programster.blogspot.com/2014/04/ubuntu-1204-setting-up-kvm-host.html ]. Containers are better than Virtual Machines for a lot of things since they are "lighter" and can allow you to heavily "oversell" your resources, however I believe life is easier in the long run with using/learning KVM/Xen instead.

      I'm sorry if this wasn't helpful enough, but let me finish by saying that I avoid giving out any of my personal contact details or emailing users. I highly recommend using tools like StackOverflow, serverfault.com, and unix.stackexchange.com for cases like this, however, feel free to comment if you ever find a fault or have some information that may be useful, or even found an alternative similar tutorial that you find useful.

    2. hi ,thanks for response, we feel not good on vmware, so we want to change to others, we will use kvm then. right now, we are using centos on vmware . so we will install cents on kvm

  3. hi, should i use centos6.5 , 64bit to setup kvm or ubuntu

    1. If you are doing production work, then definitely use centos 6.5 (or better yet centos 7 if you can as this has a later kernel with more KVM features). I will be doing a tutorial on CentOS 7 KVM as soon as possible (skipping 6.5). I always do things first on Ubuntu as it is always easier and what I use for personal stuff.

  4. i worry centos 7.0 too new, i may use 6.5, can you also do 6.5 tutorial too ,maybe same as 7 ,

    1. I will start with CentOS 7 and if CentOS 6.5 is very similar I will do both.

  5. This comment has been removed by a blog administrator.

    1. This comment was deleted for not being specific to this post. However, the user may find the lvextend command in the LVM cheatsheet useful [ http://programster.blogspot.com/2014/06/lvm-cheatsheet.html ]