August 13, 2008
I didn’t look at rtorrent and wtorrent at first. The first software I found for the web based Bittorrent client I searched was TorrentFlux (to be exact Torrentflux-b4rt). The installing was not complicated, but the software is really bad. For once the php part starts for every torrent a new Bittorrent command line program process which takes really really much memory if you’ve like 10 torrents.Their is also the problem that such processes did tend to hang and it was not possible to solve all problems via the web GUI. The next big part was that the web GUI put a really high CPU load on my browsers if the AJAX update was activated (even if it was set to 30 sec). Basically it was an non integrated set of peaces which made more work than it helped me to save, and as I could not set the overall bandwidth I started to search for something else.
It was not easy to find rtorrrent and wtorrent, don’t know why I didn’t find it when I searched for “web based bittorrent client”. I hope my howto helps somewhat in this regard. The combination of these two applications work for me now without any problems. Low CPU load on the client and Server, small footprint on the server and stable. And it works with torrents which didn’t work with torrentflux.
This Howto describes how to setup rtorrent with the web GUI wtorrent (on lighttpd) on an Ubuntu Hardy and in my case within an OpenVZ VE. Of course this Howto works also if you don’t use visualization and it should also work with the current Debian release. Whats special of my setup is that I want to run the rtorrent and wtorrent within a VE, but the finished data should be stored on an remote NFS server (e.g. a small NAS).
1. OpenVZ VE Setup
First we create the VE from a template, you can download one from OpenVZ:
vzctl create XXX --ostemplate ubuntu-8.04-i386-minimal --hostname torrent
After this we add an IP address and activate the NFS client support within the VE:
vzctl set XXX --ipadd XXX.XXX.XXX.XXX --save
vzctl set XXX --features "nfs:on" --save
After this I recommend to change the limits of your VE, I use following (configured via /etc/openvz/conf/XXX.conf)
Check them on you system that the are not too low. Now you start your VE with
vzctl start XXX
vzctl enter XXX
Take a look at configured DNS servers and that you can reach the Internet with this VE. Put your NFS server into
/etc/fstab like this:
yyy.yyy.yyy.yy:/nfsshare /media/nfs nfs soft,udp,auto,user,rsize=32768,wsize=32768 0 0
Don’t forget to create the directory and to
apt-get install nfs-common. After this try to mount the share.
2. Configure your firewall
This part of the setup is based on following assumption:
- Your Linux system is used as DSL/Cable Router and
- you’ve only one wordwide IP address and
- your VE has a private IP address.
It is assumed that your VE can connect to the internet, as only the special setup for the bittorrent ports is shown. The following iptables code will redirect the required ports to your VE, where xxx.xxx.xxx.xxx is the IP of your VE.
iptables -t nat -A PREROUTING -i ppp0 -p tcp --dport 63963:63981 -j DNAT --to-destination xxx.xxx.xxx.xxx
iptables -A FORWARD -d xxx.xxx.xxx.xxx -p tcp --dport 63963:63981 -m state --state NEW,ESTABLISHED,RELATED -j ACCEPT
iptables -t nat -A PREROUTING -i ppp0 -p tcp --dport 63982 -j DNAT --to-destination xxx.xxx.xxx.xxx
iptables -A FORWARD -d xxx.xxx.xxx.xxx -p tcp --dport 63982 -m state --state NEW,ESTABLISHED,RELATED -j ACCEPT
iptables -t nat -A PREROUTING -i ppp0 -p udp --dport 63982 -j DNAT --to-destination xxx.xxx.xxx.xxx
iptables -A FORWARD -d xxx.xxx.xxx.xxx -p udp --dport 63982 -m state --state NEW,ESTABLISHED,RELATED -j ACCEPT
3. Install the base and rtorrent
At first the packages we need: (As more packages we can use the less work we’ll have)
apt-get install rtorrent screen mc wget lighttpd gawk php5-cgi php5-common php5-sqlite php5-xmlrpc sqlite unzip php5-curl
Now download following file and save it as /etc/init.d/rtorrent in your VE and activated for automatic startup at boot time with
update-rc.d rtorrent defaults 25
After this we need to add an user under which the rtorrrent process runs and
# adduser --disabled-login rt
# usermod -aG tty rt
# su - rt
$ wget http://robert.penz.name/wp-content/uploads/2008/08/rtorrent.rc -O .rtorrent.rc
$ mkdir /home/rt/session
/home/rt/.rtorrent.rc file to your needs. You should try out rtrorrent after any config file change, to avoid problems with syntax errors or that stuff.
# su - rt
If it started press CTRL-Q to get out.
If all worked start it with
4. lighttpd setup
This sections shows how to setup lighttpd for rtorrent XML RPC and for wtorrent. Add
"mod_scgi" to the
/etc/lighttpd/lighttpd.conf and add following there too:
url.access-deny = ("~", ".inc", ".db", ".tpl.php", ".cls.php",)
Create following file
/etc/lighttpd/conf-available/10-scgi.conf with following content:
scgi.server = (
"/RPC2" => # RT_DIR
( "127.0.0.1" =>
"host" => "127.0.0.1", # Ip where rtorrent is listening
"port" => 5000, # Port specified in .rtorrent.rc
"check-local" => "disable"
Enable following two configs by setting a symlink:
# cd /etc/lighttpd/conf-enabled/
# ln -s ../conf-available/10-cgi.conf .
# ln -s ../conf-available/10-scgi.conf .
Restart the lighttpd:
5. Install the wtorrent
Get the newest version and configure it:
# cd /var/www/
# rm index.lighttpd.html
# wget "http://www.wtorrent-project.org/trac/changeset/latest/trunk/?old_path=%2F&format=zip" -O wtorrent.zip
#mv trunk/wtorrent/* .
#rm -rf trunk
# cp sample.user.conf.php user.conf.php
Change this file according your settings, specially the lines.
define( 'DIR_TORRENTS', 'torrents/');
define( 'DIR_EXEC', '/var/www/');
define( 'DIR_DOWNLOAD', '/home/rt/doing');
After this make everything belong to www-data and read/writable.
#chown -R www-data:www-data *
#chmod -R 755 *
After the install is finished do following:
# mv install.php install.php_deactivated
# mv install2.php install2.php_deactivated
You should be able to login via http://xxx.xxx.xxx.xxx/