Install And Configure OpenVZ In Ubuntu

In our previous tutorial, we have installed and configured OpenVZ on CentOS. In this tutorial, we will see how to install OpenVZ in Ubuntu 14.04.

1. Add OpenVZ Repository

Switch to root user:

sudo su

First, we will add OpenVZ Repository.

cat << EOF > /etc/apt/sources.list.d/openvz-rhel6.list
deb http://download.openvz.org/debian wheezy main
# deb http://download.openvz.org/debian wheezy-test main
EOF

Import OpenVZ GPG key:

wget http://ftp.openvz.org/debian/archive.key
apt-key add archive.key

2. Install OpenVZ kernel

Update software sources using command:

sudo apt-get update

Now, install OpenVZ kernel:

apt-get install linux-image-openvz-amd64

Or, if you still have i686:

apt-get update && apt-get install linux-image-openvz-686

3. Setting up Kernel parameters

Make sure you have added the following kernel parameters before logging into vz kernel.

vi sysctl.conf

Add the following lines:

# On Hardware Node we generally need
# 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

# Enables source route verification
net.ipv4.conf.all.rp_filter = 1

# Enables the magic-sysrq key
kernel.sysrq = 1

# We do not want all our interfaces to send redirects
net.ipv4.conf.default.send_redirects = 1
net.ipv4.conf.all.send_redirects = 0

5. Install OpenVz usage statistics tools

The following tools to be installed to gather the OpenVZ usage statistics. Here is the reason why you should install these tools.

apt-get install vzctl vzquota ploop vzstats

That’s it. We have successfully installed OpenVZ.

Now, it’s time to reboot and log in to OpenVZ kernel(it should be the default choice in the boot loader). In Ubuntu 14.04, it should be under Advanced options in the boot loader menu.

Ubuntu 14.04 [Running] - Oracle VM VirtualBox_003

Ubuntu 14.04 [Running] - Oracle VM VirtualBox_002

We’ll see how to create virtual machines using OpenVZ in our upcoming tutorials.

While creating VMs, make sure you have the same subnet on both physical and virtual machine. If you want to use different subnet, you have to edit /etc/vz/vz.conf file,

vi /etc/vz/vz.conf

Find and uncomment the line:

NEIGHBOUR_DEVS=detect

And, change it to:

NEIGHBOUR_DEVS=all

That’s it.

Ok, I have installed OpenVZ in Ubuntu, now what?

OpenVZ Home page: