Synology 上安装 RTorrent 和 ruTorrent 代替 Transmission

nginx synology rtorrent rutorrent transmission nas optware

之前一直在 NAS 上使用 transmission 作为 PT 的客户端, 不过前段时间 皇后PT 突然封了 transmission 客户端, 理由据说是有人用了离线网盘下载内容, 而离线网盘用的客户端是 transmission. 于是就无差别封了所有是 transmission 的客户端了, 比较脑残.

不过本来就觉得我目前用的 transmission web - transmission-control 有点小 bug 而且也没 RSS 功能, 也就正好借着这个机会去试试看其他的客户端. 一圈观察下来最终选中了 RTorrent

安装准备

RTorrent 不同于 transmission 有第三方的源可以直接装, 而需要自己通过 optware(ipkg) 来安装. 所以首先需要准备好 optware 环境, 安装的过程可以参考: How to Install Bootstrap - SynologyWiki

另外每次升级系统以后也需要重新安装下 optware.

安装 RTorrent

首先 ipkg update 更新可安装包列表, 然后安装 RTorrent

ipkg install rtorrent screen bash

完成以后, 创建运行 RTorrent 所需要的目录

mkdir -p /opt/share/torrent/session/
mkdir /opt/var/log/

接着修改 /opt/etc/rtorrent.conf 文件, 在最后加入

scgi_port = 127.0.0.1:5050
encoding_list = UTF-8

其中 scgi_port 用于其他程序进行控制, 而 encoding_list 据说用于解决中文乱码问题.

另外如果需要命令行去查看 RTorrent 信息的话, 还需要将系统的默认输出编码修改成 UTF-8, 我们在 /etc/profile 最后加入

export LANG=en_US.UTF-8

然后重新登入 SSH 使得设置生效, 接着就可以通过命令启动 RTorrent

/opt/etc/init.d/S99rtorrent start

运行 RTorrent 后, 可以通过 screen -r 来查看启动情况

DS1337> screen -r
                                            *** rTorrent 0.8.6/0.12.6 - DS1337:16437 ***
[View: main]



(12:51:56) Using 'epoll' based polling.
(12:51:56) Ignoring ~/.rtorrent.rc.
(12:51:56) XMLRPC initialized with 519 functions.
(12:51:56) The SCGI socket is bound to a specific network device yet may still pose a security risk, consider using 'scgi_local'.
[Throttle  80/ 80 KB] [Rate   0.0/  0.0 KB] [Port: 51780]                            [U 0/26] [D 0/26] [H 0/32] [S 0/3/768] [F 0/128]

然后按 ctrl+a + d 可以切出 screen. 还继续输入 screen -r 有可以进入查看了.

如果遇到出现这样的错误

DS1337> screen -r
Cannot find termcap entry for 'xterm-256color'.

就需要在 ~/.profile 的最后加入

if [ "$TERM" == "xterm-256color" ]; then
	export TERM=xterm-color
fi

因为 ipkg 安装的 screen 并不支持 256color, 要支持的话需要手工重新编译才行.

另外输入 /opt/etc/init.d/S99rtorrent stop 可以停止 RTorrent.

安装 ruTorrent

之前安装的 RTorrent 只是一个后台进程, 要通过浏览器对他进行控制的话我们还需要安装 ruTorrent.

ruTorrent 是 php 写的 WEB 程序, 所以还需要安装对应的服务器软件.

按文档这里应该使用 lighttpd 作为 ruTorrent 的服务器, 不过我在我 NAS上测试后发现, 重启NAS 以后自动启动的 lighttpd 会运行几秒钟, 然后自动关闭. 而手工启动的 lighttpd 却没有任何问题. 研究了半天无果, 最终决定放弃 lighttpd 改用 nginx.

所以这里我们输入

ipkg install nginx php-fcgi spawn-fcgi

等安装完成以后在 /opt/etc/init.d/ 下新建一个文件 S80php-fcgi 内容是

#!/bin/sh

phpfcgid_children="1"
phpfcgid_requests="1000"
prefix="/opt" 
PATH=${prefix}/bin:${prefix}/sbin:/sbin:/bin:/usr/sbin:/usr/bin 
NAME=php-fcgi
DAEMON=${prefix}/bin/spawn-fcgi
DAEMON_OPTS="-s /opt/tmp/php-fcgi.sock -C ${phpfcgid_children} -u nobody -P /opt/var/run/php-fcgi.pid -- ${prefix}/bin/${NAME}"

test -x $DAEMON || exit 0

if [ -z "$1" ] ; then
    case `echo "$0" | sed 's:^.*/\(.*\):\1:g'` in
        S??*) rc="start" ;;
        K??*) rc="stop" ;;
        *) rc="usage" ;;
    esac
else
    rc="$1"
fi

case "$rc" in
    start)
        export PHP_FCGI_MAX_REQUESTS=$phpfcgid_requests
        echo "Starting web server: $NAME"
        $DAEMON $DAEMON_OPTS
        ;;
    stop)
        if [ -n "`pidof $NAME`" ]; then
            echo "Stopping web server: $NAME"
            killall $NAME 2> /dev/null
        fi
        ;;
    restart)
        "$0" stop
        sleep 1
        "$0" start
        ;;
    *)  
        echo "Usage: $0 (start|stop|restart|usage)"
        ;;
esac

exit 0

然后给予这个文件执行权限和建立相关目录并启动

chmod +x /opt/etc/init.d/S80php-fcgi
mkdir -p /opt/var/run/
/opt/etc/init.d/S80php-fcgi start

完成以后开始配置 nginx 让他支持 php, 我们编辑 /opt/etc/nginx/nginx.conf

把第一行的 #user nobody; 的注释解开也就是改成

user  nobody;

然后找到

    server {                                                                  
        listen  8082;                                                         
        server_name  localhost;

找到这段以后, 在最后加入

        location ~ \.php$ {
                fastcgi_pass unix:/opt/tmp/php-fcgi.sock;                         
                fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
                include fastcgi_params;     
        }

保存后用命令 /opt/etc/init.d/S80nginx start 启动 nginx 服务器. 然后开始装 RTorrent 和 Plugins

cd /opt/share/nginx
wget -O rutorrent-3.6.tar.gz  http://dl.bintray.com/novik65/generic/rutorrent-3.6.tar.gz
wget -O plugins-3.6.tar.gz http://dl.bintray.com/novik65/generic/plugins-3.6.tar.gz
tar xvf rutorrent-3.6.tar.gz
tar xvf plugins-3.6.tar.gz -C rutorrent/
rm rutorrent-3.6.tar.gz
rm plugins-3.6.tar.gz

然后还需要修改 rutorrent/conf/config.php 文件

  • 将其中的 $scgi_port 修改成 5050 这是之前 /opt/etc/rtorrent.conf 中配置的端口.
  • 另外将 $forbidUserSettings 修改成 true 这个设置的作用是让不同的用户可以有不同的设置, 没啥必要所以去掉.

由于之前解压 ruTorrent 的目录就是 lighttpd 的默认目录, 所以可以直接启动 lighttpd, 输入命令

 /opt/etc/init.d/S80lighttpd start

接着通过浏览器访问 http://NAS_IP:8082/rutorrent 其中 NAS_IP 需要根换成正确的IP地址, 就可以看到如下的效果

可以从日志中看到很多错误, 这个我们先不管, 首先要做的是切换到 插件

需要将其中的 rpc 插件关闭, 因为我们已经载入了一个叫 httprpc 的插件了, 这2个插件作用是相同的, 另外因为有 httprpc 插件, 所以才不需要像其他文档一样需要在 lighttpd 上设置 /PRC2.

另外还需要关闭的一个插件是 filedrop 那个插件是用来让 ruTorrent 支持种子拖拽上传的, 不过插件本身有问题会导致上传的种子文件保存后文件名乱码, 但如果通过添加按钮添加的则不会, 所以先禁用, 以后等有机会看看是哪里的问题.

至于剩下的插件要开要关就自己看着办了.

设置用户认证

默认 ruTorrent 是没有任何认证机制的, 他的认证需要考 HTTP 服务器来实现.

输入命令

/usr/syno/apache/bin/htpasswd -c /opt/etc/nginx/htpasswd admin password

其中 admin 就是登录的用户名, 而 password 就是登录的密码.

接着编辑 /opt/etc/nginx/nginx.conf 继续找到刚刚的加入 php 的那段后加入

        location  /rutorrent  {
                auth_basic            "Restricted";
                auth_basic_user_file  htpasswd;
        }

然后重启服务器

/opt/etc/init.d/S80nginx restart

刷新下浏览器上 ruTorrent 的页面, 现在那个页面应该需要输入用户名和密码才可以使用了.

设置 webman 代理

一般我们设置好了 DDNS 以后就可以在外面访问家里的 NAS 了, 而我们刚刚搭建的 ruTorrent 如果不开 8081 的映射是无法访问的, 所以这里我们把 ruTorrent 映射到 5000 端口的 /rutorrent 下.

先在 /opt/share/www/nginx/rutorrent/conf/rutorrent.alias.conf 新建个文件输入

LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_http_module modules/mod_proxy_http.so

ProxyRequests On
ProxyPreserveHost Off

ProxyPass /rutorrent http://127.0.0.1:8082/rutorrent
ProxyPassReverse /rutorrent http://127.0.0.1:8082/rutorrent

然后链接回群晖自带的 apache

ln -sf /opt/share/www/nginx/rutorrent/conf/rutorrent.alias.conf /usr/syno/etc/sites-enabled/rutorrent.alias.conf

接着重启群晖的 apache

 /usr/syno/apache/bin/httpd -DSSL -f /usr/syno/apache/conf/httpd.conf-sys -k restart

然后我们通过浏览器访问 http://NAS_IP:5000/rutorrent 查看 rutorrent 了.

其他设置

rTorrent 不像其他 BT 软件会自动的用 upnp 在路由器上映射端口, 所以我们需要手工帮他映射端口

默认 rTorrent 使用 51777-51780 端口做通讯, 所以我们打开 DMS, 在 “控制面板” > “路由器配置” 中加入如图红框的自定义端口

另外需要注意的是

在 ruTorrent 的配置都是临时的, 重启服务器以后就会消失. 如果要保证配置文件重启后生效, 需要手工去修改 /opt/etc/rtorrent.conf 这点比较麻烦.

具体的可以看这里: Issue 881 - rutorrent - Configuration not saving

最后

之后的工作只是把之前其他 BT 的种子之类的导入到新的 RTorrent 中. 当然新的 RTorrent 还支持 RSS 之类的就没仔细研究了.

另外实际使用下来发现 ruTorrent 无法批量的修改 ticker, 如果重置 PT 网站 passkey 的话工作量可想而至, 如果有谁知道如何批量修改的话也请告知, 谢谢

参考资料

Comments