NPCHK Blog

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

Ubuntu 18.04 (Bionic) 編譯rtorrent+RuTorrent (WebUI)安裝指南

前言

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

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

其他系統編譯rtorrent教學:

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

Debian 9 (Stretch): https://npchk.info/debian9-install-rtorrent/

CentOS 7: https://npchk.info/centos7-rtorrent/

安裝編譯工具與依賴

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.2-cgi php7.2-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.2-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.2:

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

配置php-geoip:

nano /etc/php/7.2/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.2-fpm和Nginx以套用新設置:

systemctl restart php7.2-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 cfscrape 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';

安裝及配置RuTorrent的第三方插件(Plugins)

「File Manager」能令我們在Rutorrent直接進行檔案複製/刪除/移動/壓縮/解壓等等,非常推薦安裝!
安裝「File Manager」Plugin:
下載插件:

git clone https://github.com/nelu/rutorrent-thirdparty-plugins

移動插件到RuTorrent Plugin目錄:

mv rutorrent-thirdparty-plugins/filemanager/ /var/www/rt/plugins/

安裝依賴組件:

apt install zip

配置File Manager:

nano /var/www/rt/plugins/filemanager/conf.php

#將$pathToExternals部分改成:
$pathToExternals['rar'] = '/usr/bin/rar';
$pathToExternals['zip'] = '/usr/bin/zip';
$pathToExternals['unzip'] = '/usr/bin/unzip';
$pathToExternals['tar'] = '/bin/tar';
$pathToExternals['gzip'] = '/bin/gzip';
$pathToExternals['bzip2'] = '/bin/bzip2';

配置RuTorrent:

nano /var/www/rt/conf/config.php
#將「$topDirectory = '/';」修改成「$topDirectory = '/home/peter/';」

設置檔案權限:

chown -R peter:peter /var/www/rt/plugins/filemanager/
chmod 755 /var/www/rt/plugins/filemanager/scripts/*

安裝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. iloft表示:

    可以尝试把Nginx 替换成Caddy 配置起来更简单~~

發佈回覆給「iloft」的留言 取消回覆

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

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