Roll your own Subversion server, Server Setup

We’ll begin by initializing a Cloud Server in the Rackspace Cloud and loading a Centos 5.3 image. You can always use a different Linux distribution but this guide will focus on this distro and its own packages and nuances. Once that’s done, set up your VPS by following Slicehost’s CentOS setup guides Page 1 and Page 2. Be sure to get the ‘Development Tools’ meta-package installed as it contains most of the tools we will use later on and will install Subversion right off the bat.

There are two additions to the guide that will be useful for us. First, when setting up the firewall, open up port 10000 which will let us access our Webmin interface once installed. The following line will open that up:

iptables -A INPUT -p tcp --dport 10000 -j ACCEPT

Second, add the /sbin and /usr/sbin directories to your $PATH environment variable. Modify the ~/.bash_profile file and change the line:

PATH=$PATH:$HOME/bin

To:

PATH=/sbin:/usr/sbin:$PATH:$HOME/bin

Don’t forget to run “source .bash_profile” to apply the changes instantly

Hostname

Next, lets give our VPS a hostname which we will use to refer to it from now on. I will use the hostname code.example.com from now on. This Rackspace Cloud Guide will get you set up. If you will send out mail from your server, it would be a good idea to change your Reverse DNS pointer as well which you can do so by following this guide.

Webmin

While optional, Webmin provides a web-based GUI to administer many aspects of your server. I find it easier to change firewall rules and setup cron jobs from Webmin for example. Unfortunately there are no Nginx or Svnserve modules yet so we’ll still have to rely on the command line for now.

The easiest way to install Webmin on CentOS is to use their Webmin YUM repo, instructions for which are found at Webmin.com. Once installed, visit your Webmin install at http://code.example.com:10000/ (replace code.example.com with your domain or IP) and login with the username root and your root password. If you can’t connect, make sure that TCP port 10000 is open on your firewall and that the Webmin server is running.

Optimizations

The Webmin homepage has some basic stats which will be critical to a stable server once everything is installed. For now we can see that my RAM usage is around 85 MB and that I am using no Virtual memory which is good. Here’s what my page looks like:

Initial Memory Usage

Let’s see what is currently running on our server and see if we can optimize anything. On the left frame, go to:

System -> Running Processes

Click on Display: Memory to see the processes arranged by memory usage. Here’s what I see:

Detailed Memory Usage

Hmm, the #1 process is something called yum-updatesd and it seems to be using a sizable chunk of memory. A quick visit to the manpage tells us that it is a Update notifier daemon which sounds good but Google says otherwise. Let’s disable it by issuing the command:

sudo /etc/init.d/yum-updatesd stop
...
Stopping yum-updatesd:                                     [  OK  ]

Now let’s stop it from starting on boot with the following:

sudo chkconfig yum-updatesd off

And finally, check that it is indeed off running this command and checking the output:

sudo chkconfig --list yum-updatesd
...
yum-updatesd    0:off   1:off   2:off   3:off   4:off   5:off   6:off

Reboot your machine and let’s see what our base memory footprint is. Here is mine:

Optimized memory usage

Might not look like much since I’ve gone from 85 MB to about 68 MB but on a 256 MB slice, every MB counts!

Ruby on Rails, MySQL, and Nginx

With YUM, installing the web and db servers is a piece of cake. Once again, Slicehost has a great set of articles for us to follow.

Ruby on Rails

We first get Ruby on Rails installed by following the Ruby on Rails guide. Everything should be straightforward until you get to the part where you install Sqlite3 as this will happen:

sudo gem install sqlite3-ruby
ERROR:  Error installing sqlite3-ruby:
    sqlite3-ruby requires Ruby version > 1.8.5

We have Ruby 1.8.5 which is not compatible with the latest sqlite3-ruby gem. This happens because gem development and distribution outpaces CentOS’ package updates so this out-of-sync condition between RubyGems and YUM based packages can occur. Fortunately, the fix is easy (after a bit of Googling of course). All we have to do is install a previous version of the gem using the -v option. Version 1.2.4 of the sqlite3-ruby gem is that latest one compatible with Ruby 1.8.5 so let’s install that version:

sudo gem install sqlite3-ruby -v 1.2.4

Now let’s do the simple test to see if the module is working correctly:

irb
irb(main):001:0> require 'rubygems'
=> true
irb(main):002:0> require 'sqlite3'
=> true

If require sqlite3 returns true, you’re good to go. And that’s it! RoR is now installed.

MySQL

Now we add the database backend by following the Installing MySQL guide (skip the PHP section). I suggest you follow this Securing your MySQL Install guide right after to tighten up security on your DB.

Again, you will run into a similar problem like we had with the sqlite3-ruby gem.

sudo gem install mysql -- --with-mysql-config=/usr/lib64/mysql/mysql_config
ERROR:  Error installing mysql:
    mysql requires Ruby version >= 1.8.6

Version 2.7 of the mysql gem is the latest one compatible with Ruby 1.8.5 so let’s install that version instead:

sudo gem install mysql -v 2.7 -- --with-mysql-config=/usr/lib64/mysql/mysql_config

Incredibly simple now that we have the right version of the gem. Let’s test it out with:

irb
irb(main):001:0> require 'rubygems'
=> true
irb(main):002:0> require 'mysql'
=> true

So far so good!

Nginx and Thin

For our web stack, we will use Nginx as the front facing component (listening on port 80) which will then proxy non-static requests to a couple of Thin instances listening in the background. There are dozens of methods with which to run RoR and they all have their own pros and cons but this is the easiest method I’ve found with a small memory footprint.

First, install Nginx by following the Installing Nginx via yum guide. I recommend you also follow the Nginx Configuration guide for a couple of optimizations, especially regarding gzip compression.

Next, install Thin following the first few steps on the thin web server for Ruby guide. We don’t have our RoR app set up yet so we will look at that section in the next article.

End Notes

This should all be straightforward and it might look simple, but believe it or not, your tiny 256 MB slice is almost ready to serve a fully featured Subversion server.

In the next article we will setup our Subversion server which will lay the foundation of the rest of the system.

Tags: , , ,


  • DarcyKitchin
    I'm quite sure no one still uses a system with only 256 MB of memory. Even in 2009 people had at least 500 MB of RAM.
    Darcy Kitchin @ Domain names
  • Thanks foe posting this!!!
blog comments powered by Disqus