搭建自己的 PT 盒子

前言

前些日子,兽兽大佬发了一篇文章介绍了 Debian 9 安装 rTorrent + ruTorrent + Nginx 搭建自己的 PT / BT 盒子,作为国服大刷子(上传量很大很大的人),他的文章是非常有学习价值的了,我正好也想玩玩 PT,正好某个 PT 站公开发邀请,买了几台独服开始玩玩,作为纯新手,记录一下自己学习的过程吧。本文很多都抄自兽兽大佬的文章

Private Tracker,简称 PT,即私用种子服务器。Private Tracker 可以统计用户的上传和下载量,计算用户的分享率。可以简单将它理解为 BT 的升级版,在拥有 BT 所有功能的同时,需要达到一定的分享率才能不被删除帐号。PT 下载其实也是 BT 下载的一种,但有两个明显的改进:一是私密的小范围下载,二是进行流量统计,根据上载量决定你的权限

安装 rTorrent

业内用来刷 PT/BT 的有很多种软件,比如 TransmissionDelugeuTorrent等等,这边选择了 rTorrent,至于原因,据兽兽大佬所说,rTorrent 上传量最高,适合大刷子使用,其他的特点还有占用内存小、频宽利用率高等等。

本次安装使用 Debian 9.4

安装必备软件

这边的介绍非常简单,详细的设置可以参考 LEMP 安装教程

apt update && apt upgrade -y && apt install sudo nano curl vim wget rtorrent apt-transport-https lsb-release ca-certificates git subversion python-pip python-dev build-essential unrar-free unzip sqlite3 apache2-utils mediainfo -y

pip install -U pip && pip install supervisor

curl -sL https://deb.nodesource.com/setup_8.x | bash - && apt install nodejs -y
sudo npm i npm -g && sudo npm i pm2 -g && sudo npm i node-gyp -g

wget -O /etc/apt/trusted.gpg.d/nginx-mainline.gpg https://packages.sury.org/nginx-mainline/apt.gpg
sh -c 'echo "deb https://packages.sury.org/nginx-mainline/ $(lsb_release -sc) main" > /etc/apt/sources.list.d/nginx.list'
apt update && apt install nginx-extras -y 

后台运行 rTorrent

为了简化步骤,我们假设在 root 用户下运行 rTorrent,并且设置下载目录在 /var/www/downloads,虽然这样并不是特别的安全。

sudo mkdir -p /var/www/downloads/{.session,~watch}

创建配置文件:

nano ~/.rtorrent.rc

参考配置内容如下:

# Maximum and minimum number of peers to connect to per torrent.
min_peers = 40
max_peers = 100

# Same as above but for seeding completed torrents (-1 = same as downloading)
min_peers_seed = 40
max_peers_seed = 100

# Maximum number of simultanious uploads per torrent.
max_uploads = 50

# Global upload and download rate in KiB. "0" for unlimited.
download_rate = 0
upload_rate = 0

# Default directory to save the downloaded torrents.
directory = /var/www/downloads

# Default session directory. Make sure you don't run multiple instance of rtorrent using the same session directory. Perhaps using a relative path?
session = /var/www/downloads/.session

# Watch a directory for new torrents, and stop those that have been deleted.
schedule = watch_directory,5,5,load_start=/var/www/downloads/.watch/*.torrent
schedule = untied_directory,5,5,stop_untied=

# Close torrents when diskspace is low.
schedule = low_diskspace,5,60,close_low_diskspace=10240M

# The ip address reported to the tracker.
# ip = 127.0.0.1
# ip = rakshasa.no

# The ip address the listening socket and outgoing connections is bound to.
# bind = 127.0.0.1
# bind = rakshasa.no

# Port range to use for listening.
port_range = 55950-56000

# Start opening ports at a random position within the port range.
port_random = yes

# Check hash for finished torrents. Might be usefull until the bug is fixed that causes lack of diskspace not to be properly reported.
check_hash = no

# Set whether the client should try to connect to UDP trackers.
use_udp_trackers = yes

# Alternative calls to bind and ip that should handle dynamic ip's.
# schedule = ip_tick,0,1800,ip=rakshasa
# schedule = bind_tick,0,1800,bind=rakshasa

# Encryption options, set to none (default) or any combination of the following: allow_incoming, try_outgoing, require, require_RC4, enable_retry,prefer_plaintext
# The example value allows incoming encrypted connections, starts unencrypted outgoing connections but retries with encryption if they fail, preferring plaintext to RC4 encryption after the encrypted handshake

encryption = allow_incoming,enable_retry,prefer_plaintext

# Enable DHT support for trackerless torrents or when all trackers are down.
# May be set to "disable" (completely disable DHT), "off" (do not start DHT), "auto" (start and stop DHT as needed), or "on" (start DHT immediately). The default is "off". For DHT to work, a session directory must be defined.
dht = disable
# UDP port to use for DHT.
# dht_port = 6881

# Enable peer exchange (for torrents not marked private)
peer_exchange = no

scgi_port = 127.0.0.1:5000

network.xmlrpc.size_limit.set = 2000000

编辑完成后按 ctrl + x 保存退出,再按 y 确认即可:

使用 Supervisor 后台运行 rTorrent

echo_supervisord_conf > /etc/supervisord.conf
mkdir -p /var/log/supervisor
nano /etc/supervisord.conf

在文件末尾加入如下内容:

[program:rtorrent]
command = /usr/bin/rtorrent
user = root
autostart = true
autorestart = true
stdout_logfile = /var/log/supervisor/rtorrent.log
stderr_logfile = /var/log/supervisor/rtorrent.error.log

后台运行:

supervisord -c /etc/supervisord.conf

管理命令:

supervisorctl status
supervisorctl [stop|start|reread] xxx
supervisorctl update xxx

使用 Flood 管理 PT 下载

Flood 是一个基于 nodejs 的现代化管理 rtorrent 的 GUI 界面,整体设计较为美观,使用也比较方便。

安装配置 Flood

cd /var/www && git clone https://github.com/jfurrow/flood.git && cd flood && cp config.template.js config.js
sudo npm i --unsafe-perm && sudo npm run build && pm2 start npm -- start

然后 Flood 就会运行在 127.0.0.1:3000 端口,这个端口可以在 config.js 中修改。

Nginx 整合

如果修改 config.js 中端口监听 0.0.0.0 那么就直接可以公网访问,当然更好的办法是使用 Nginx 转发一下,参考配置如下:

location / {
    proxy_connect_timeout 10;
    proxy_send_timeout 60;
    proxy_read_timeout 60;
    proxy_buffer_size 64k;
    proxy_buffers 16 32k;
    proxy_busy_buffers_size 128k;
    proxy_temp_file_write_size 64k;
    proxy_pass_header Set-Cookie;
    proxy_redirect off;
    proxy_set_header Referer $http_referer;
    proxy_set_header Host $host;
    proxy_http_version 1.1;
    proxy_hide_header X-Powered-By;
    proxy_set_header Cookie $http_cookie;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-Host $host;
    proxy_set_header X-Forwarded-Server $host;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_no_cache $http_pragma $http_authorization;
    proxy_cache_bypass $http_pragma $http_authorization;
    proxy_pass http://127.0.0.1:3000;
    client_max_body_size 10m;
    client_body_buffer_size 1m;
}

目前 flood 可能会出现上传种子出现失败,选择通过链接添加种子即可。

Last modification:May 6th, 2018 at 09:48 pm

Leave a Comment