OpenVZ Ubuntu Install


I have been using OpenVZ for years, and it does everything I have ever needed it to do. I have run mail servers, and web servers, and everything else you would want to do. I have even installed OpenVPN on a client successfully. Here is the host install for Ubuntu on 8.04 Hardy. I use the installer from https://help.ubuntu.com/community/OpenVZ. They also have a Fiesty install for the server on the ubuntu help page. If you have issue with my install of Openvz on Ubuntu server.

Install the kernel and tools

$ sudo apt-get install linux-openvz vzctl

Important! Please use the linux-image-2.6.24-17-openvz kernel or later as linux-image-2.6.24-16-openvz is broken and the kernel does not boot, see [WWW] https://bugs.launchpad.net/ubuntu/+source/linux/+bug/210672.

Reboot into the openvz kernel

Remove the -server kernel or the -generic if you are on a desktop machine

$ sudo apt-get remove --purge --auto-remove `dpkg -l linux-image-*server | awk '$1 ~ /ii/ {print $2}'`

Change the sysctl variables in /etc/sysctl.conf

This step might not be necessary once the vzctl package is going to be updated

# On Hardware Node we generally need
# packet forwarding enabled and proxy arp disabled

net.ipv4.conf.default.forwarding=1
net.ipv4.conf.default.proxy_arp = 0
net.ipv4.ip_forward=1

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

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

# TCP Explict Congestion Notification
#net.ipv4.tcp_ecn = 0

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

Apply the sysctl changes

$ sudo sysctl -p

Create a symlink to /vz because most of the vz tools expects the OpenVZ folders to reside there. This step is not necessary, but can eliminate further problems when other vz related components are installed.

$ sudo ln -s /var/lib/vz /vz

Now that you have a working openvz kernel installed, and sysctl options setup we We want to download a template from http://openvz.org/download/template/cache/. I use the ubuntu-8.04-i386-minimal.tar.gz template for my containers. Here are the commands to download the template.

$ cd /var/lib/vz/template/cache
$ wget http://download.openvz.org/template/precreated/ubuntu-8.04-i386-minimal.tar.gz

We have a host system, and template for a container.  We now just have to setup a container.

Creating a container

$ sudo vzctl create 101 --ostemplate ubuntu-8.04-i386-minimal

Adding an ip address

$ sudo vzctl set 101 --ipadd SET_IP_ADDRESS_HERE --save

Setting hostname

$ sudo vzctl set 101 --hostname SET_HOSTNAME_HERE --save

Setting nameserver

$  sudo vzctl set 101 --nameserver SET_NAMESERVER_IP_HERE --save

Setting virtual name

$ sudo vzctl set 101 --name SET_VENAME_HERE --save

Now that we have all this set we will start the container.

$ sudo vzctl start 101 (you can also use the VENAME)

There seems to be a strange bug in the kernel that is causing the networking, and hostname not to copy over to the container so here is a simple fix I have come up with.  These aren't really fixes, but workarounds for us who love Ubuntu, and know they will fix the problem next release.  Hopefully.

Problem:

cp: skipping file `/etc/network/interfaces', as it was replaced while being copied
/bin/cp: skipping file `/etc/hosts', as it was replaced while being copied

Fixing the networking problem.

Backup the /etc/vz/dists/scripts/debian-add_ip.sh file however you feel like.

$ vim /etc/vz/dists/scripts/debian-add_ip.sh

And replace the cp line:
# cp -f ${CFGFILE} ${CFGFILE}.bak

with this:
[ -e ${CFGFILE}.bak ] && rm ${CFGFILE}.bak
cat ${CFGFILE} >${CFGFILE}.bak

Fixing the hostname problem.

$ sudo vzctl enter 101
$ vi /etc/hostname
Add what you want the hostname to be set to. Save the file and exit the container with
$ exit

Restart the container.
$ sudo vzctl stop 101
$ sudo vzctl start 101

Once you restart the container you will be all fixed, but the error will still show up for /etc/hosts but who needs that anyway.  I believe just editing the file in the container will be sufficient for the changes you need.

You have a running hardware node and a running container you need to some minor configurations to the container.

Enter the container this will chroot you in the container.  Make sure you are not on the hardware node.

$ sudo vzctl enter 101

You will need a language support. Of course I use english so here is the command.

$ apt-get install language-pack-en-base

Set the timezone

$ dpkg-reconfigure tzdata

Exit the container

$ exit

If you want to stop the vps do the following.

$ sudo vzctl stop 101 (you can also use the VENAME)

There is a bug in the 2.6.24-17 kernel that affects the cp and mv functionality inside the contain and prevents the network settings from being copied.

To take a backup or snapshot just run a vzctl chkpnt on the hardware node.

$ sudo vzctl chkpnt 101 --dumpfile DUMPFILE_NAME

Restore from a chkpnt or revert to a snapshot.

$ sudo vzctl restore 101 --dumpfile DUMPFILE_NAME

If you want to destroy a container and start over just use the following command.

$ sudo vzctl destroy 101

Here are some other usable commands to run on the hardware node

Running list of VPS's

$ sudo vzlist

List all Containers

$ sudo vzlist -a

I also tend to know how many containers I will install on a hardware node, and use vzsplit to build my configs.  I tend to change the size of the DISKSPACE I use for each one, but other then that it is a nice command. It asks for the number ot VEs.  Just enter the number of containers you want.  It will output a config for you to use in your /etc/vz/conf/101.conf.

$ vzsplit
Enter the number of VEs:

Let me know if you have any questions about my walkthrough please add a comment.

  1. No comments yet.

You must be logged in to post a comment.