NPCHK Blog

路邊小博客(<ゝω・)☆

Debian 9 (Stretch) 編譯rtorrent+RuTorrent (WebUI)安裝指南

前言

教學通過測試於Debian 9,支援IPv6。若想用於其他/不同版本的系統,請自行修改指令和軟件包名稱。
以下將編譯安裝rtorrent和libtorrenth的0.9.7 / 0.9.6版本:

  • 添加支援OpenSSL 1.1.0
  • 原生支援IPv6

其他系統編譯rtorrent教學:

Debian 7 (wheezy): https://npchk.info/debian7-install-rtorrent/

Debian 8 (Jessie): https://npchk.info/debian8-install-rtorrent/

Ubuntu 16/17: https://npchk.info/ubuntu-install-rtorrent/

Ubuntu 18: https://npchk.info/ubuntu-bionic-install-rtorrent/

上次更新時間: 2019年7月10日

安裝編譯工具與依賴

apt update
apt install git build-essential automake libcppunit-dev libtool zlib1g-dev gawk libsigc++-2.0-dev libssl-dev libncurses5-dev libncursesw5-dev libcurl4-openssl-dev libxmlrpc-c++8-dev nano screen unzip

編譯rtorrent 0.9.7

從Github取得libtorrent 0.13.7 並添加支援OpenSSL1.1:

git clone https://github.com/rakshasa/libtorrent
cd libtorrent/
git config --global user.email "[email protected]"
git config --global user.name "yourname"
git checkout v0.13.7
git cherry-pick 7b29b6b

編譯及安裝libtorrent:

./autogen.sh
./configure --disable-debug 
make -j$(nproc)
make install
cd ~

刷新動態庫:

ldconfig

從Github取得rtorrent 0.9.7:

git clone https://github.com/rakshasa/rtorrent
cd rtorrent
git checkout v0.9.7

編譯及安裝rtorrent:

./autogen.sh
./configure --with-xmlrpc-c --with-ncurses --enable-ipv6 --disable-debug
make -j$(nproc)
make install
cd ~

編譯rtorrent 0.9.6

從Github取得libtorrent feature-bind:

git clone https://github.com/rakshasa/libtorrent
cd libtorrent/
git checkout origin/feature-bind
git checkout 9eb9ba2

編譯及安裝libtorrent:

./autogen.sh
./configure --disable-debug 
make -j$(nproc)
make install
cd ~

刷新動態庫:

ldconfig

從Github取得rtorrent feature-bind:

git clone https://github.com/rakshasa/rtorrent
cd rtorrent
git checkout origin/feature-bind
git checkout b088c1c

編譯及安裝rtorrent:

./autogen.sh
./configure --with-xmlrpc-c --with-ncurses --enable-ipv6 --disable-debug
make -j$(nproc)
make install
cd ~

新增系統使用者

新增系統使用者,用於執行rtorrent和php-fpm
例如peter:

adduser peter

配置Nginx和PHP

安裝RuTorrent的網頁伺服器軟體:

apt install nginx-full php-fpm apache2-utils php7.0-cgi php7.0-cli php-geoip curl

禁用Nginx默認網站 新建站點配置文件:

rm /etc/nginx/sites-enabled/default
touch /etc/nginx/sites-available/rutorrent.conf
ln -s /etc/nginx/sites-available/rutorrent.conf /etc/nginx/sites-enabled/000-rutorrent.conf
nano /etc/nginx/sites-available/rutorrent.conf
輸入以下內容
server {
 
 server_name _;
 
 root /var/www;
 index index.html;
 
 location / {
 auth_basic "Restricted";
 auth_basic_user_file /etc/nginx/htpasswd;
 try_files $uri $uri/ =404;
 }
 
 location /RPC2 {
 scgi_pass unix:/tmp/rpc.socket;
 include scgi_params;
 scgi_param SCRIPT_NAME /RPC2;
 }
 
 location ~ \.php$ {
 try_files $uri =404;
 fastcgi_pass unix:/run/php/php7.0-fpm.sock;
 fastcgi_split_path_info ^(.+\.php)(/.+)$;
 fastcgi_index index.php;
 fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
 include fastcgi_params;
 }
 
}

配置php-fpm7.0:

nano /etc/php/7.0/fpm/pool.d/www.conf
#修改參數#
user = peter
group = peter

配置php-geoip:

nano /etc/php/7.0/fpm/php.ini
#加入一行:extension=geoip.so

下載MaxMind GeoIP 數據庫:

rm -rf /usr/share/GeoIP
mkdir -p /usr/share/GeoIP
cd /usr/share/GeoIP/
wget https://github.com/NPCHK/GeoLiteCountry/raw/master/GeoIP.dat

重啟php7.0-fpm和Nginx以套用新設置:

systemctl restart php7.0-fpm
systemctl restart nginx

配置RuTorrent及Plugins

從Github取得RuTorrent:

wget https://github.com/Novik/ruTorrent/archive/master.zip
unzip master.zip

移動RuTorrent到Nginx的www目錄:

mv ruTorrent-master /var/www/rt

設置RuTorent需賬號及密碼登錄(例如peter):

htpasswd -c /etc/nginx/htpasswd peter

設置RuTorrent與PHP使用者peter的權限:

chown peter -R /var/www/rt/share

設置RuTorrent使用UNIX Domain Socket連接Nginx/rtorrent:

nano /var/www/rt/conf/config.php
找到以下部分並修改成:
        //$scgi_port = 5000;
        //$scgi_host = "127.0.0.1";

        // For web->rtorrent link through unix domain socket 
        // (scgi_local in rtorrent conf file), change variables 
        // above to something like this:
        //
        $scgi_port = 0;
        $scgi_host = "unix:///tmp/rpc.socket";

以下將配置RuTorrent的Plugins的依賴

nano /var/www/rt/conf/config.php

#替換$pathToExternals = array( );的內容:

        $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.
                "pgrep"  => '/usr/bin/pgrep',                  // Something like /usr/bin/pgrep. 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.
                "python"  => '/usr/bin/python',                  // Something like /usr/bin/python. If empty, will be found in PATH.
        );

「screenshots」Plugin需要ffmpeg:

apt install ffmpeg

「mediainfo」Plugin需要mediainfo:

apt install mediainfo

「CloudFlare」Plugin需要cfscrape pyrocore:

apt install python python-pip
pip install --upgrade pip
hash -d pip
pip install setuptools
pip install cfscrape cloudscraper pyrocore

「unrar」Plugin需要unrar和rar;
unrar和rar是non-free軟體,安裝前須檢查sources.list有沒有non-free字眼:

nano /etc/apt/sources.list
#例如:deb http://XXX.debian.org/debian/ stretch main non-free
如無,請在stretch main後添加「non-free」並更新APT倉庫:
apt update

安裝unrar和rar:

apt install unrar rar

「Spectrogram」Plugin需要sox libsox-fmt-mp3:

apt install sox libsox-fmt-mp3

配置「Spectrogram」Plugin:

nano /var/www/rt/plugins/spectrogram/conf.php
#修改為$pathToExternals['sox'] = '/usr/bin/sox';

安裝「Autodl-irssi」 Plugin(第三方插件 非必要功能)
安裝irssi及依賴:

apt install irssi libarchive-zip-perl libnet-ssleay-perl libhtml-parser-perl libxml-libxml-perl libdigest-sha-perl libjson-perl libjson-xs-perl libxml-libxslt-perl php-xml

下載及安裝Autodl-irssi:

mkdir -p ~/.irssi/scripts/autorun
cd ~/.irssi/scripts
curl -sL http://git.io/vlcND | grep -Po '(?<="browser_download_url": ")(.*-v[\d.]+.zip)' | xargs wget --quiet -O autodl-irssi.zip
unzip -o autodl-irssi.zip
rm autodl-irssi.zip
cp autodl-irssi.pl autorun/
mkdir -p ~/.autodl
touch ~/.autodl/autodl.cfg

配置Autodl-irssi:

nano ~/.autodl/autodl.cfg
#輸入以下容內並設置Port及密碼,例如:
[options]
gui-server-port = 50000
gui-server-password = a577a5727fec6348

下載「Autodl-irssi」 Plugin到RuTorrent並設置PHP使用者peter的權限:

cd /var/www/rt/plugins/
git clone https://github.com/autodl-community/autodl-rutorrent.git autodl-irssi
cp autodl-irssi/_conf.php autodl-irssi/conf.php
chown -R peter:peter autodl-irssi

配置「Autodl-irssi」 Plugin:

nano autodl-irssi/conf.php
#填入剛才設置的Autodl-irssi Port及密碼

配置rtorrent

**登錄至使用者peter,以下將使用peter操作**
創建rtorrent配置文件:

nano ~/.rtorrent.rc
內容(把*.*.*.*改為盒子的IPv4地址):
directory = /home/peter/Downloads
session = /home/peter/rtorrent/.sessions
 
schedule = watch_dir,5,5,"load.start=/home/peter/rtorrent/torrents/*.torrent, d.directory.set=/home/peter/rtorrent/incoming"
schedule = untied_directory,5,5,stop_untied=
schedule = untied_directory,5,5,close_untied=
schedule = untied_directory,5,5,remove_untied=
schedule = tied_directory,5,5,start_tied=
schedule = low_diskspace,10,30,close_low_diskspace=100M

execute.nothrow=rm,/tmp/rpc.socket
scgi_local = /tmp/rpc.socket
schedule = chmod,0,0,"execute=chmod,777,/tmp/rpc.socket"

upload_rate = 0
download_rate = 0
port_range = 34543-34543
port_random = no
encryption = allow_incoming,try_outgoing,enable_retry
dht = auto
check_hash = no
 
encoding_list = UTF-8
ip = *.*.*.*

創建下載、監控及記錄目錄:

mkdir ~/Downloads
mkdir ~/rtorrent/
mkdir ~/rtorrent/incoming
mkdir ~/rtorrent/.sessions
mkdir ~/rtorrent/torrents/

設置開機自啟

nano /etc/systemd/system/rtorrent.service

輸入以下內容:

[Unit]
Description=rTorrent Service
After=network.target

[Service]
Type=forking
KillMode=none
LimitNOFILE=65536
ExecStart=/usr/bin/screen -S rt -fa -d -m /usr/local/bin/rtorrent
ExecStop=/usr/bin/killall -w -s 2 /usr/local/bin/rtorrent
WorkingDirectory=/home/peter
User=peter
Group=peter

[Install]
WantedBy=multi-user.target
nano /etc/systemd/system/irssi.service

輸入以下內容:

[Unit]
Description=rTorrent Service
After=network.target

[Service]
Type=forking
ExecStart=/usr/bin/screen -S autodl -fa -d -m /usr/bin/irssi
User=root

[Install]
WantedBy=multi-user.target

啟用以上設置:

systemctl enable rtorrent.service
systemctl enable irssi.service

啟動rtorrent和irssi

systemctl start rtorrent.service
systemctl start irssi.service

安裝完成,訪問RuTorrent: http://YOURIPADDRESS/rt/

安裝資訊

下載文件的保存目錄/位置 = /home/peter/Downloads
監控目錄 = /home/peter/rtorrent/torrents/
Nginx根目錄 = /var/www/
訪問rtorrent命令行界面: screen -r rtorrent
訪問irssi界面:screen -r autodl






  1. 秦大叔表示:

    你好,受益於你的教學
    在二個盒子及家中的二台Nas都裝上了Rutorrent+Rtorrent並完美的支持了ipv6
    發現一個問題,geoip好像對於ipv6 address無法辨別
    國家類別會變成未知unknown,更新過GeoIPv6.dat不過好像也沒什麼效果
    上網google了一下,也到rt作者github看了一下,沒有找到相關修正的方法
    是rt0.9.6不支援v6的geoip嗎?
    使用Qbittorrent3.3.11 可以正常顯示出ipv6 address跟國家類別

    二個盒子的系統皆為Ubuntu 16.04 TLS 64bit
    家用Nas一台Asustor 安裝Linux Center run Debian8.9 (jessie)
    另一台Synology 安裝Debian Chroot run Debian8.9 (jessie)

    1. Admin表示:

      GeoIP顯示與Rutorrent和PHP有關
      但目前還沒找到顯示方法

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。

這個網站採用 Akismet 服務減少垃圾留言。進一步了解 Akismet 如何處理網站訪客的留言資料