Zachary Loeber

The personal website of Zachary Loeber.

Linux: Headless Ubuntu Torrent Home Server

So it got to that time of the year where I feel the itch to upgrade my aging home server. I assessed the situation and realized that, for what it does, my current server does not need any kind of hardware upgrade. So I just decided to rebuild it with Ubuntu 11.04 64 bit and change up the server software a bit to be more accessible to my wife as well as to be a bit more modern (torrentflux and derivatives have been dead for a while now).

Preface

In this rebuild I wanted to make the services on the server more accessible for my wife. So my software selection is a bit more cohesive as I want all the services to be accessible to more than just the technically inclined. I also wanted her to be able to download missed TV shows without my help should she find the need to do so.

Software I chose to install:

  • Peer Guardian for Linux – Blocks IP addresses from known haters and other groups of your choice.
  • Mediatomb PS3 Media Server – A upnp server for playing movies and other media
  • Transmission – A pretty cool bittorrent client
  • Torrentwatch-x – Web based RSS tracker for bittorrents, integrates with transmission
  • Mollify – A simple web based file browser
  • Samba – For windows workstation integration
  • Webmin – I didn’t want to mess with a manual samba configuration so I set this up to simplify things 🙂

Initial Server Install

As I refuse to just post a bunch of screenshots of pressing “next” I’m going to skip the base install documentation. The brief rundown of what to do is to install Ubuntu server 11.04 64 bit, do not select drive encryption, select “OpenSSH server”, “LAMP Server”, and “SAMBA file server” for the core software. If you flubbed this up for whatever reason you can always run “sudo tasksel” to select these metapackages later on.

I started out with some generic apps. For whatever reason add-apt-repository was not available in the 64bit server version of ubuntu 11.04. Install this to make that handy command available again. I add in rkhunter, screen and htop cause I like them 🙂 We also install ntp to update our time automatically:

sudo apt-get install python-software-properties ntp ntpdate rkhunter screen htop

I also modified the base apt repository list: Uncomment the following in /etc/apt/sources.list (sudo nano /etc/apt/sources.list):

deb http://archive.canonical.com/ubuntu natty partner
deb-src http://archive.canonical.com/ubuntu natty partner

Update your system and make our working directory used in the rest of this post. All scripting and commands posted are assuming that this Downloads folder exists, should you do things any other way then you will have to keep that in mind throughout the post and modify things as needed. Adding to that, the whole post is not simply a copy and paste fully scripted out procedure so do things intelligently and with fair warning that your results may vary based on your environment and technical acuity:

sudo apt-get update
sudo apt-get upgrade
cd ~
mkdir Downloads

Peer Guardian for Linux Install

Install the repository and the software. You will be asked a series of questions. You can skip them and modify the pglcmd.conf file directly afterwards if you like. I do recommend you be careful when selecting your block lists. The default should be fine but you may want to add a few more from the list when given the option:

sudo apt-add-repository ppa:jre-phoenix
sudo apt-get update
sudo apt-get install pgld pglcmd

If you skipped or just chose the default wizards then update the default config file to allow services that have nothing to do with torrent traffic in and out of your server:

sudo cp /etc/pgl/pglcmd.conf ~
sudo sed -i 's/WHITE_TCP_OUT=""/WHITE_TCP_OUT="80 443 22"/' /etc/pgl/pglcmd.conf
sudo sed -i 's/WHITE_TCP_IN=""/WHITE_TCP_IN="80 443 22"/' /etc/pgl/pglcmd.conf
sudo sed -i 's/WHITE_IP_OUT=""/WHITE_IP_OUT="192.168.0.0\/16"/' /etc/pgl/pglcmd.conf
sudo sed -i 's/WHITE_IP_IN=""/WHITE_IP_IN="192.168.0.0\/16"/' /etc/pgl/pglcmd.conf
sudo /etc/init.d/pgl reload

If you ever find that an update makes PeerGuardian unable to be started run sudo dpkg-reconfigure –force pglcmd. Here is some extra information taken directly from pgl when it failed to start for me. Make of it what you will:

If any blocklists are missing, they will be downloaded. This may take several

minutes. Please be patient and don’t abort. If you want to follow the update

process, then do in another terminal a

tail -f /var/log/pgl/pglcmd.log

The lists are saved to /var/spool/pgl/.

The installation of pglcmd will fail, if starting pgld fails. So if

downloading the blocklists fails temporarily, the installation will fail. In

this case you may turn the automatic starting off by setting in

/etc/pgl/pglcmd.conf:

INIT=”0″

Then complete the installation and turn the automatic start on again:

sudo dpkg-reconfigure –force pglcmd

Transmission Install

This small guide  should get you going but you still have to look at enabling UPnP/NAT-PMP on your firewall. If you are running TomatoUSB (my new favorite) then go to port forwarding -> UPnP/NAT-PMP to enable this setting. (Note: I wrote this up with without explaining a whole lot, I was looking for something else entirely when I found this well written guide with good explanations on the settings: http://1000umbrellas.com/2010/10/04/updated-transmission-installationconfiguration-on-ubuntu-server).

First install Transmission. Create a new home for transmission, Note that we add the incomplete directory so if a torrent dies or gets interrupted it remains in that directory instead of mucking up your downloads directory. We enable this behavior later on. Make it so you can modify this directory and all its contents by simply being in the debian-transmission group (this coincides with a transmission umask setting we will make shortly). Enable ports 9091 and 51413 (if using ufw, by default this is not enabled and therefore not needed). Finally update the transmission configuration, you need to do this with the daemon entirely stopped or the configuration changes will get overwritten the next time you restart the services:

sudo add-apt-repository ppa:transmissionbt/ppa
sudo apt-get update
sudo apt-get install transmission-daemon
cd /home
sudo mkdir -p ./torrents/download
sudo mkdir ./torrents/upload
sudo mkdir ./torrents/incomplete
sudo chown -R debian-transmission:debian-transmission ./torrents
sudo chmod g+w -R ./torrents/
sudo ufw allow 9091
sudo ufw allow proto tcp to any port 49152:65535
sudo /etc/init.d/transmission-daemon stop
sudo nano /etc/transmission-daemon/settings.json

Replace the following lines to (optionally) set downloaded torrents umask so that members of the debian-transmission group can read and write completed torrents (so you don’t have to sudo to move and delete the files). Also, get rid of authentication and update to your new directory layout:

"download-dir": "/home/torrents/download",
"incomplete-dir": "/home/torrents/incomplete",
"incomplete-dir-enabled": true,
"rpc-authentication-required": false,
"rpc-whitelist": "127.0.0.1,192.168.*.*",
"rpc-username": "",
"rpc-password": "",
"umask": 2,
"port-forwarding-enabled": true,
"peer-port-random-on-start": true,

Add your primary user account to the transmission group, replace with your own login ID:

sudo usermod -a -G debian-transmission <username>

Startup Transmisison:

sudo /etc/init.d/transmission-daemon start

Test Transmission by going to http://servername:9091/transmission/ and uploading a torrent of your choice. When it starts downloading and connecting to peers validate that our blocklist configuration is indeed working by checking the logs in real time:

watch tail -n20 /var/log/pgl/pgld.log

Torrentwatch-X Install

Torrentwatch-X is a nifty web interface for tracking rss feeds which point to torrents for such things as TV shows. I set this up so if my wife needs to get some TV show she missed it is as simple as a few clicks in a browser to download. Below should get everything setup in a way that is integrated with your prior transmission install:

sudo apt-get install php-services-json php5-curl php5-cgi
cd ~/Downloads
wget http://torrentwatch-x.googlecode.com/files/TorrentWatchX-0.8.0.tar.gz -O torrentwatch-x.tar.gz
tar xzvf ./torrentwatch-x.tar.gz
sudo mv ./TorrentWatchX-0.8.0/ /var/www/torrentwatch-x/
sudo cp /var/www/torrentwatch-x/php/config.php.dist /var/www/torrentwatch-x/php/config.php
sudo mkdir /etc/torrentwatch
sudo chown www-data.www-data -R /etc/torrentwatch/
sudo usermod -a -G debian-transmission www-data
sudo mkdir /var/www/torrentwatch-x/download
sudo chown www-data.www-data -R /var/www/torrentwatch-x/
sudo su
echo '*/15 * * * * /usr/bin/php-cgi -q /var/www/torrentwatch-x/rss_dl.php -D >/dev/null 2>&1' >> /var/spool/cron/crontabs/root
exit

Modify /etc/torrentwatch/torrentwatch.config and replace the [Settings] area only with the following to integrate transmission with torrentwatch-x:

[Settings]
Episode Only = 0
Combine Feeds = 1
Transmission Login =
Transmission Password =
Transmission Host = localhost
Transmission Port = 9091
Transmission URI = /transmission/rpc
Watch Dir =
Download Dir = /home/torrents/download
Cache Dir = /var/www/torrentwatch-x/rss_cache/
TVDB Dir = /var/www/torrentwatch-x/tvdb_cache/
Save Torrents =
Run Torrentwatch = True
Client = Transmission
Verify Episode = 1
Only Newer = 1
Download Proper =
Default Feed All =
Deep Directories = 0
Require Episode Info = 1
Disable Hide List =
History = /var/www/torrentwatch-x/rss_cache/rss_dl.history
MatchStyle = regexp
FirstRun =
Extension = torrent
verbosity = 0
Default Seed Ratio = -1
Script =
Email Notifications =
SMTP Server = localhost
TimeZone = UTC
Email Address =
Episodes Only =
Hide Donate Button =

Mollify Install

I opted for installing Mollify for my wife to be able to easily access the server files from any computer. Here is how to get it setup:

cd ~/Downloads
wget "http://www.mollify.org/download/latest.php" -O mollify_1.8.1.zip
unzip ./mollify_1.8.1.zip
sudo mv ./mollify /var/www/
sudo chown -R www-data.www-data /var/www/mollify/
sudo touch /var/www/mollify/backend/configuration.php
sudo nano /var/www/mollify/backend/configuration.php

Enter the following

<?php
$$CONFIGURATION_TYPE = "mysql";
$DB_HOST = "localhost";
$DB_DATABASE = "mollify";
$DB_USER = "mollify";
$DB_PASSWORD = "MollifyPass";
$DB_PORT = "3306";
$DB_SOCKET = "/var/run/mysqld/mysqld.sock";
$DB_TABLE_PREFIX = "mollify_";
?>

Create your database with whatever login and password you want to use:

mysql -u root -p
CREATE DATABASE mollify;
CREATE USER 'mollify'@'localhost' IDENTIFIED BY 'MollifyPass';
GRANT ALL PRIVILEGES ON mollify.* TO 'mollify'@'localhost' WITH GRANT OPTION;

Go to http:///mollify/backend/install/ to complete the mollify installation (basically select next then create an admin account admin/admin). Logon to http:///mollify/backend/admin/.

Select Published Folders on left, Click on the add folder button, Put in the path of /home/torrents/downloaded with the description of “Downloaded Torrents”, Select the new published path and then click on “Add Folder for New Users/Groups”, check your admin account. Give your wife the admin account or create a new one, up to you. Other configuration settings for mollify can be set manually, here is a link to possible options : http://code.google.com/p/mollify/wiki/ConfigurationAdditionalOptions. There are also example configurations at /var/www/mollify/backend/examples

PS3 Media Server Installation

Originally I was going to use mediatomb but I was having all kinds of issues getting it working the way I wanted and the xml config file and extra scripts you would need to get it working well is a total pain in the rear to setup. I finally scratched the mediatomb idea and went with PS3 Media Server. It runs on java and is more memory intensive but I simply do not care at this point (last sentence said in a frustrated tone).  Besides someone already wrote an awesome script to automate the install 🙂

sudo apt-get install xvfb sudo ia32-libs mencoder ffmpeg mplayer vlc sun-java6-jre
sudo su -
wget -q --no-check-certificate https://svn.paissad.net/misc/stuffs/install_PMS.sh -O /tmp/install_PMS.sh && bash /tmp/install_PMS.sh
Xvfb :5 &

Double-check that your user name is still part of the admin group, I found for some reason it was not after running the install process (nano /etc/group, look for the admin group and make sure your account name is listed at the end of the line). Then start a new terminal session with your server with X11 forwarding set (ie. ssh -X yourserver). From here you you have to stop the service, edit your settings, and restart the service:

sudo /etc/init.d/pms-linux stop
sudo pms-linux &

Edit your settings so that you are streaming /home/torrents/download and /home/torrents/upload (or whatever directory you want to stream, I chose these two to be able to automatically stream downloaded torrents and uploaded content quickly). Save your settings, exit, start pms-linux:

sudo /etc/init.d/pms-linux start

You can now just access the simple web terminal to kick off rescans of your media folders should you find the need to do so. The site will be http://:5001/console/

Webmin Installation

This isn’t really needed but I wanted to setup the /home/torrents/download directory to be accessible via samba and I did not want to deal with doing it all via command-line. So I opted for webmin’s samba module to do the configuration:

cd ~/Downloads
sudo apt-get install perl libnet-ssleay-perl openssl libauthen-pam-perl libpam-runtime libio-pty-perl apt-show-versions python
wget 'http://downloads.sourceforge.net/project/webadmin/webmin/1.560/webmin_1.560_all.deb?r=http%3A%2F%2Fsourceforge.net%2Fsettings%2Fmirror_choices%3Fprojectname%3Dwebadmin%26filename%3Dwebmin%2F1.560%2Fwebmin_1.560_all.deb&ts=1313790358&use_mirror=superb-sea2' -O webmin_1.560_all.deb
sudo dpkg -i ./webmin_1.560_all.deb
sudo ufw allow 10000
sudo /usr/share/webmin/changepass.pl /etc/webmin root <yourpass>

You can now logon to your webmin interface by going to https://:10000/ and using /. If this does not work then use root/, select webmin -> Webmin Users -> Convert Unix Users -> select your username and select to convert now. Finally, share out any files/folders that you wish to share using the samba plugin within webmin.

 

comments powered by Disqus