Cheap VPS & Xen Server


Residential Proxy Network - Hourly & Monthly Packages

Building A Virtual Server (VPS) With Debian 3.1 (Sarge) And OpenVZ


In this HowTo I will describe the steps to be taken to prepare a server for OpenVZ virtual machines on Debian 3.1 (Sarge) 32Bit Linux. With OpenVZ you can create multiple Virtual Private Servers (VPS) on the same hardware, similar to Xen and the Linux Vserver project. OpenVZ is the open-source branch of Virtuozzo, a commercial virtualization solution used by many providers that offer virtual servers. The OpenVZ kernal patch is licensed under the GPL license, and the user-level tools are under the QPL license.

In the first chapter I will compile the linux kernel for Debian with the OpenVZ patches. This results in an easy-to-install .deb package. This is nescessary when you need drivers that are not compiled in the stock kernel that is avilable from systs.org.  You can skip the first chapter if the precompiled kernel fulfills your needs and install the kernel as described in chapter 1.2.

I want to say first that this is not the only way of setting up such a system. There are many ways of achieving this goal but this is the way I take. I do not issue any guarantee that this will work for you!

Please note: if you want to use the precompiled OpenVZ kernel, you can skip the sections 1 and 1.1 and go directly to 1.2. If you want to compile your own kernel, please read the sections 1 and 1.1 before you proceed with 1.2.

1 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

1.1 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/stable/022stab078.14/patches/patch-022stab078-combined.gz
gzip -d patch-022stab078-combined.gz
patch -p1 < patch-022stab078-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/stable/022stab078.14/configs/kernel-2.6.8-022stab078-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-022stab078-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

1.2 Installing The OpenVZ Kernel

If you have skipped the first chapter, you can install the precompiled Debian kernel now.

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 kernel-image-2.6.8-stable-ovz

1.3 Installing OpenVZ Tools

Install the packages:

apt-get install vzctl vzquota vzctl-template

Now you should reboot your server:

shutdown -r now

2 Install And Start Your Virtual Private Server (VPS)

OpenVZ.org offers precreated OpenVZ template caches for download:

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

I 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 /var/lib/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 and set the number of sockets to 120:

vzctl set 101 –ipadd 192.168.0.167 –save
vzctl set 101 –numothersock 120 –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

3 Build Your Own Ubuntu OpenVZ Virtual Private Server Template

First install the debootstrap utility from Ubuntu. This allows us to bootstrap Debian Sarge and Ubuntu installations.

cd /tmp
wget http://archive.ubuntulinux.org/ubuntu/pool/main/d/debootstrap/debootstrap_0.3.3.0ubuntu3_all.deb
dpkg -i debootstrap_0.3.3.0ubuntu3_all.deb

Now we bootstrap the Ubuntu installation. I use the VPS ID 110. You can use any ID, as long as it is unused on the server and > 100.

debootstrap –arch i386 dapper /var/lib/vz/private/110 http://archive.ubuntulinux.org/ubuntu

Apply the basic configuration to the VPS:

vzctl set 110 –applyconfig vps.basic –save

Set the name of the template:

echo “OSTEMPLATE=ubuntu-6.06” >> /etc/vz/conf/110.conf

Set the IP and nameserver. If you get this warning: “Warning: configuration file for distribution ubuntu-6.06 not found default used“, ignore it.

vzctl set 110 –ipadd 192.168.0.169 –save
vzctl set 110 –nameserver 192.168.0.2 –save
vzctl set 110 –numothersock 120 –save

Add some additional package sources to the sources.list of the VPS:

echo “deb http://archive.ubuntulinux.org/ubuntu dapper-updates main restricted” >> /var/lib/vz/private/110/etc/apt/sources.list
echo “deb http://archive.ubuntulinux.org/ubuntu dapper universe” >> /var/lib/vz/private/110/etc/apt/sources.list
echo “deb http://security.ubuntu.com/ubuntu dapper-security main restricted” >> /var/lib/vz/private/110/etc/apt/sources.list
echo “deb http://security.ubuntu.com/ubuntu dapper-security universe” >> /var/lib/vz/private/110/etc/apt/sources.list

Start the VPS:

vzctl start 110

Update the system:

vzctl exec 110 apt-get update
vzctl exec 110 apt-get -u upgrade
vzctl exec 110 apt-get install ssh libedit2 openssh-client openssh-server quota

Disable gettys on terminals:

vzctl exec 110 sed -i -e ‘/getty/d’ /etc/inittab

Fix some mounts:

vzctl exec 110 rm -f /etc/mtab
vzctl exec 110 ln -s /proc/mounts /etc/mtab

Run apt-get clean to remove unnecessary packages:

vzctl exec 110 apt-get clean

Stop the VPS and remove the IP addresses:

vzctl set 110 –ipdel all –save
vzctl stop 110

Delete the SSH host keys and create a script thet generates new host keys on first

boot of the VPS:

rm -f /var/lib/vz/private/110/etc/ssh/ssh_host_*
cat << EOF > /var/lib/vz/private/110/etc/rc2.d/S15ssh_gen_host_keys
#!/bin/bash
ssh-keygen -f /etc/ssh/ssh_host_rsa_key -t rsa -N ”
ssh-keygen -f /etc/ssh/ssh_host_dsa_key -t dsa -N ”
rm -f \$0
EOF
chmod a+x /var/lib/vz/private/110/etc/rc2.d/S15ssh_gen_host_keys

Pack the VPS to make it easily installable:

cd /var/lib/vz/private/110
tar czf /var/lib/vz/template/cache/ubuntu-6.06-minimal.tar.gz .

Hint: The dot in the line above is part of the command! It reads ….tar.gz[space][dot]

Now we remove the VPS we used to setup the template:

vzctl destroy 110

To create an instance of our Ubuntu server template, you can use this command:

vzctl create 102 –ostemplate ubuntu-6.06-minimal –config vps.basic

and then follow the other steps described in chapter 2.

Comments

comments