rtorrent

Moderator: frogmaker

frogmaker
Moderator
Moderator
Posty: 55
Rejestracja: 06 maja 2018, 12:57

rtorrent

Post autor: frogmaker »

2. Instalacja programów i paczek.

sudo apt-get update
sudo apt-get upgrade

sudo apt-get install subversion build-essential automake libtool libcppunit-dev libcurl3-dev
sudo apt-get install libsigc++-2.0-dev libcppunit-dev unzip unrar-free curl libncurses-dev
sudo apt-get install apache2 apache2-utils php5 php5-cli php5-curl php-xml-rss php5-xmlrpc
sudo apt-get install php5-sqlite sqlite libapache2-mod-php5 libapache2-mod-xsendfile


3. Instalacja i włączanie modułu scgi.

sudo apt-get install libapache2-mod-scgi
ln -s /etc/apache2/mods-available/scgi.load /etc/apache2/mods-enabled/scgi.load
sudo /etc/init.d/apache2 restart


4. Instalacja XMLRPC.

cd $HOME
sudo mkdir install
cd install
sudo svn checkout http://svn.code.sf.net/p/xmlrpc-c/code/stable xmlrpc-c
cd xmlrpc-c
sudo ./configure --disable-cplusplus
sudo make
sudo make install


5. Instalacja rTorrent.
5.1. Instalacja bibliotek Libtorrent.

cd ..
sudo wget https://github.com/rakshasa/libtorrent/ ... 3.4.tar.gz -O libtorrent-0.13.4.tar.gz
sudo tar xvf libtorrent-0.13.4.tar.gz
cd libtorrent-0.13.4
sudo ./autogen.sh
sudo ./configure
sudo make
sudo make install


5.2. Instalacja rTorrent.

cd ..
sudo wget https://github.com/rakshasa/rtorrent/ar ... 9.4.tar.gz -O rtorrent-0.9.4.tar.gz
sudo tar xvf rtorrent-0.9.4.tar.gz
cd rtorrent-0.9.4
sudo ./autogen.sh
sudo ./configure --with-xmlrpc-c
sudo make
sudo make install
sudo ldconfig



6. Tworzenie folderów potrzebnych do poprawnego funkcjonowania rTorrenta.

sudo mkdir -p /opt/rtorrent/{session,watch,download}
sudo chmod 777 -R /opt/rtorrent/{session,watch,download}
sudo chown rtorrent:rtorrent -R /opt/rtorrent/{session,watch,download}


7. Tworzenie i edycja pliku z konfiguracją użytkownika .rtorrent.rc.

sudo wget https://raw.githubusercontent.com/raksh ... torrent.rc -O /opt/rtorrent/.rtorrent.rc

sudo nano /opt/rtorrent/.rtorrent.rc

--->
# Maksymalna i minimalna ilość perów
min_peers = 40
max_peers = 100

# Same as above but for seeding completed torrents (-1 = same as downloading)
#min_peers_seed = 10
#max_peers_seed = 50

# Maximum number of simultanious uploads per torrent.
#max_uploads =15

# Tu ustawiamy prędkość wysyłania (upload) i pobierania (download) 0=bez ograniczeń
# Zalecana prędkość uploadu to 75% maksymalnej prędkości łącza
download_rate = 0
upload_rate = 8

# DomyÅ›lny katalog do zapisu pobranych plików:
directory = ~/rtorrent/pobrane

#Katalog gdzie zapisywana będzie sesja
session = ~/.session

# Przeszukiwanie danego katalogu na obecność torrentów do pobrania
# Zatrzymywanie gdy torrent (plik torrent) zostanie usuniety
schedule = watch_directory,5,5,load_start=~/rtorrent/pliki-torrent/*.torrent

# Close torrents when diskspace is low.
#schedule = low_diskspace,5,60,close_low_diskspace=100M

# Stop torrents when reaching upload ratio in percent,
# when also reaching total upload in bytes, or when
# reaching final upload ratio in percent.
# example: stop at ratio 2.0 with at least 200 MB uploaded, or else ratio 20.0
#schedule = ratio,60,60,stop_on_ratio=200,200M,2000

# The ip address reported to the tracker.
#ip = 127.0.0.1
#ip = rakshasa.no

# The ip address the listening socket and outgoing connections is
# bound to.
#bind = 127.0.0.1
#bind = rakshasa.no

# Port range to use for listening.
port_range = 8200-8300

# Start opening ports at a random position within the port range.
port_random = yes

# Check hash for finished torrents. Might be usefull until the bug is
# fixed that causes lack of diskspace not to be properly reported.
check_hash = yes

# Set whetever the client should try to connect to UDP trackers.
use_udp_trackers = yes

# Alternative calls to bind and ip that should handle dynamic ip's.
#schedule = ip_tick,0,1800,ip=rakshasa
#schedule = bind_tick,0,1800,bind=rakshasa

# Encryption options, set to none (default) or any combination of the following:
# allow_incoming, try_outgoing, require, require_RC4, enable_retry, prefer_plaintext
#
# The example value allows incoming encrypted connections, starts unencrypted
# outgoing connections but retries with encryption if they fail, preferring
# plaintext to RC4 encryption after the encrypted handshake
#
# encryption = allow_incoming,enable_retry,prefer_plaintext

#
# Do not modify the following parameters unless you know what you're doing.
#

# Hash read-ahead controls how many MB to request the kernel to read
# ahead. If the value is too low the disk may not be fully utilized,
# while if too high the kernel might not be able to keep the read
# pages in memory thus end up trashing.
#hash_read_ahead = 10

# Interval between attempts to check the hash, in milliseconds.
#hash_interval = 100

# Number of attempts to check the hash while using the mincore status,
# before forcing. Overworked systems might need lower values to get a
# decent hash checking rate.
#hash_max_tries = 10

# Max number of files to keep open simultaniously.
#max_open_files = 128

# Number of sockets to simultaneously keep open.
#max_open_sockets = <no default>


# Example of scheduling commands: Switch between two ip's every 5
# seconds.
#schedule = "ip_tick1,5,10,ip=torretta"
#schedule = "ip_tick2,10,10,ip=lampedusa"

# Remove a scheduled event.
#schedule_remove = "ip_tick1"# Maksymalna i minimalna ilość perów
min_peers = 40
max_peers = 100

# Same as above but for seeding completed torrents (-1 = same as downloading)
#min_peers_seed = 10
#max_peers_seed = 50

# Maximum number of simultanious uploads per torrent.
#max_uploads =15

# Tu ustawiamy prędkość wysyłania (upload) i pobierania (download) 0=bez ograniczeń
# Zalecana prędkość uploadu to 75% maksymalnej prędkości łącza
download_rate = 0
upload_rate = 8

# Domyślny katalog do zapisu pobranych plików:
directory = ~/rtorrent/pobrane

#Katalog gdzie zapisywana będzie sesja
session = ~/.session

# Przeszukiwanie danego katalogu na obecność torrentów do pobrania
# Zatrzymywanie gdy torrent (plik torrent) zostanie usuniety
schedule = watch_directory,5,5,load_start=~/rtorrent/pliki-torrent/*.torrent

# Close torrents when diskspace is low.
#schedule = low_diskspace,5,60,close_low_diskspace=100M

# Stop torrents when reaching upload ratio in percent,
# when also reaching total upload in bytes, or when
# reaching final upload ratio in percent.
# example: stop at ratio 2.0 with at least 200 MB uploaded, or else ratio 20.0
#schedule = ratio,60,60,stop_on_ratio=200,200M,2000

# The ip address reported to the tracker.
#ip = 127.0.0.1
#ip = rakshasa.no

# The ip address the listening socket and outgoing connections is
# bound to.
#bind = 127.0.0.1
#bind = rakshasa.no

# Port range to use for listening.
port_range = 6890-6999

# Start opening ports at a random position within the port range.
port_random = yes

# Check hash for finished torrents. Might be usefull until the bug is
# fixed that causes lack of diskspace not to be properly reported.
check_hash = yes

# Set whetever the client should try to connect to UDP trackers.
use_udp_trackers = yes

# Alternative calls to bind and ip that should handle dynamic ip's.
#schedule = ip_tick,0,1800,ip=rakshasa
#schedule = bind_tick,0,1800,bind=rakshasa

# Encryption options, set to none (default) or any combination of the following:
# allow_incoming, try_outgoing, require, require_RC4, enable_retry, prefer_plaintext
#
# The example value allows incoming encrypted connections, starts unencrypted
# outgoing connections but retries with encryption if they fail, preferring
# plaintext to RC4 encryption after the encrypted handshake
#
# encryption = allow_incoming,enable_retry,prefer_plaintext

#
# Do not modify the following parameters unless you know what you're doing.
#

# Hash read-ahead controls how many MB to request the kernel to read
# ahead. If the value is too low the disk may not be fully utilized,
# while if too high the kernel might not be able to keep the read
# pages in memory thus end up trashing.
#hash_read_ahead = 10

# Interval between attempts to check the hash, in milliseconds.
#hash_interval = 100

# Number of attempts to check the hash while using the mincore status,
# before forcing. Overworked systems might need lower values to get a
# decent hash checking rate.
#hash_max_tries = 10

# Max number of files to keep open simultaniously.
#max_open_files = 128

# Number of sockets to simultaneously keep open.
#max_open_sockets = <no default>


# Example of scheduling commands: Switch between two ip's every 5
# seconds.
#schedule = "ip_tick1,5,10,ip=torretta"
#schedule = "ip_tick2,10,10,ip=lampedusa"

# Remove a scheduled event.
#schedule_remove = "ip_tick1"
dht = auto
dht_port = 6881

peer_exchange = yes

# SCGI
scgi_port = localhost:5000

#umask
system.umask.set = 0022
frogmaker
Moderator
Moderator
Posty: 55
Rejestracja: 06 maja 2018, 12:57

Re: rtorrent

Post autor: frogmaker »

sudo apt-get install git
sudo git clone https://github.com/Novik/ruTorrent.git /var/www/rutorrent/
sudo chown -R www-data:www-data /var/www/rutorrent
Awatar użytkownika
jurek
Administrator
Administrator
Posty: 104
Rejestracja: 17 maja 2009, 15:48
Lokalizacja: Piast

Re: rtorrent

Post autor: jurek »

Contents [hide]

1. Create new user “rtorrent” and home directory.
2. Update system/server.
3. Install some needed dependencies: Apache2, PHP7 etc.
4. Install rtorrent.
5. Create directories, these are needed for rTorrent to function.
6. Download .rtorrent.rc file and put it in the home directory of the user that will run rTorrent.
7. Install and configure ruTorrent.
7.1. ruTorrent via GIT.
7.2. ruTorrent mobile.
8. Install GeoIP database.
9. Secure ruTorrent web access.
10. Configure access to ruTorrent.
11. Activate Apache2 modules.
12. Secure SCGI (/RPC2) directory.
13. Autostart rTorrent – systemd.
14. Start service rTorrent.

[important]

Tested:

Debian 9.x.x,
rTorrent ver: 9.6,
Libtorrent ver: 13.6,
ruTorrent 3.7 – git,
Apache 2.4.x.

[/important]

Add your username to /etc/sudoers.

su

Root password.

apt-get install sudo
nano /etc/sudoers

Example:

joe ALL=(ALL) ALL

Adding unrar to the APT list.

sudo nano /etc/apt/sources.list

Add these: main contrib non-free at the end of each link line e.g.

deb http://http.debian.net/debian stretch-backports main contrib non-free

then update, upgrade and install unrar

sudo apt-get update
sudo apt-get dist-upgrade
sudo apt-get install unrar

1. Create new user “rtorrent” and home directory.

home directory: /opt/rtorrent.

Debian 9.5+.

sudo adduser --disabled-login --disabled-password --home /opt/rtorrent --system rtorrent

Debian 8-9.

sudo adduser -s /sbin/nologin --home /opt/rtorrent rtorrent

2. Update system/server.

sudo apt-get update
sudo apt-get upgrade

3. Install some needed dependencies: Apache2, PHP7 etc.

sudo apt-get -y install php php-geoip php7.0-cli php7.0-json php7.0-curl php7.0-cgi php7.0-mbstring libapache2-mod-php libapache2-mod-scgi libapache2-mod-xsendfile apache2 unrar unzip libav-tools ffmpeg mediainfo curl screen sqlite3 git net-tools sox

4. Install rtorrent.

sudo apt-get -y install rtorrent libtorrent19 libxmlrpc-core-c3

5. Create directories, these are needed for rTorrent to function.

sudo mkdir -p /opt/rtorrent/{session,watch,download}
sudo chmod 777 -R /opt/rtorrent/{session,watch,download}
sudo chown rtorrent:rtorrent -R /opt/rtorrent/{session,watch,download}

6. Download .rtorrent.rc file and put it in the home directory of the user that will run rTorrent.

Default directory: /opt/rtorrent/.

sudo wget --no-check-certificate https://terminal28.com/download/.rtorrent.rc-new -O /opt/rtorrent/.rtorrent.rc
sudo chmod 777 /opt/rtorrent/.rtorrent.rc

Example .rtorrent.rc:

# Port SCGI
scgi_port = localhost:5000

#This is an example resource file for rTorrent. Copy to

# ~/.rtorrent.rc and enable/modify the options as needed. Remember to
# uncomment the options you wish to enable.

# Maximum and minimum number of peers to connect to per torrent.
#
throttle.min_peers.normal.set = 40
throttle.max_peers.normal.set = 100

# Same as above but for seeding completed torrents (-1 = same as downloading)
#
throttle.min_peers.seed.set = 10
throttle.max_peers.seed.set = 100

# Maximum number of simultanious uploads per torrent.
#
throttle.max_uploads.set = 15

# Global upload and download rate in KiB. "0" for unlimited.
#
throttle.global_down.max_rate.set_kb = 0
throttle.global_up.max_rate.set_kb = 8

# Default directory to save the downloaded torrents.
#
directory.default.set = /opt/rtorrent/download

# Default session directory. Make sure you don't run multiple instance
# of rtorrent using the same session directory. Perhaps using a
# relative path?
#
session.path.set = /opt/rtorrent/session

# Watch a directory for new torrents, and stop those that have been
# deleted.
#
schedule2 = watch_directory,5,5,load_start=/opt/rtorrent/session/*.torrent
schedule2 = untied_directory,5,5,stop_untied=

# Close torrents when diskspace is low.
#
schedule2 = low_diskspace,5,60,close_low_diskspace=2000M

# The ip address reported to the tracker.
#
#network.local_address.set = 127.0.0.1
#network.local_address.set = rakshasa.no

# The ip address the listening socket and outgoing connections is
# bound to.
#
#network.bind_address.set = 127.0.0.1
#network.bind_address.set = rakshasa.no

# Port range to use for listening.
#
network.port_range.set = 6890-6999

# Start opening ports at a random position within the port range.
#
network.port_random.set = no

# Check hash for finished torrents. Might be usefull until the bug is
# fixed that causes lack of diskspace not to be properly reported.
#
pieces.hash.on_completion.set = no

# Set whether the client should try to connect to UDP trackers.
#
trackers.use_udp.set = yes

# Alternative calls to bind and ip that should handle dynamic ip's.
#
#schedule2 = ip_tick,0,1800,ip=rakshasa
#schedule2 = bind_tick,0,1800,bind=rakshasa

# Encryption options, set to none (default) or any combination of the following:
# allow_incoming, try_outgoing, require, require_RC4, enable_retry, prefer_plaintext
#
# The example value allows incoming encrypted connections, starts unencrypted
# outgoing connections but retries with encryption if they fail, preferring
# plaintext to RC4 encryption after the encrypted handshake
#
protocol.encryption.set = allow_incoming,enable_retry,prefer_plaintext

# Enable DHT support for trackerless torrents or when all trackers are down.
# May be set to "disable" (completely disable DHT), "off" (do not start DHT),
# "auto" (start and stop DHT as needed), or "on" (start DHT immediately).
# The default is "off". For DHT to work, a session directory must be defined.
#
dht.mode.set = auto

# UDP port to use for DHT.
#
dht.port.set = 6881

# Enable peer exchange (for torrents not marked private)
#
protocol.pex.set = yes

# Set downlad list layout style. ("full", "compact")
#
#ui.torrent_list.layout.set = "full"

7. Install and configure ruTorrent.
7.1. ruTorrent via GIT.

sudo git clone https://github.com/Novik/ruTorrent.git /var/www/rutorrent/
sudo chown -R www-data:www-data /var/www/rutorrent

7.2. ruTorrent mobile.

Acces to ruTorrent, rTorrent from Apple smartphones and older smartphones.

http://terminal28.com/access-to-rutorre ... le-phones/

Acces to ruTorrent, rTorrent from Android smartphones.

http://www.transdroid.org/.

Update path to Download directory.

Edit ruTorrent’s config.php config file and change path to Download directory.

Locate $topDirectory and add path to Download directory (/opt/rtorrent/download):

sudo nano /var/www/rutorrent/conf/config.php

$topDirectory = '/opt/rtorrent/download'; // Upper available directory. Absolute path with trail slash.

Some apps might not be in default location.
Use whereis app to find binary files and then update lines in config file. See below.

whereis gzip

Output:
gzip: /bin/gzip /usr/share/man/man1/gzip.1.gz /usr/share/info/gzip.info.gz

$pathToExternals = array(
"php" => '/usr/bin/php', // Something like /usr/bin/php. If empty, will be found in PATH.
"curl" => '/usr/bin/curl', // Something like /usr/bin/curl. If empty, will be found in PATH.
"gzip" => 'bin/gzip', // Something like /usr/bin/gzip. If empty, will be found in PATH.
"id" => '/usr/bin/id', // Something like /usr/bin/id. If empty, will be found in PATH.
"stat" => '/usr/bin/stat', // Something like /usr/bin/stat. If empty, will be found in PATH.
);

8. Install GeoIP database.

wget http://geolite.maxmind.com/download/geo ... ity.dat.gz
sudo gunzip GeoLiteCity.dat.gz
sudo mkdir -v /usr/share/GeoIP
sudo mv -v GeoLiteCity.dat /usr/share/GeoIP/GeoIPCity.dat

9. Secure ruTorrent web access.

Create the .htpasswd file.

cd /var/www/rutorrent
sudo htpasswd -c /var/www/rutorrent/.htpasswd nazwa_użytkownika

You will be asked for a password twice.

Output:

New password:
Re-type new password:
Adding password for user username

Edit file /var/www/rutorrent/.htaccess and add location secured by password.

sudo nano /var/www/rutorrent/.htaccess

AuthUserFile /var/www/rutorrent/.htpasswd
AuthName "ruTorrent_login"
AuthType Basic
require valid-user

10. Configure access to ruTorrent.

Edit /etc/apache2/sites-available/rutorrent and add infoformation about: alias, files and location secured by password.

sudo nano /etc/apache2/sites-available/rutorrent.conf

# ruTorrent
#===========================================================================
<IfModule alias_module>

Alias /rutorrent /var/www/rutorrent/

<Directory /var/www/rutorrent/>
Options +Indexes +Includes +FollowSymLinks +MultiViews
AllowOverride all
Require all granted
</Directory>

</IfModule>
#===========================================================================

Enable ruTorrent WebUI.

sudo ln -s /etc/apache2/sites-available/rutorrent.conf /etc/apache2/sites-enabled/rutorrent.conf

11. Activate Apache2 modules.

sudo a2enmod auth_digest
sudo a2enmod authn_file
sudo a2enmod xsendfile
sudo a2enmod scgi

12. Secure SCGI (/RPC2) directory.

Create folders: passwords-available, passwords-enabled in /etc/apache2.

sudo mkdir -p /etc/apache2/passwords-{available,enabled}

Go to /etc/apache2/passwords-available and make a new password for SCGI.

cd /etc/apache2/passwords-available
sudo htpasswd -c rtorrentscgi username

Enable rtorrentscgi password.

Link folder passwords-available to passwords-enabled.

sudo ln -s /etc/apache2/passwords-available/rtorrentscgi /etc/apache2/passwords-enabled/rtorrentscgi

Edit file /etc/apache2/sites-available/rtorrentscgi and add location of SCGI secured by password.

sudo nano /etc/apache2/sites-available/rtorrentscgi.conf

#rTorrent SCGI Password Location
#===========================================================================
<LocationMatch "/RPC2">
AuthType Basic
AuthName "rtorrentscgi"
AuthUserFile /etc/apache2/passwords-enabled/rtorrentscgi
Require valid-user
BrowserMatch "MSIE" AuthDigestEnableQueryStringHack=On
Require ip 127.0.0.1
</LocationMatch>
#===========================================================================

# SCGI PORT
#===========================================================================

#LoadModule scgi_module /usr/lib/apache2/modules/mod_scgi.so
SCGIMount /RPC2 127.0.0.1:5000

#===========================================================================

Enable rtorrentscgi config.

sudo ln -s /etc/apache2/sites-available/rtorrentscgi.conf /etc/apache2/sites-enabled/rtorrentscgi.conf

Restart Apache2 server.

sudo service apache2 restart

13. Autostart rTorrent – systemd.

Create rtorrent autostart script for systemd.

sudo nano /etc/systemd/system/rtorrent.service

[Unit]
Description=rTorrent
After=network.target

[Service]
UMask=002
Type=forking
RemainAfterExit=yes
KillMode=none
User=rtorrent
ExecStartPre=-/bin/rm -f /opt/rtorrent/session/rtorrent.lock
ExecStart=/usr/bin/screen -d -m -fa -S rtorrent /usr/bin/rtorrent
ExecStop=/usr/bin/killall -w -s 2 /usr/bin/rtorrent
WorkingDirectory=/opt/rtorrent/

[Install]
WantedBy=multi-user.target

Enable rTorrent autostart..

sudo systemctl enable rtorrent.service

From now rTorrent will start with system automatically in a detached shell using screen.

Commands:

sudo service rtorrent start - uruchamianie
sudo service rtorrent stop - zatrzymywanie
sudo service rtorrent restart - restart

or

sudo systemctl start rtorrent - uruchamianie
sudo systemctl stop rtorrent - zatrzymywanie
sudo systemctl restart rtorrent - restar

14. Start service rTorrent.

sudo service rtorrent start

Testing rTorrent:

sudo netstat -npl | grep rtorrent

Output:

tcp 0 0 127.0.0.1:5000 0.0.0.0:* LISTEN 16229/rtorrent
tcp 0 0 0.0.0.0:6890 0.0.0.0:* LISTEN 16229/rtorrent
udp 0 0 0.0.0.0:6881 0.0.0.0:* 16229/rtorrent

Access to your web front-end for rTorrent.

http://IP address/rutorrent

or

http://domain/rutorrent
Awatar użytkownika
jurek
Administrator
Administrator
Posty: 104
Rejestracja: 17 maja 2009, 15:48
Lokalizacja: Piast

Re: rtorrent

Post autor: jurek »

nowa wersja wymaga zmiany składni w pliku konfiguracyjnym do prawidłowego rozpoznawania torrentów w folderze watch:

session = ./.session

(-) schedule = watch_directory,5,5,load_start=./.torrent/*.torrent
(-) schedule = untied_directory,5,5,remove_untied=
(+) schedule2 = watch_start, 5, 5, ((load.start_verbose, "./.torrent/*.torrent"))
(+) schedule2 = untied_directory, 5, 5, remove_untied=

port_range = 49155-49965
encryption = allow_incoming,try_outgoing,enable_retry
Awatar użytkownika
jurek
Administrator
Administrator
Posty: 104
Rejestracja: 17 maja 2009, 15:48
Lokalizacja: Piast

Re: rtorrent

Post autor: jurek »

If you want to download torrents to Raspberry Pi, it's possible. There are a few options to do so, but the most lightweight option is rTorrent with ruTorrent. I prefer using WebGUI to manage torrents from anywhere (thanks to DDNS).

If you are planning to buy a new Raspberry Pi, I recommend the Raspberry Pi 4B with 2GB RAM, I am perfectly satisfied with it.

This article will show you how to install and configure rTorrent, ruTorrent, and Apache on Raspberry Pi.

Note: I don't recommend installing them with a script from the Internet, I tried it once. Long story short: I had to reinstall my Raspbian.

Note2: Do not download to an SD card, it'll ruin it quickly. Buy one HDD and connect it instead.

In this article we will install these packages (and dependencies):

rTorrent - torrent service
ruTorrent - WebGUI to manage torrents
Apache - web service to serve ruTorrent

Let's get started!

Note: feel free to change the path or username in these commands, but be careful and change them in every relevant command! I used /mnt/Torrent path where I want to download the content of torrents to, the username is "rtorrent", and /var/www/rutorrent/ path where all ruTorrent files are stored.

Open SSH connection to your Raspberry Pi

Update all packages
sudo apt update

Create "rtorrent" user, it will run rtorrent service
sudo adduser --disabled-login --disabled-password --home /mnt/Torrent --system rtorrent

Install all required packages
sudo apt -y install php php7.3-cli php7.3-json php7.3-curl php7.3-cgi php7.3-mbstring libapache2-mod-php libapache2-mod-scgi libapache2-mod-xsendfile apache2 libav-tools ffmpeg mediainfo curl screen sqlite3 git net-tools sox rtorrent libtorrent20 libxmlrpc-core-c3 git

Create and set correct permission for "session" folder
sudo mkdir -p /mnt/Torrent/session
sudo chmod 777 -R /mnt/Torrent/session
sudo chown rtorrent:rtorrent -R /mnt/Torrent/session

Create a new file called "rtorrent.rc", this is the configuration file of rTorrent
sudo nano /mnt/Torrent/.rtorrent.rc

network.scgi.open_port = "127.0.0.1:5000"
throttle.min_peers.normal.set = 10
throttle.max_peers.normal.set = 50
throttle.min_peers.seed.set = 20
throttle.max_peers.seed.set = 60
throttle.max_uploads.set = 30
network.http.dns_cache_timeout.set = 0
system.file.allocate.set = 1
pieces.preload.type.set = 2
throttle.global_down.max_rate.set_kb = 0
throttle.global_up.max_rate.set_kb = 0
directory.default.set = /mnt/Torrent
session.path.set = /mnt/Torrent/session
schedule2 = session_save, 1200, 43200, ((session.save))
network.port_range.set = 55001-55001
network.port_random.set = no
pieces.hash.on_completion.set = no
trackers.use_udp.set = yes
protocol.encryption.set = allow_incoming,try_outgoing,enable_retry
dht.mode.set = disable
dht.port.set = 6881
protocol.pex.set = no
execute2 = {sh,-c,/usr/bin/php /var/www/rutorrent/php/initplugins.php torrent &}
network.http.max_open.set = 50
network.max_open_files.set = 600
network.max_open_sockets.set = 300
method.set_key = event.download.erased,delete_erased,"execute=rm,-rf,--,$d.base_path="

Set correct permission for ".rtorrent.rc"
sudo chmod 777 /mnt/Torrent/.rtorrent.rc

Create folder for ruTorrent
sudo mkdir -p /var/www/rutorrent/

Download ruTorrent from GitHub
sudo git clone https://github.com/Novik/ruTorrent.git /var/www/rutorrent/

Grant permission for this new folder
sudo chown -R www-data:www-data /var/www/rutorrent

Edit ruTorrent configuration file
sudo nano /var/www/rutorrent/conf/config.php

Replace these values in this file:

$topDirectory = '/mnt/Torrent';
"php" => '/usr/bin/php',
"curl" => '/usr/bin/curl',
"gzip" => '/bin/gzip',
"id" => '/usr/bin/id',
"stat" => '/usr/bin/stat',

Secure ruTorrent WebGUI with password (change the username)
sudo htpasswd -c /var/www/rutorrent/.htpasswd username

Do not forget the username and password!

Configure Apache to use this new ".htpasswd" file
sudo nano /var/www/rutorrent/.htaccess

AuthUserFile /var/www/rutorrent/.htpasswd
AuthName "ruTorrent_login"
AuthType Basic
require valid-user
<Files ~ "^.*\.([Hh][Tt][Aa])">
Order allow,deny
Deny from all
Satisfy all
</Files>
Options -Indexes

Configure Apache to serve ruTorrent web interface (Change the path in 2nd line - security reason against scanner bots)
sudo nano /etc/apache2/sites-available/rutorrent.conf

<IfModule alias_module>
Alias /rutorrent /var/www/rutorrent/
<Directory /var/www/rutorrent/>
Options -Indexes -Includes -FollowSymLinks +MultiViews
AllowOverride all
Require all granted
</Directory>
</IfModule>

Enable this new website
sudo ln -s /etc/apache2/sites-available/rutorrent.conf /etc/apache2/sites-enabled/rutorrent.conf

Enable necessary Apache modules
sudo a2enmod auth_digest authn_file xsendfile scgi

Edit Apache config file for scgi
nano /etc/apache2/sites-available/rtorrentscgi.conf

<LocationMatch "/RPC2">
AuthType Basic
AuthName "rtorrentscgi"
AuthUserFile /var/www/rutorrent/.htpasswd
Require valid-user
BrowserMatch "MSIE" AuthDigestEnableQueryStringHack=On
Require ip 127.0.0.1
</LocationMatch>
SCGIMount /RPC2 127.0.0.1:5000

Enable scgi in Apache
ln -s /etc/apache2/sites-available/rtorrentscgi.conf /etc/apache2/sites-enabled/rtorrentscgi.conf

Create systemd service for rTorrent
nano /etc/systemd/system/rtorrent.service

[Unit]
Description=rTorrent
After=network.target

[Service]
UMask=002
Type=forking
RemainAfterExit=yes
KillMode=none
User=rtorrent
Restart=on-failure
RestartSec=5
StartLimitInterval=60s
StartLimitBurst=3
ExecStartPre=-/bin/rm -f /mnt/Torrent/session/rtorrent.lock
ExecStart=/usr/bin/screen -d -m -fa -S rtorrent /usr/bin/rtorrent
ExecStop=/usr/bin/killall -w -s 2 /usr/bin/rtorrent
WorkingDirectory=/mnt/Torrent/

[Install]
WantedBy=multi-user.target

Start and enable rTorrent service
systemctl start rtorrent
systemctl enable rtorrent.service

Check the WebGUI
Check IP address of Raspberry Pi:
hostname -I

Replace the IP and try to open in the browser like this:
192.168.0.102/rutorrent

Note: if you have changed the default path in step 14, do not forget to replace it as well as in here.

It should work :) Login info provided by you in the step 12.

If it doesn't work for some reason, check the Apache and rTorrent services.
systemctl status apache2 rtorrent

Let's continue with optimization steps

Secure Apache by adding the below lines at the end of apache2.conf file
nano /etc/apache2/apache2.conf

ServerSignature Off
ServerTokens Prod
<IfModule mod_headers.c>
Header unset ETag
</IfModule>
FileETag None

Remove the "index.php" file and create an empty "index.html" instead
rm /var/www/html/index.php
echo “” > /var/www/html/index.html
chmod 444 /var/www/html/index.html

Disable useless logging (extend MicroSD lifetime)
a2disconf other-vhosts-access-log
systemctl reload apache2

Disable unnecessary Apache modules (save memory)
a2dismod proxy_http
a2dismod proxy
a2dismod status
systemctl restart apache2

That's all. Have fun!

Optional: Install RPI-Monitor to check Memory and HDD usage from the web browser.

If it doesn't work for some reason, check the Apache and rTorrent services.
systemctl status apache2 rtorrent

If you have a question, feel free to leave a comment below.
ODPOWIEDZ