NPCHK Blog

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

Debian 8 (Jessie) 編譯rtorrent+RuTorrent (WebUI)安裝指南

前言

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

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

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

其他系統編譯rtorrent教學:

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

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

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

修改系統APT源

https://lists.debian.org/debian-devel-announce/2019/03/msg00006.html
Debian8的軟件包已經從主鏡像站中被刪除,但是我們可以使用snapshot.debian.org解決APT源問題
清空/etc/apt/sources.list並輸入以下內容:

deb http://snapshot.debian.org/archive/debian/20190321T212815Z/ jessie main contrib non-free
deb-src http://snapshot.debian.org/archive/debian/20190321T212815Z/ jessie main contrib non-free
deb http://snapshot.debian.org/archive/debian/20190321T212815Z/ jessie-backports main contrib non-free
deb-src http://snapshot.debian.org/archive/debian/20190321T212815Z/ jessie-backports main contrib non-free
deb http://snapshot.debian.org/archive/debian-security/20190321T215527Z/ jessie/updates main contrib non-free
deb-src http://snapshot.debian.org/archive/debian-security/20190321T215527Z/ jessie/updates main contrib non-free
deb http://snapshot.debian.org/archive/debian/20190321T212815Z/ jessie-updates main contrib non-free
deb-src http://snapshot.debian.org/archive/debian/20190321T212815Z/ jessie-updates main contrib non-free

安裝編譯工具與依賴

apt -o Acquire::Check-Valid-Until=false
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:

git clone https://github.com/rakshasa/libtorrent
cd libtorrent/
git checkout v0.13.7

編譯及安裝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

安裝網頁伺服器軟體及插件

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

apt install nginx-full php5-fpm apache2-utils curl php5-geoip

刪除網頁伺服器軟體的默認頁面,創建及編輯Rutorrent的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:/var/run/php5-fpm.sock;
 fastcgi_split_path_info ^(.+\.php)(/.+)$;
 fastcgi_index index.php;
 fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
 include fastcgi_params;
 }

}

配置php5-fpm:

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

配置php-geoip:

nano /etc/php5/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

修改php5-fpm的上傳檔案數量和大小限制:

nano /etc/php5/fpm/php.ini
#修改參數:
upload_max_filesize = 100M
max_file_uploads = 10000
post_max_size = 100M
memory_limit = 256M

重啟php5-fpm和Nginx以套用新設置:

systemctl restart php5-fpm
systemctl restart nginx

安裝及配置RuTorrent

從Github取得RuTorrent:

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

移動RuTorrent到Nginx的www目錄:

mv ruTorrent-master /var/www/rt

建立一個Web用戶於登入RuTorrent (例如用戶名叫tom):

htpasswd -c /etc/nginx/htpasswd tom

設置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)

配置Curl:

nano /var/www/rt/conf/config.php
#「"curl"  => '',」修改為「"curl"  => '/usr/bin/curl',」

「screenshots」Plugin需要ffmpeg;

apt install ffmpeg

「mediainfo」Plugin需要mediainfo:

apt install mediainfo

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

nano /etc/apt/sources.list
#例如:deb http://XXX.debian.org/debian/ jessie main non-free
#如無,請在jessie main後添加「non-free」

更新APT倉庫並安裝unrar和rar:

apt update
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/*

安裝「Autodl-irssi」 Plugin(用於RSS外國PT站 不知道這是甚麼的不建議安裝)
安裝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-parser

下載「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通訊,例如:
$autodlPort = 50000;
$autodlPassword = "a577a5727fec6348aa";

現在切換到用戶peter來繼續配置Autodl-irssi:

su - peter

下載及安裝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 = a577a5727fec6348aa

配置rtorrent

我們繼續使用用戶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/

登出peter,回到root繼續餘下配置:

exit

設置開機自啟

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=peter

[Install]
WantedBy=multi-user.target

啟用以上設置:

systemctl enable rtorrent.service
systemctl enable irssi.service

啟動rtorrent和irssi

systemctl start rtorrent.service
systemctl start irssi.service

現在已經完成安裝程序,瀏覽器訪問…:

http://你的服務器IP地址/rt/
#使用上面設置的Web用戶「tom」登入

安裝資訊

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






  1. crazi表示:

    请问大大,我创建用户pt,用pt登陆后运行
    screen -S pt;
    rtorrent;
    Error in option file: ~/.rtorrent.rc:22: Junk at end of input
    这个错误如何解决呢?
    ip = *.*.*.*
    这个是否填服务器ip?

    1. Admin表示:

      沒錯,要把*.*.*.*改成服務器IP。

      1. crazi表示:

        博主,不知道为啥,只有把
        ip = *.*.*.* #這裡填IPv4地址 如果用了IPv6補丁的話需要這個參數,否則Tracker只知道IPv6地址
        后面的#全删掉才不会报错

發佈留言

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

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