配置环境
VPS 使用的系统是 Ubuntu 18.04,已经安装了 caddyserver,所以继续使用 caddy 作为 http server。
安装必备软件
apt update && apt dist-upgrade -y && apt install sudo nano curl vim wget apt-transport-https lsb-release ca-certificates git subversion python-pip python-dev build-essential unrar-free unzip mediainfo man-db -y
curl -sL https://deb.nodesource.com/setup_10.x | bash -
curl -sL https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add - && echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
apt update && apt install nodejs yarn -y && yarn global add pm2 node-gyp
使用 rTorrent 下载器
安装 rTorrent
rTorrent 0.9.6 会导致误报上传,故编译安装最新版 0.9.7
安装 libtorrent
wget https://github.com/rakshasa/rtorrent/releases/download/v0.9.7/libtorrent-0.13.7.tar.gz
tar -zxvf libtorrent-0.13.7.tar.gz
cd libtorrent-0.13.7
./configure; make; make install
安装 rTorrent
wget https://github.com/rakshasa/rtorrent/releases/download/v0.9.7/rtorrent-0.9.7.tar.gz
tar -zxvf rtorrent-0.9.7.tar.gz
cd rtorrent-0.9.7
./configure --with-xmlrpc-c
make
make install
配置 rTorrent
为了简化步骤,我们假设在 root 用户下运行 rTorrent,并且设置下载目录在 /usr/local/caddy/www/file/pt/
,虽然这样并不是特别的安全。
mkdir /etc/rtorrent
创建配置文件
vim /etc/rtorrent/rtorrent.rc
参考配置:
## Instance layout (base paths)
method.insert = cfg.basedir, private|const|string, (cat,"/usr/local/caddy/www/file/pt/")
method.insert = cfg.download, private|const|string, (cat,(cfg.basedir),"download/")
method.insert = cfg.logs, private|const|string, (cat,(cfg.basedir),"log/")
method.insert = cfg.logfile, private|const|string, (cat,(cfg.logs),"rtorrent-",(system.time),".log")
method.insert = cfg.session, private|const|string, (cat,(cfg.basedir),".session/")
method.insert = cfg.watch, private|const|string, (cat,(cfg.basedir),"watch/")
## Create instance directories
execute.throw = sh, -c, (cat,\
"mkdir -p \"",(cfg.download),"\" ",\
"\"",(cfg.logs),"\" ",\
"\"",(cfg.session),"\" ",\
"\"",(cfg.watch),"/load\" ",\
"\"",(cfg.watch),"/start\" ")
## Listening port for incoming peer traffic (fixed; you can also randomize it)
network.port_range.set = 55950-56000
network.port_random.set = yes
## Tracker-less torrent and UDP tracker support
## (conservative settings for 'private' trackers, change for 'public')
dht.mode.set = disable
protocol.pex.set = no
trackers.use_udp.set = yes
## Peer settings
throttle.max_downloads.global.set = 300
throttle.max_uploads.global.set = 300
throttle.max_downloads.set = 50
throttle.max_uploads.set = 50
throttle.global_down.max_rate.set_kb = 0
throttle.global_up.max_rate.set_kb = 0
throttle.min_peers.normal.set = 90
throttle.max_peers.normal.set = 100
throttle.min_peers.seed.set = -1
throttle.max_peers.seed.set = -1
trackers.numwant.set = 100
protocol.encryption.set = allow_incoming,try_outgoing,enable_retry
## Limits for file handle resources, this is optimized for
## an `ulimit` of 1024 (a common default). You MUST leave
## a ceiling of handles reserved for rTorrent's internal needs!
network.http.max_open.set = 99
network.max_open_files.set = 600
network.max_open_sockets.set = 900
network.receive_buffer.size.set = 4M
network.send_buffer.size.set = 12M
## Memory resource usage (increase if you have a large number of items loaded,
## and/or the available resources to spend)
pieces.memory.max.set = 1024M
network.xmlrpc.size_limit.set = 4M
## Basic operational settings (no need to change these)
session.path.set = (cat, (cfg.session))
directory.default.set = (cat, (cfg.download))
log.execute = (cat, (cfg.logs), "execute.log")
log.xmlrpc = (cat, (cfg.logs), "xmlrpc.log")
execute.nothrow = sh, -c, (cat, "echo >",\
(session.path), "rtorrent.pid", " ",(system.pid))
## Other operational settings (check & adapt)
encoding.add = utf8
system.umask.set = 0027
system.cwd.set = (directory.default)
network.http.dns_cache_timeout.set = 25
schedule2 = monitor_diskspace, 15, 60, ((close_low_diskspace, 1000M))
pieces.preload.type.set = 2
pieces.hash.on_completion.set = no
view.sort_current = seeding, greater=d.ratio=
keys.layout.set = qwerty
#network.http.capath.set = "/etc/ssl/certs"
network.http.ssl_verify_peer.set = 0
network.http.ssl_verify_host.set = 0
## Some additional values and commands
method.insert = system.startup_time, value|const, (system.time)
method.insert = d.data_path, simple,\
"if=(d.is_multi_file),\
(cat, (d.directory), /),\
(cat, (d.directory), /, (d.name))"
method.insert = d.session_file, simple, "cat=(session.path), (d.hash), .torrent"
## Watch directories (add more as you like, but use unique schedule names)
## Add torrent
schedule2 = watch_load, 11, 10, ((load.verbose, (cat, (cfg.watch), "load/*.torrent")))
## Add & download straight away
schedule2 = watch_start, 10, 10, ((load.start_verbose, (cat, (cfg.watch), "start/*.torrent")))
## Run the rTorrent process as a daemon in the background
## (and control via XMLRPC sockets)
system.daemon.set = true
network.scgi.open_local = (cat,(session.path),rpc.socket)
execute.nothrow = chmod,770,(cat,(session.path),rpc.socket)
## Logging:
## Levels = critical error warn notice info debug
## Groups = connection_* dht_* peer_* rpc_* storage_* thread_* tracker_* torrent_*
print = (cat, "Logging to ", (cfg.logfile))
log.open_file = "log", (cfg.logfile)
log.add_output = "info", "log"
#log.add_output = "tracker_debug", "log"
使用 Systemd 运行 rTorrent
创建配置文件
nano /etc/systemd/system/rtorrent.service
参考配置:
[Unit]
Description=systemd integration for rtorrent - starts/stops rtorrent instances on startup/shutdown
Wants=network-online.target
After=network-online.target
[Service]
User=root
Group=root
Type=simple
KillMode=process
ExecStart=/usr/local/bin/rtorrent -n -o import=/etc/rtorrent/rtorrent.rc
WorkingDirectory=/usr/local/caddy/www/file/pt
[Install]
WantedBy=multi-user.target
管理方式为:
systemctl start rtorrent
systemctl [restart|stop|enable|status] rtorrent
使用 Flood 管理 PT 下载
Flood 是一个基于 nodejs 的现代化管理 rtorrent 的 GUI 界面,整体设计较为美观,使用也比较方便。
安装 Flood
cd /usr/local/caddy/www/
git clone https://github.com/jfurrow/flood.git
cd flood && cp config.template.js config.js
npm install && npm run build
NODE_ENV=production pm2 start server/bin/start.js --name flood
然后 Flood 就会运行在 127.0.0.1:3000
端口,这个端口可以在 config.js
中修改。
caddy 整合
nano /usr/local/caddy/Caddyfile
参考配置:
[域名] {
gzip
timeouts none
tls [email]
proxy / http://127.0.0.1:3000
}
初次登录配置
第一次登录 Flood 会要求创建帐号和填写 rTorrent 接口,这里选择 Unix Socket
,参考路径:/usr/local/caddy/www/file/pt/.session/rpc.socket