前言
教學通過測試於CentOS 7,支援IPv6。若想用於其他/不同版本的系統,請自行修改指令和軟件包名稱。
以下將編譯安裝rtorrent和libtorrent的原生0.9.6版本
其他系統編譯rtorrent教學:
Debian 8 (Jessie): https://npchk.info/debian8-install-rtorrent/
Ubuntu 18: https://npchk.info/ubuntu-bionic-install-rtorrent/
上次更新時間: 2019年5月2日
安裝編譯工具與依賴
yum groupinstall "Development Tools" yum install cppunit-devel libtool zlib-devel gawk libsigc++20-devel openssl-devel ncurses-devel libcurl-devel xmlrpc-c-devel wget unzip screen
關閉SElinux:
vi /etc/selinux/config 如果看見SELINUX=enforcing或permissive,就把他換成SELINUX=disabled和重啟系統
編譯rtorrent 0.9.7
從Github取得libtorrent 0.13.7:
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
編譯及安裝libtorrent:
./autogen.sh ./configure --disable-debug make -j$(nproc) make install cd ~
設定環境變量 不設定rtorrent會找不到libtorrent:
vi /etc/ld.so.conf #加入一行 /usr/local/lib/
export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig 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 ~
設定環境變量 不設定rtorrent會找不到libtorrent:
vi /etc/ld.so.conf #加入一行 /usr/local/lib/
export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig 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 passwd peter
配置Nginx和PHP
安裝RuTorrent的網頁伺服器軟體:
yum install epel-release yum install nginx php-fpm httpd-tools php-cgi php-cli curl
禁用Nginx默認網站 編輯站點配置文件:
rm -f /usr/share/nginx/html/index.html /etc/nginx/nginx.conf vi /etc/nginx/nginx.conf
#輸入以下內容
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;
# Load dynamic modules. See /usr/share/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;
events {
worker_connections 1024;
}
http {
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
include /etc/nginx/mime.types;
default_type application/octet-stream;
# Load modular configuration files from the /etc/nginx/conf.d directory.
# See http://nginx.org/en/docs/ngx_core_module.html#include
# for more information.
include /etc/nginx/conf.d/*.conf;
server {
server_name _;
root /usr/share/nginx/html/;
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;
scgi_pass 127.0.0.1:5000;
include scgi_params;
scgi_param SCRIPT_NAME /RPC2;
}
location ~ \.php$ {
try_files $uri =404;
#fastcgi_pass unix:/run/php-fpm/php-fpm.sock;
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-fpm:
vi /etc/php-fpm.d/www.conf #修改參數# user = peter group = peter 取消注釋 env[PATH] = /usr/local/bin:/usr/bin:/binlisten = /run/php-fpm/php-fpm.sock
配置php-geoip:
yum install php-pecl-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
重啟php-fpm和Nginx以套用新設置:
systemctl restart php-fpm systemctl restart nginx
設置開機自啟動:
systemctl enable nginx.service systemctl enable php-fpm.service
配置RuTorrent及Plugins
從Github取得RuTorrent:
wget https://github.com/Novik/ruTorrent/archive/master.zip unzip master.zip
移動RuTorrent到Nginx的www目錄:
mv ruTorrent-master /usr/share/nginx/html/rt
設置RuTorent需賬號及密碼登錄(例如peter):
htpasswd -c /etc/nginx/htpasswd peter
設置RuTorrent與PHP使用者peter的權限:
chown peter -R /usr/share/nginx/html/rt/share
以下將配置RuTorrent的Plugins的依賴
vi /var/www/rt/conf/config.php
#替換$pathToExternals = array( );的內容:
$pathToExternals = array(
"php" => '/bin/php', // Something like /usr/bin/php. If empty, will be found in PATH.
"curl" => '/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/pgrep', // Something like /usr/bin/gzip. If empty, will be found in PATH.
"id" => '/bin/id', // Something like /usr/bin/id. If empty, will be found in PATH.
"stat" => '/bin/stat', // Something like /usr/bin/stat. If empty, will be found in PATH.
"python" => '/bin/python', // Something like /usr/bin/python. If empty, will be found in PATH.
);
設置RuTorrent使用UNIX Domain Socket連接Nginx/rtorrent:
###以下部分測試中,請無視###
vi /usr/share/nginx/html/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的依賴
rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7 rpm --import http://li.nux.ro/download/nux/RPM-GPG-KEY-nux.ro rpm -Uvh http://li.nux.ro/download/nux/dextop/el7/x86_64/nux-dextop-release-0-1.el7.nux.noarch.rpm yum install ffmpeg unzip mediainfo unrar sox python python-pip pip install --upgrade pip hash -d pip pip install cfscrape pyrocore
配置rtorrent
**登錄至使用者peter,以下將使用peter操作**
創建rtorrent配置文件:
vi ~/.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 scgi_port = 127.0.0.1:5000 ip = *.*.*.*
創建下載、監控及記錄目錄:
mkdir ~/Downloads mkdir ~/rtorrent/ mkdir ~/rtorrent/incoming mkdir ~/rtorrent/.sessions mkdir ~/rtorrent/torrents/
設置防火墻
檢查防火墻服務狀態:
systemctl status firewalld
若防火墻正在運行,需打開rtorrent的34543監聽端口:
firewall-cmd --permanent --add-port=34543/tcp
載入設定:
firewall-cmd --reload
設置開機自啟
vi /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
啟用以上設置:
systemctl enable rtorrent.service
啟動rtorrent
systemctl start rtorrent.service
安裝完成,訪問RuTorrent: http://YOURIPADDRESS/rt/
安裝資訊
下載文件的保存目錄/位置 = /home/peter/Downloads 監控目錄 = /home/peter/rtorrent/torrents/ Nginx根目錄 = /usr/share/nginx/html/ 訪問rtorrent命令行界面: screen -r rtorrent
你好,在u2里看到了你个人页面里的教程地址,就点进来了,受益匪浅。可否出一篇配置https访问web ui的教程
可以用Cloudflare + Always Use HTTPS,毋需設置Nginx和SSL證書續期。
谢谢你的解答,最近在学习搭建rtorrent+rutorrent,不喜欢用一键脚本,看你的博客学了不少东西,表示感谢!你在u2个人主页里共享的离线服务器,用手机端查看的时候有不能滑动的问题,可以考虑禁用 ipad插件,然后用另外一个作者的rutorrent mobile分支解决~