Debianhelp.co.uk


OpenVZ vserver Configuration in Debian

What is OpenVZ?

OpenVZ is an Operating System-level server virtualization solution, built on Linux. OpenVZ creates isolated, secure virtual private servers — VPSs (otherwise known as virtual environments — VE) on a single physical server enabling better server utilization and ensuring that applications do not conflict. Each VPS performs and executes exactly like a stand-alone server; VPSs can be rebooted independently and have root access, users, IP addresses, memory, processes, files, applications, system libraries and configuration files.

Download OpenVZ

http://openvz.org/download

OpenVZ Documentation

http://openvz.org/documentation/

OpenVZ FAQ

http://openvz.org/documentation/faq

Prepare Your Server To Host Virtual Private Servers

First we install some prerequisites for the kernel compilation.

#apt-get install kernel-package libncurses5-dev fakeroot wget bzip2

Compiling The OpenVZ linux kernel

Downloading The Kernel Sources

The OpenVZ patch is currently available for the kernel 2.6.8 only. We will use the vanilla kernel from kernel.org and patch and configure it for our needs. To download and unpack the sources, execute the following commads

#cd /usr/src

#wget http://www.kernel.org/pub/linux/kernel/v2.6/linux-2.6.8.tar.bz2

#tar xjf linux-2.6.8.tar.bz2

#cd linux-2.6.8/

Getting The OpenVZ Patch And Patch The Kernel

Now we download the OpenVZ kernel patch from OpenVZ.org and apply it to the kernel sources.

#wget http://download.openvz.org/kernel/022stab064.1/patches/patch-022stab064-combined.gz

#gzip -d patch-022stab064-combined.gz

#patch -p1 < patch-022stab064-combined

Getting The Kernel Config For OpenVZ

OpenVZ.org offers several kernel configurations from generic i686 to enterprise configurations. I select the generic i686 configuration. You may select another config depending on your hardware and processor. The configs can be downloaded from here: http://openvz.org/download/kernel/

#wget http://download.openvz.org/kernel/022stab064.1/configs/kernel-2.6.8-022stab064-i686.config.ovz

Now run "make menuconfig", select "Load an alternate configuration file" and select the file "/usr/src/linux-2.6.8/kernel-2.6.8-022stab064-i686.config.ovz".

#make menuconfig

If you have some special kernel config requirements, change them now. Then select Exit and then Save to save the kernel configuration.

#make-kpkg clean

Now we compile the kernel.

#fakeroot make-kpkg --revision=OpenVZ.2.6.8 kernel_image

If the compilation stops with an error, run

#make clean

and then re-run the previous commands starting with

#make menuconfig

Installing The OpenVZ Kernel

If you have skipped the first chapter, you can download the precompiled Debian kernel with these commands

#cd /usr/src/

#wget http://downloads.howtoforge.com/debian_openvz_howto/kernel-image-2.6.8-022stab064-up_OpenVZ.2.6.8_i386.deb

No matter if you have compiled your own OpenVZ kernel or use the precompiled one, do this to install it

#dpkg -i /usr/src/kernel-image-2.6.8-022stab064-up_OpenVZ.2.6.8_i386.deb

Now reboot your server

#shutdown -r now

Installing OpenVZ Tools

Add the repository for the OpenVZ Tools to /etc/apt/sources.list:

#echo "deb http://debian.systs.org/ stable openvz" >> /etc/apt/sources.list

#apt-get update

Install the packages

#apt-get install vzctl vzquota

Now you should reboot your server

#shutdown -r now

Install And Start Your Virtual Private Server (VPS)

OpenVZ.org offers precreated OpenVZ template caches for download

http://openvz.org/download/template/cache/

we will show here how to install and start a Fedora 4 minimal template. The steps for the other template caches available on http://openvz.org/download/template/cache/ are exactly the same (in case you do not want to install Fedora 4 in a VPS). If you want to create your own custom templates, please have a look at chapter 3 of this tutorial.

Download the Fedora 4 template

#cd /vz/template/cache

#wget http://download.openvz.org/template/precreated/fedora-core-4-i386-minimal.tar.gz

Create the VPS. The ID of the first VPS is 101. You can choose any numeric ID, as long as the ID is > 100 and unique.

#vzctl create 101 --ostemplate fedora-core-4-i386-minimal --config vps.basic

Now I set some basic settings. Configure this VPS to start automatically on boot

#vzctl set 101 --onboot yes --save

Set the hostname. Replace "test101.mytest.org" with the hostname your VPS shall have

#vzctl set 101 --hostname test101.mytest.org --save

Set the IP of the VPS. Replace 192.168.0.167 with a free IP from your network

#vzctl set 101 --ipadd 192.168.0.167 --save

Set the nameserver in the VPS. Replace 192.168.0.2 with a nameserver reachable from your server

#vzctl set 101 --nameserver 192.168.0.2 --save

Start the VM

#vzctl start 101

Start the SSH server

#vzctl exec 101 /etc/init.d/sshd start

Set the root password inside the virtual server

#vzctl exec 101 passwd

Now you will be able to login to the virtual server with an SSH client, e.g. PuTTY for Windows.

To see the status of the VPS, run

#vzctl status 101

To stop the VPS, run this

#vzctl stop 101

To see the status of all VPS' on the system, run

#vzlist -a