📜 ⬆️ ⬇️

Installing and configuring rtorrent + rutorrent + nginx + php-fpm in Arch Linux

Prehistory


To work with torrents, I used ktorrent for a long time. This client completely satisfied my needs for convenient download management, until I noticed that on popular torrents the processor load reached 50% ( and with uTP even more ), and the memory consumption in the already fat KDE became unpleasantly evident.

It was decided to change KDE to xfce ( this is a separate story ), and choose a program for torrents with good functionality and convenient controls. Having tried transmission, deluge and rtorrent, I stopped at the last.

How to configure rtorrent + rutorrent + nginx + php-fpm, and will be under the cut.

Why is that?


I want to answer right away why the above mentioned tools are chosen.
')
Arch Linux . You can talk about this distribution for a long time, I like its organization and philosophy in general, and I can use it for myself with maximum efficiency. To whom it is interesting to read about it in more detail, look here and here .

nginx . I am impressed with how this little thing does its job, saving memory, flexibly tuning and providing all the functionality I need.

php-fpm . You can configure the number of worker threads, in conjunction with nginx, it gives excellent performance.

rtorrent . Low resource consumption, well tuned.

rutorrent . Actively developing, has a nice interface.

Install the necessary software



Let us proceed from the fact that Arch Linux is already on the computer, and the user is familiar with its package system.

To install the bundle web part, execute the following command:

sudo pacman -S nginx php-fpm

I recommend installing rtorrent and librtorrent from AUR, there is a wonderful PKGBUILD called rtorrent-color that makes a boring console interface more enjoyable ( if you use it ), and libtorrent-extended, which has additional patches. Therefore, we execute the command:

yaourt rtorrent-color

and

yaourt libtorrent-extended

To get the rutorrent, you need to clone it from svn using the command:

svn checkout rutorrent.googlecode.com/svn/trunk rutorrent-read-only


The files will appear in the “rutorrent-read-only” directory, then we will take them from there.

Customization



In the /etc/php/php-fpm.conf file you need to set the following parameters:



The /etc/nginx/conf/nginx.conf file is as follows:

 worker_processes 2; error_log /var/log/nginx/error.log; pid /var/run/nginx.pid; events { worker_connections 1024; use epoll; } http { include /etc/nginx/conf/mime.types; default_type application/octet-stream; upstream backend { server 127.0.0.1:9000; } upstream backendrtorrent { server unix:/home/pf/.rtorrent.sock; } sendfile on; keepalive_timeout 65; include /etc/nginx/conf/sites-enabled/*; include /etc/nginx/conf/conf.d/*; } 


Please note that the backend subsection points to php-fpm, and the backendrtorrent indicates the rtorrent socket file (more on this later ).

Create directories / etc / nginx / conf / sites-enabled and / etc / nginx / conf / sites-available . In the second, we will create a configuration file rutorrent.eternity with the following content and make a symbolic link to it in the first directory:

 server { listen 80; server_name localhost; access_log /srv/http/nginx/rutorrent.eternity/logs/access.log; error_log /srv/http/nginx/rutorrent.eternity/logs/errors.log; location / { root /srv/http/nginx/rutorrent.eternity/htdocs; index index.php index.html index.htm; } location /RPC2 { include /etc/nginx/conf/scgi_params; scgi_pass backendrtorrent; } location ~ /\.ht { deny all; } location ~* \.(jpg|jpeg|gif|bmp|ico|png|css|js|swf)$ { root /srv/http/nginx/rutorrent.eternity/htdocs; access_log off; expires 30d; } location ~ .php$ { fastcgi_split_path_info ^(.+\.php)(.*)$; fastcgi_pass backend; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /srv/http/nginx/rutorrent.eternity/htdocs$fastcgi_script_name; include fastcgi_params; fastcgi_param QUERY_STRING $query_string; fastcgi_param REQUEST_METHOD $request_method; fastcgi_param CONTENT_TYPE $content_type; fastcgi_param CONTENT_LENGTH $content_length; fastcgi_intercept_errors on; fastcgi_ignore_client_abort off; fastcgi_connect_timeout 60; fastcgi_send_timeout 180; fastcgi_read_timeout 180; fastcgi_buffer_size 128k; fastcgi_buffers 4 256k; fastcgi_busy_buffers_size 256k; fastcgi_temp_file_write_size 256k; } } 


Notice the location of the error and access logs ( /srv/http/nginx/rutorrent.eternity/logs ), as well as the root directory of web documents ( /srv/http/nginx/rutorrent.eternity/htdocs ). These directories must exist. Also pay attention to the location / RPC2 block , it is mandatory for the rutorrent. I do not provide a description of the remaining parameters here, detailed documentation on the Internet is sufficient.

In the / etc / hosts file add this line:

127.0.0.1 localhost.localdomain localhost eternity rutorrent.eternity

eternity is the name of my system, it may be different with you. In this case, it needs to be changed everywhere in the configuration files.

You can run nginx and php-fpm:

sudo /etc/rc.d/nginx start
sudo /etc/rc.d/php-fpm start


You can now test the bundle web part by uploading a simple php file to the root directory of web documents. When you go to the web browser at rutorrent.eternity, it should display correctly.

Now you need to install rutorrent. Transfer the contents of the above directory rutorrent-read-only / rtorrent to the root directory of web documents ( remember , this is the directory /srv/http/nginx/rutorrent.eternity/htdocs ). Do the same with the rutorrent-read-only / plugins directory, copy it over the existing plugins directory in the rutorrent file tree. Garbage type .svn can be removed.

Open the /srv/http/nginx/rutorrent.eternity/htdocs/conf/config.php file and replace it with just two lines:

$scgi_port = 0;
$scgi_host = "unix:///home/pf/.rtorrent.sock";


The socket file must match the one mentioned above.

The web interface is ready, now you need to configure rtorrent itself.

Create a .rtorrent.rc file in your home directory with the following contents:

scgi_local = /home/pf/.rtorrent.sock
max_memory_usage = 268435456
system.file_allocate.set = yes
done_fg_color = 2
done_bg_color = 0
active_fg_color = 4
active_bg_color = 0
download_rate = 250
upload_rate = 250
directory = /home/pf/work/downloads/torrents
session = /home/pf/work/downloads/torrents/.session
port_range = 29292-29292
check_hash = no
use_udp_trackers = yes
encryption = allow_incoming,try_outgoing,enable_retry,prefer_plaintext
dht = auto
dht_port = 6881
peer_exchange = yes


The line system.file_allocate.set = yes makes sense if libtorrent is compiled with the option --with-posix-fallocate, which on modern file systems allows you to instantly allocate the necessary space for the torrent. Options like * g_color apply only to rtorrent-color. Catalogs, ports and speed set up at your discretion.

The final touch is the script for running rtorrent. Place the following contents in /etc/rc.d/rtorrentd :

 #!/usr/bin/env bash . /etc/rc.conf . /etc/rc.d/functions rtorrent_user="pf" rtorrent_socket="/home/pf/.rtorrent.sock" case "$1" in start) stat_busy "Starting rtorrent" if [ -S $rtorrent_socket ]; then rm $rtorrent_socket fi su $rtorrent_user -c 'LANG=uk_UA.UTF-8 screen -d -m -S rtorrent rtorrent' &> /dev/null if [ $? -gt 0 ]; then stat_fail else while [ ! -S $rtorrent_socket ] do printf "%10s \r" waiting done chmod 666 $rtorrent_socket add_daemon rtorrent stat_done fi ;; stop) stat_busy "Stopping rtorrent" killall -w -s 2 /usr/bin/rtorrent &> /dev/null if [ -S $rtorrent_socket ]; then rm $rtorrent_socket fi if [ $? -gt 0 ]; then stat_fail else rm_daemon rtorrent stat_done fi ;; restart) $0 stop sleep 1 $0 start ;; *) echo "usage: $0 {start|stop|restart}" esac exit 0 


Naturally, the screen should be installed. Variables rtorrent_user and rtorrent_socket correct for your environment. If rtorrent autoload is needed, place it in the /etc/rc.conf file in the DAEMONS array.

Everything. Run the rtorrent command

sudo /etc/rc.d/rtorrentd start

go to the rutorrent.eternity website in your browser and enjoy.

Source: https://habr.com/ru/post/120167/


All Articles