12月 13, 2013

(Debian/Ubuntu) 第一次設定 rtorrent 就上手

零、概念:
User / Browser -->Web Server-->rutorrent--scgi:5000--> rtorrent
前端叫:rutorrent (這是 php 寫成的網頁)
後端叫:rtorrent (兩者差一個"u"字 別搞錯了)

使用者用瀏覽器操作 UI 介面,訊號透過 SCGI 傳到後端的 rtorrent 程式。
一、安裝 web server、php、rtorrent、screen
 # apt-get install lighttpd rtorrent php5-cgi screen
Reading package lists... Done
  Building dependency tree
  Reading state information... Done
  The following NEW packages will be installed:
    lighttpd php5-cgi php5-common rtorrent spawn-fcgi
  After this operation, 23.4 MB of additional disk space will be used.

二、啟用 php 模組
# vim /etc/lighttpd/conf-enabled/15-fastcgi-php.conf
server.modules += ( "mod_fastcgi" )
fastcgi.server += ( ".php" =>
  ((
      "bin-path" => "/usr/bin/php-cgi",
      "socket" => "/var/run/lighttpd/php.socket",
      "max-procs" => 1,
      "bin-environment" => (
          "PHP_FCGI_CHILDREN" => "0",
          "PHP_FCGI_MAX_REQUESTS" => "10000"
      ),
      "bin-copy-environment" => (
              "PATH", "SHELL", "USER"
      ),
      "broken-scriptfilename" => "enable"
   ))
)

三、開啟 Web Server 上的 SCGI 通道 (使用 Port 5000,連線名稱 RPC2)
# vim /etc/lighttpd/conf-enabled/20-bt.conf
server.modules += ( "mod_scgi" )
scgi.server = (
"/RPC2"=>
 (
 "127.0.0.1" =>
  (
   "host" => "127.0.0.1",
   "port" => 5000,
   "check-local" => "disable"
  )
 )
)

四、建立「家目錄」網頁鏈結(假設用戶 jack) 並重新啟動 Web Server
# ln -s /home/jack /var/www/jack
# /etc/init.d/lighttpd restart
* Stopping web server lighttpd             [ OK ]
* Starting web server lighttpd             [ OK ]

五、接下來請用一般用戶(jack)權限,我們要開始設定 Web UI 部份。
$ cd ~
$ wget http://dl.bintray.com/novik65/generic/rutorrent-3.6.tar.gz
$ tar -zxvf rutorrent-3.6.tar.gz
$ chmod -R 777 ./rutorrent/share/
$ mkdir /tmp /bt  /bt/session

六、設定使用者 rtorrent 環境檔案:.rtorrent.rc
$ vim ~/.rtorrent.rc
# Maximum and minimum number of peers to connect to per torrent.
min_peers = 20
max_peers = 60

# Same as above but for seeding completed torrents
min_peers_seed = 1
max_peers_seed = 1

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

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

# Default directory to save the downloaded torrents.
directory = ./

# Default session directory.
session = ./session

# For Web UI (Rutorrent @ SCGI port 5000)
scgi_port = localhost:5000
encoding_list = UTF-8

# Watch a directory for new torrents
schedule = watch_directory,5,5, "load_start=./*.torrent, d.set_custom1=./../tmp"
system.method.set_key = event.download.finished,move_complete,"execute=mv,-u,$d.get_base_path=,$d.get_custom1=;"

# Enable DHT.
dht = on
dht_port = 6778

# Enable peer exchange
peer_exchange = yes

七、執行 rtorrent 並用 screen 丟在背景執行 (Ctrl+a d)
$ screen
$ cd bt
~/bt$ rtorrent

八、設定結束了。上傳種子有兩種方式:
(a) 透過網頁 http://x.x.x.x/jack/rutorrent/ 進行種子上傳。
(b) 透過 FTP 將種子上傳到 ~/bt/ 目錄下。
九、請記得:rtorrent 一定要在 screen 裡面執行,才能確保 torrent 運作不中斷。

沒有留言:

張貼留言