Installing rtorrent + ruTorrent on Ubuntu Server 10.04 LTS

First things first. To give credit where it’s due, I have to link to sharky’s tutorial at filesharefreak.com. Much of my tutorial is copied from there, with a few changes to include my own personal preferences as well as a few fixes that I had to implement for my particular setup.

There’s no question that for Linux users, rtorrent is a fantastic lightweight bittorrent client.  But, if you’re like me, you prefer a nice web user interface (WebUI) for your rtorrent as opposed to its not-user-friendly text interface.  That’s where ruTorrent comes in.  It closely mimics uTorrent’s user interface, and is therefore very user-friendly and very welcoming to Windows users looking to switch to Linux for their torrenting.

Step 1: Accessing Your Server

Should be obvious, but I feel I should include it anyway. If you have a monitor and keyboard connected to your server, of course you can use them. Just log in and proceed to Step 2. Otherwise, you’ll need a way to access your server remotely, be it from across the house or further.

If you’re installing Ubuntu Server, you have an option to install a Secure Shell (SSH) server during the install process. That’s easiest. But if you’ve installed Debian or Ubuntu’s desktop version, you will need to install it (sudo aptitude install openssh-server ) if you haven’t already.  Then it’s just a matter of connecting to your server using a program like Putty if you’re in Windows.  Mac OS X and Linux have SSH built-in, so you can just run it from a command line (ie.ssh <ipaddress> ).

Step 2: Install Necessary Packages

In order to use rtorrent with ruTorrent, you’ll need to install a web server as well as ensure that a few dependencies are met and some tools to compile rtorrent (don’t be scared, it’ll work better, and I’ll explain why in Step #3).  I use Apache web server, some will use lighttpd.  I only chose Apache because my server also serves as a test platform for other web projects (ie. this site and the others listed under “Web Portfolio”) in addition to ruTorrent.

I prefer to install packages via the command line (again, don’t be scared, I’ll explain below) in Linux, especially when I have multiple packages to install, as is the case here.

First, make sure you have a list of current versions of packages in the repositories:
sudo aptitude update

When that’s finished, you’re ready to start installing tools, dependencies and the other packages needed to run your server. First, let’s make sure we have all of the packages that rtorrent will depend on:
sudo build-dep rtorrent

Now we can install the tools to compile rtorrent and the Apache web server we’ll use to access the ruTorrent WebUI:
$sudo aptitude install -y build-essential pkg-config libcurl4-openssl-dev libsigc++-2.0-dev libncurses5-dev screen subversion libterm-readline-gnu-perl php5-cgi apache2-server apache2-utils libapache2-mod-scgi

Where "-y" means that the package manager, Aptitude, will assume the answer will be "yes" instead of asking for confirmation that you want to install these packages. See that list of packages? It’s much easier to type out on the command line than to search and check them off in the Software Center, no? Alright, that’s done.

Step 3: Compile rtorrent

Okay, if using the command line is off-putting, then this is where Linux neophytes get scared.  For those that really don’t want to compile from source, you don’t have to.  You can skip Step #1, install Apache and rtorrent from the Ubuntu Software Center and skip ahead to configure ruTorrent and Apache.  And it’ll pretty much work.  But your mileage may vary because the version of rtorrent in Ubuntu’s (and Debian’s) repositories is compiled with an older version of xmlrpc-c.  You’ll get a warning in ruTorrent informing you of this, and in my case, file sizes of torrents and their files (and, by extension, amount downloaded, uploaded, rate and ratio) were not being displayed correctly.  So, you’ve been warned.

Now, let’s compile rtorrent and its components.  First, libtorrent:
cd /tmp
sudo wget http://libtorrent.rakshasa.no/downloads/libtorrent-0.12.6.tar.gz
sudo tar zxfv libtorrent-0.12.6.tar.gz
cd libtorrent-0.12.6
sudo ./configure
sudo make
sudo make install

So what’s that mean?  Well, in the first line we navigate to a temporary directory, /tmp.  Then we download the source code for libtorrent, extract it, enter the directory containing the extracted files, and the last three lines are where we actually compile and install the application.

Pretty much the same deal for xmlrp-c:
cd /tmp
sudo svn checkout http://xmlrpc-c.svn.sourceforge.net/svnroot/xmlrpc-c/stable xmlrpc-c
cd xmlrpc-c/
sudo ./configure
sudo make
sudo make install

Great.  That’s done.  On to rtorrent:
cd /tmp
sudo wget http://libtorrent.rakshasa.no/downloads/rtorrent-0.8.6.tar.gz
sudo tar zxfv rtorrent-0.8.6.tar.gz
cd rtorrent-0.8.6
sudo ./configure --with-xmlrpc-c
sudo make
sudo make install

That wasn’t so bad, was it?

Step 4: Configure rtorrent

Like most Linux applications, rtorrent is configured with a simple plain-text file.  So we’ll have to create that file, and fill it with the requisite settings.  To do that, navigate to the home folder of the user that will be running rtorrent (some create a separate user for this, I found it to be more trouble than it was worth and just run it under my own account now, but this is up to you).  If you’re logged in as that user, simply typing “cd” at the command line will suffice.

So, once we’re in the home directory, we’ll have to create and open the file for editing.  This can be done in one step with Debian and Ubuntu’s default text editor, nano:
nano .rtorrent.rc
Now that the file’s loaded up and ready for editing, let’s get some settings in there. “Chris” is the user that will run rtorrent; edit as necessary for your situation, and do the same for your directories, creating directories as needed (ie. mkdir .rtorrent/session downloads):
directory = /home/chris/downloads
scgi_port = localhost:5000 #Important - we need this for ruTorrent to work
session = /home/chris/.rtorrent/session
schedule = low_diskspace,5,60,close_low_diskspace=100M
port_range = 51515-61234
port_random = no
use_udp_trackers = no
encryption = allow_incoming,try_outgoing
dht = off
peer_exchange = no
#The Following Are VERY Important
encoding_list = UTF-8
scgi_local = /tmp/rpc.socket
schedule = chmod,0,0,"execute=chmod,777,/tmp/rpc.socket"

My settings are pretty basic, but there’s a lot you can do with your configuration file.  Check out this page if you’d like to find out how to automatically move files upon completion, change permissions, set up watch directories, and so on.  It’s all up to you.

Great, that’s done.  You have a fully-functional rtorrent that you can run now.  But we want a WebUI, so…

Step 5: Setting up ruTorrent

First, download it.  Second, we’ll have to edit it so that it can find and connect to rtorrent.
cd /var/www/rutorrent/conf
nano config.php

Now look for the line “$scgi_port = 5000;” and also take note of the following line: “$XMLRPCMountPoint = "/RPC2".” These are vital for allowing ruTorrent to communicate with rtorrent. The values in ruTorrent’s config.php must match up with the values in rtorrent’s configuration file above and in Apache’s configuration.  Which brings us to…

Step 6: Apache

Not a whole lot to do here, we just need to make sure that Apache can allow ruTorrent to connect to rtorrent, and it is also wise to password protect your rutorrent directory on the web server.

So, we’ll navigate to Apache’s configuration files and configure them:
cd /etc/apache2
sudo nano httpd.conf

SCGIMount /RPC2 127.0.0.1:5000 
<directory /var/www/rutorrent/>
AuthName "Log In"
AuthType Basic
AuthUserFile /home/chris/.htpasswd
AuthGroupFile /dev/null
require user chris
</directory>

The First line was referenced in the last paragraph of Step #5.  Those numbers need to match those in rtorrent’s .rtorrent.rc and ruTorrent’s config.php.  You can change them as you see fit (that is /RPC2 can be changed to /RPCx, where x is a positive integer, and the port number can be changed from 5000; in typical practice this would be changed to 5001, or 5002, etc.), but make sure you do it across the board.

The lines below deal with security; password-protecting the rutorrent directory on your web server.  For this to work, you will need to create the .htpasswd file referred to in line 5.  You can do this simply by running the htpasswd command:
htpasswd -c /home/chris/.htpasswd chris

For more information on htpasswd, visit Apache.org.

Next, we’ll have to make sure that SCGI is enabled in Apache, to do this, we simply need to copy it to the correct location:
sudo cp mods-available/scgi.load mods-enabled/scgi.load
and restart Apache:
sudo /etc/init.d/apache2 restart

That’s it!  To run rtorrent, simply type “screen rtorrent” at the command line.  Screen is used so that you can close your SSH session (or continue to use it for something else) while keeping rtorrent running in the background.  For the latter, simply hold “Ctrl” and then hit the “A” and “D” keys in that order (Ctrl+A+D).  rtorrent will disappear but continue to run, to verify this, you can simply type “screen –R” to get it back.  Or, of course, you can verify with your ruTorrent WebUI by typing “http://<server-address-here>/rutorrent” in a web browser.

I’ve had success installing rtorrent on Ubuntu 10.04 Server 32-bit and 64-bit with this method.  I’ve had less success with this version of rtorrent on Debian, so no guarantees that it’ll work.

I believe this guide is complete, but if you do see any omissions, typos, or if you have anything else to contribute, please leave a comment.

Enjoy!

Bookmark and Share

Set Up a Debian LAMP Test Server

I mentioned in an earlier post that I’d explain how to set up a Debian GNU/Linux LAMP (Linux, Apache, MySQL, PHP/Perl) server. So here it is, complete with plenty of screenshots.

Before I get started, a disclaimer: This is a guide to set up a personal test server. I wouldn’t advise using these settings for a live website as I can’t vouch for the security of the setup.

With that out of the way, here are the instructions.

First, you’ll have to boot up from the CD (or DVD) that you downloaded and burned. This will usually just require popping the disc into the drive and powering up the system, but depending on your computer’s BIOS settings, you may need to change boot device priorities so that the system looks to the CD before the hard drive.

Collecting Information for the Installation

When your PC boots from the Debian install disc, you should be greeted with the following screen (click the images below for full-resolution versions):

Boot Screen

Choose “Install,” or, if you prefer, you can choose the graphical installation. The steps are pretty much identical, the only real differences being the fact that the graphical setup is prettier and you can use your mouse.

Next you’ll be asked to select a language:

Language

Choose your language of choice and next you’ll choose your country:

Country

Choose appropriately, then select a keyboard layout:

Country

Again, choose whatever is appropriate for your hardware. Note to Canadian users: Choose the “American English” keyboard layout unless you have a French Canadian keyboard. If you don’t, you may see some odd behaviour (eg. the “?” key may display an accented uppercase “E.”).

Setup will now attempt to connect to your network:

DHCP

If you have any trouble here, you’ll have to troubleshoot your network connection. Once you’re connected, the system will ask for a host name. This is exactly the same thing as the “Computer Name” in Windows.

DHCP

Once you’ve got a unique hostname entered, continue on to specify your time zone:

Time Zone

Be sure to specify the correct time zone (and also make sure your system’s clock is correct), or you may experience funny behaviour in the form of network timeouts, timestamps on files uploaded to the webserver not matching those on the PC you’re working from, etc.

Bookmark and Share

Relocate the /home Directory to a New Partition

The Problem:

A file server that was receiving my nightly backups had its power supply unit give out when a resistor blew up. Since the old 400MHz Celeron machine wasn’t much more than a glorified external hard drive, I decided that instead of replacing the fried part, a more practical, energy-efficient solution would involve putting its 80GB hard drive into another machine, and backing up my important files to that machine instead.

This solution proved the most promising, as now I would have full access to a relatively current copy all of my Desktop, Documents and Pictures directories on both machines – even if one were switched off – in addition to having a nightly backup of my important data.

The only problem here was that when doing my backups, I wanted to keep my files synchronized between the two computers and I didn’t have room for everything in the /home directory on the Stereo PCs small 20GB hard drive.

The Solution:

Hook up the 80GB drive as a slave and move the /home partition on the Linux machine in the livingroom to the larger hard drive.

When I initially installed Ubuntu on my jukebox PC, I figured I’d put everything in one partition as it was only one, small, 20GB drive anyway. When I decided to add the 80GB backup drive to the system, it became apparent that separating /home from the rest of the system would be a good idea as well.

I didn’t want to reinstall anything, and I didn’t want to lose any personal settings (I had multiple user accounts set up for other family members), so the solution was just to move the /home directory. Only a few steps are actually required to accomplish this, and since the steps in the articles I’ve found on the subject have required a little bit of tweaking, I figured I’d write my own how-to both to help others, and to refresh my own memory should I ever need to do it again.

Bookmark and Share

Thin Client Test Server

The Problem:

I needed a web server to practice and test with. The only extra PC that I had lying around was an old thin client.

The Solution:

I picked up a Visara UCT machine at a yard sale for $1. I didn’t know what it was, but it was obviously some sort of PC given the parallel, PS/2, USB, VGA and serial ports in the back. I was thinking maybe one of those point of sale machines. The guy selling it thought it was an old black box. They had several. I should have bought more.

The only downside to this little machine was its lack of memory (only 32 MB of RAM), and its lack of storage (a 16 MB DiskOnModule IDE device). The thing is obviously not designed to do much work on its own. It does only have a 300MHz Geode processor, but that’s good enough for basic tasks. I did some pretty cool stuff with a top-of-the-line Pentium II, 300MHz machine back in 1998. I ended up deciding that this little thing would best serve me as a test web server.

The Result:

Well, I wish I had more to report with this one. All that I did was install more memory (128MB of PC-133 SDRAM) and an old 20GB laptop hard disk drive (HDD). You try to find an operating system that uses less than 16 MB. Even Damn Small Linux – DSL – is at least triple that without anything installed, and those DiskOnModule drives aren’t free like my 20GB was. I had to use an adaptor to connect the thing to the IDE socket on the motherboard, but that was a trivial matter.

The tricky part was finding out where to draw power. This little machine doesn’t have your typical ATX power supply unit (PSU). It has a tiny, silent proprietary device to handle those duties. So, I had to find a way to connect a Molex connector to the device so that I could power the hard drive. Luckily, the motherboard had a four-pin connector not unlike the fan connectors on a typical ATX board, and exactly the same dimensions as a floppy drive’s power connector. Perfect. I just snipped the floppy/Molex connector off of a regular ATX supply, and I had a perfect adapter for this machine.

inside
Inside the Visara UCT, 2.5" laptop hard drive installed

Okay, hardware’s all hooked up. Good to go. Right? Almost. I still needed to install an operating system (OS). How to do this without a CD-ROM? I considered a network boot, and I almost tried a USB drive install, but I wasn’t convinced either would work, the latter especially. A more modern PC wouldn’t have an issue with this, but this is not a powerful system. So I took the easy, tried and true method and connected a spare CD-ROM. You can plug an ATX PSU’s Molex connectors into the IDE devices – (HDD and CD in this case) even though it’s not plugged into an external power source. Just connect it to something on the motherboard, and since the computer is turned on, current will flow through the connected wires. In my case it was the aforementioned floppy-connector-sized pins that I plugged into.

Now to install the OS. My choice was Debian GNU/Linux. Free, open-source, and robust. All that, and an ideal platform for running the world’s most popular web server: Apache. Installation was very straightforward, contrary to popular belief. After that I installed Samba to share folders with my Windows PCs, MySQL Server for a databse solution, and openSSH to administer the machine remotely via Putty. Simple.

test server complete
Completed, painted and working; stacked to give an impression of its size

UPDATE:
For those interested, I’ve written a guide to setting up a Debian GNU/Linux server like the one installed in this system.

Bookmark and Share