Deploying OpenVZ Containers

OpenVZ is container-based virtualization for Linux in the likes of LXC. OpenVZ creates multiple secure, isolated Linux containers on a single physical server. [1]
It consists of an optional custom Linux kernel and command-line tools (mainly vzctl).

In this post I'll demonstrate how to install, configure and run an OpenVZ container, bridged to the outside world.

First, lets install it:
This should automatically update the GRUB bootloader. Now let's install the OpenVZ userspace tools:
To enable communication between the container and the OS add the following kernel tunables:
Reboot into the new OpenVZ aware kernel:
Before we can create virtual machines with OpenVZ, we need to have a template for the distribution that we want to use in the virtual machines in the /vz/template/cache directory.
You can download one from http://wiki.openvz.org/Download/template/precreated.
Let's download a CentOS 6 template:
Setup the container and make it start on boot:
Note that each container must have an unique Id, in this case 10.Now let's setup a hostname and IP address:
Next lets set the maximum number of non-TCP sockets (local sockets, UDP and other types of sockets) and use Google DNS inside the container:
Let's start the container:
This will create a virtual interface with a name similar to this:
Now lets create a bridge and add our external interface p2p1 and the interface of the container to the bridge br0, so that we can access it from outside:
Time to change the root password:
To enter the container use:
To stop, restart or destroy the container run:
To get a list of all containers execute:
All the configuration commands that we executed in the previous steps got saved in the following file:

You can create this configuration file manually instead of using the OpenVZ userspace tools as well.

Experimenting with Ploop:
Resources: [1]. http://openvz.org/

No comments:

Post a Comment