NPCHK Blog

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

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

前言

本文章適用於Ubuntu,並於Ubuntu 16.04/16.10/17.04通過測試,添加rTorrent支援IPv6。

適用於Ubuntu 18.04的教學

適用於Debian的文章:https://npchk.info/debian8-install-rtorrent/

rtorrent的版本是最新版本0.9.6,詳情可參閱作者的Github https://rakshasa.github.io/rtorrent/

感謝兵藤一誠@U2的指導 和 ノエル@U2的建議

如果你是小白,請確保系統是Ubuntu和系統沒嘗試過安裝rtorrent (保持乾淨的安裝環境),否則請重裝Ubuntu,然後跟着Copy and Paste指令就OK

安裝及配置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 screen unzip

下載libtorrent

git clone https://github.com/memoz/libtorrent.git

編譯並安裝libtorrent 需時10-30分鍾

cd libtorrent \
&& git checkout in-use \
&& ./autogen.sh \
&& ./configure --disable-debug \
&& make \ #可加入 -j 參數使用多核編譯,但用在某些低性能CPU會出現ERROR
&& make install

刷新動態庫

ldconfig

下載rtorrent

cd ~
git clone https://github.com/memoz/rtorrent.git

編譯並安裝rTorrent 需時10-30分鍾

cd rtorrent \
&& git checkout in-use \
&& ./autogen.sh \
&& ./configure --with-xmlrpc-c --with-ncurses --enable-ipv6 --disable-debug \
&& make \ #也可加入 -j 參數使用多核編譯
&& make install \
&& cd ~

新增系統使用者 例如:peter

adduser peter

使用者切換到peter 建立rtorrent配置文件

nano ~/.rtorrent.rc


#內容如下#
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

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
scgi_port = 127.0.0.1:5000
ip = *.*.*.* #這裡填IPv4地址 如果用了IPv6補丁的話需要這個參數,否則Tracker只知道IPv6地址

根據上面的配置文件新增文件夾

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

安裝及配置RuTorrent

切換回root進行以下步驟 安裝RuTorrent的網頁伺服器軟體

apt install nginx-full php-fpm apache2-utils php7.0-cgi php7.0-cli 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 127.0.0.1:5000;
 include scgi_params;
 scgi_param SCRIPT_NAME /RPC2;
 }

 location ~ \.php$ {
 try_files $uri =404;
 fastcgi_pass 127.0.0.1:9000;
 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 = www-data 改為user = peter
### group = www-data 改為group = peter
###將listen = /var/run/php7.0-fpm.sock 改為listen = 127.0.0.1:9000

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

systemctl restart php7.0-fpm
systemctl restart nginx

下載RuTorrent並移動到www目錄

wget https://github.com/Novik/ruTorrent/archive/master.zip
unzip master.zip
mv ruTorrent-master /var/www/rt

為RuTorrent加入登錄密碼 例如用戶名為peter

htpasswd -c /etc/nginx/htpasswd peter

設置RuTorrent與使用者peter的權限

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

使用peter啟動rtorrent

screen -S rt   ###創建名為"rt"的screen窗口,可自行改名
rtorrent   ##啟動rtorrent

安裝完成!在瀏覽器輸入 http://你的IP地址/rt/ 即可進入RuTorrent。

Q&A

Q1:首次啟動RuTorrent會出現報錯: Bad response from server: (500 [error,list]) Warning: XMLRPC call is failed.

A1:在命令行按CTRL+Q退出rtorrent,接着清除瀏覽器緩存。最後輸入”rtorrent”以再次啟動rtorrent,便可正常訪問RuTorrent。

Q2:RuTorrent各種報錯 例如:Plugin will not work. rTorrent user can’t access external program (mediainfo)…….

A2:那是RuTorrent內置插件,你可以安裝缺少的程序或在”Plugins”停用它。

Q3:我在RuTorrent設定中修改數值後,會出現Bad response from server: (500 [error,setsettings]) Warning: XMLRPC call is failed.或Bad response from server: (500 [error,list]) Link to XMLRPC failed. May be, rTorrent is down?

A3:你輸入的數值不合法,例如”整體最大可開啟的檔案數量”的數值為1 – 2^16 (65536),如果超出範圍輸入0或70000,rtorrent就會崩潰或Bad response from server。如果rtorrent崩掉請回screen再次啟動rtorrent

Q4:關掉SSH後怎樣返回rtorrent命令行?

A4:由於關掉SSH時會連帶rtorrent一起關掉,所以要把rtorrent放在screen運行。輸入以下指令可返回rtorrent screen:

screen -r rt
###按CTRL+A-D可關閉screen去背景  ###按CTRL+K可殺掉screen

 

Q5:為甚麼已在”Plugins”啟用GeoIP插件,但仍然沒有顯示Peer國家?

A5:修改PHP配置文件

nano /etc/php/7.0/fpm/php.ini

##加入一行:extension=geoip.so

下載最新的GeoIP庫:

rm /usr/share/GeoIP/GeoIP.dat
cd /usr/share/GeoIP
wget http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/GeoIP.dat.gz
gunzip GeoIP.dat.gz

安裝php-geoip

apt install php-geoip

重啟php7.0-fpm套用新設置

systemctl restart php7.0-fpm






  1. bfida表示:

    感谢dalao的教程 帮了小白很多

    按照dalao的教程安装碰上了几个问题 摸索着解决了
    第一个问题出现在安装php-fpm时提示没有源
    需要执行下
    add-apt-repository ppa:ondrej/php
    apt-get update
    就好了

    第二个问题是apt-get的php-fpm已经是php7.1-fpm
    配置文件的路径变成了/etc/php/7.1/fpm/pool.d/www.conf

    第三个是我在root用户切换到"peter"然后执行
    screen -S rt报错
    需要执行下
    script /dev/null
    就能打开screen了

    最后希望dalao能写一个webdav或者http的教程
    自己尝试弄了下失败了

  2. 求助表示:

    rtorrent: Could not lock session directory: "/home/peter/rtorrent/.sessions/", No such file or directory

    1. Admin表示:

      修改.rtorrent.rc的「session = 」路徑
      如果是root執行的mkdir ~/rtorrent/.sessions
      session路徑會是/root/rtorrent/.sessions

      如果是用peter執行mkdir ~/rtorrent/.sessions
      session路徑會是/home/peter/rtorrent/.sessions

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

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

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