VPS-like Virtualization sollution for Rails Servers: OpenVZ

This article shows how to create multiple VPS-es using OpenVZ and how to configure those VPS-es as a Rails prod/testing server.

It is an updated and improved version of http://wiki.openvz.org/Quick_installation

Why OpenVZ?

+ low overhead, good performace (claiming only 3% penalty)

+ soft memory allocation

+ free

+ relatively easy to install/manage

– requires both host and to guest OS be  Linux

– no GUI on guest machines

Install OpenVZ on host machine

The used machine is a Ubuntu 8.04 server. I recommend using this version because it is a LTS version (supported until 2010)

sudo apt-get upgrade
sudo su
ln -sf /bin/bash /bin/sh
/etc/init.d/apparmor stop
update-rc.d -f apparmor remove
apt-get remove apparmor apparmor-utils
apt-get install linux-openvz
apt-get install vzctl vzquota
Add followind lines to /etc/sysctl.conf
net.ipv4.conf.default.proxy_arp = 0
kernel.sysrq = 1
net.ipv4.conf.default.send_redirects = 1
net.ipv4.conf.all.send_redirects = 0

Next, you need to get a patched version of the current kernel

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

The installed kernel should now be set as the default boot option

vim /boot/grub/menu.lst

Select the patched kernel as the default boot option.

sudo reboot

To setup the machine:

vzctl create 101 --ostemplate ubuntu-8.04-x86 --config vps.basic
vzctl set 101 --hostname test.example.com --save
vzctl set 101 --ipadd --save
vzctl set 101 --onboot yes --save
vzctl set 101 --nameserver  --nameserver --save
vzctl restart 101
vzctl exec 101 passwd

To set up more memory and disk space::

vzctl set 101 --privvmpages $((256 * 512)) --save
vzctl set 101 --diskspace 3G:5G --save


To start the created machine:

vzctl start 101

Setup guest machine

apt-get update
apt-get install language-pack-en-base
apt-get upgrade

Installing rails

sudo apt-get install ruby rdoc ri irb
sudo apt-get install git-core
sudo apt-get install libruby libmysql-ruby
sudo apt-get install libopenssl-ruby
sudo apt-get install ruby1.8-dev
wget http://rubyforge.org/frs/download.php/57643/rubygems-1.3.4.tgz
tar -zxf rubygems-1.3.4.tgz
ruby rubygems-1.3.4/setup.rb

gem1.8 install rails
gem1.8 install rcov ruby-debug capistrano-ext

Passenger setup

apt-get install build-essential
apt-get install apache2-prefork-dev libapr1-dev libaprutil1-dev
gem install passenger

To clone a guest:


vzdump --compress --dumpdir /home/backup --stop 101

vzdump --restore /home/vzdump-102.tgz 101

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: