« Linux 自動餵貓機 | 首頁 | 2006/09, Vol. 128 PChome Magazine »

2006年08月29日

Linux Console 下的 BT 操作

在 Fecora Core 1 安裝 BitTorrent 4.20.9

安裝 Python 2.4

wget http://www.python.org/ftp/python/2.4.3/Python-2.4.3.tar.bz2

tar jxf Python-2.4.3.tar.bz2

cd Python-2.4.3

./configure

make

make install

安裝 zope.interface

wget http://www.zope.org/Products/ZopeInterface/3.0.1final/ZopeInterface-3.0.1.tgz

tar zxf ZopeInterface-3.0.1.tgz

cd ZopeInterface-3.0.1

python setup.py install

安裝 Twisted

wget http://tmrc.mit.edu/mirror/twisted/Twisted/2.4/Twisted-2.4.0.tar.bz2

tar jxf Twisted-2.4.0.tar.bz2

cd Twisted-2.4.0

python setup.py install

安裝 python.crypto

wget http://www.amk.ca/files/python/crypto/pycrypto-2.0.1.tar.gz

tar zxf pycrypto-2.0.1.tar.gz

cd pycrypto-2.0.1

python setup.py install

安裝 BitTorrent 4.20.9

wget http://download.bittorrent.com/dl/BitTorrent-4.20.9.tar.gz

tar zxf BitTorrent-4.20.9.tar.gz

cd BitTorrent-4.20.9

python setup.py install

在 Linux Console 下載 BitTorrent-shared file

bittorrent-console --save_in /path/to/save_file http://somewhere.of.internet/somefile.torrent

常用參數備忘

參數 說明 範例
--max_upload_rate 限制最大上載頻寬 (B/s) --max_upload_rate 10
--max_download_rate 限制最大下載頻寬 (B/s) --max_download_rate 100
--save_in 下載檔案存放路徑
(預設: ~/Desktop/BitTorrent Downloads)
--save_in ~/downloads
--save_as 下載檔案另存檔名 --save_as myname.iso
--save_incomplete_in 未下載完成的檔案存放路徑
(預設: ~/.bittorrent/incomplete)
--save_incomplete_in /tmp
--language 設定語系 --language zh_TW

其他備忘

  • 使用 bittorrent-curses 替代 bittorrent-console 指令 (參數相同), 可獲得較佳的視覺效果
  • 背景執行 bittorrent-console 下載: 於指令最後加上 > /dev/null 2>&1 & 即可

在自己的 Web 站台發佈自製種子

Server 端操作 (with Apache HTTP Server)

啟用 BitTorrent tracker

bittorrent-tracker --port 6969 --dfile /tmp/dstate > /dev/null 2>&1 &

產生 .torrent 檔案

maketorrent-console \
--use_tracker http://your.web.host:6969/announce \
/path/to/shared_file

將 .torrent 檔案置入站台目錄

mv /path/to/file.torrent /var/www/html

於 Apache HTTP Server 設定檔加入 .torrent File Type

vi httpd.conf

AddType application/x-bittorrent .torrent

killall -HUP httpd

產生種子

bittorrent-console \
--save_in /path_of_shared_file/ \
/var/www/html/file.torrent

開放防火牆

iptables -A INPUT -p tcp --dport 6969 -j ACCEPT

iptables -A INPUT -p tcp --dport 6881:6889 -j ACCEPT

Client 端操作

以任一種 BitTorrent Client 開啟 URL: http://your.web.host/file.torrent 即可

參考資料:

相關資源:

Posted by Jamyy at 2006年08月29日 12:54

Trackback Pings

TrackBack URL for this entry:
http://cha.homeip.net/cgi-bin/mt/mt-tb.cgi/224

Comments

請問關于bittorrent-tracker的作用是追蹤什么信息?
與Windows相比,Linux+Bittorrent的下載速度很慢。這與Bittorrent自身有關繫嗎?

Posted by: Ivan at 2006年09月11日 15:16

您好!

Tracker 的是指運行於伺服器上的一個軟體,負責分配頻寬(bandwidth),而不是用於分享檔案的所有人包括種子同peer的ul與dl都依賴Tracker來分配頻寬。

這個軟體能夠追蹤到底有多少人同時在下載同一個文件。客戶端連上tracker伺服器,就會獲得一個下載人員的名單,根據這個,BT會自動連上別人的機器進行下載。

(引用自: http://www.btzonebt.com/airways/viewthread.php?tid=57844)

Linux 的 BT 比 Windows 的慢? 真的嗎? 不好意思, 雖然我寫了這篇關於 Linux BT 的文章, 但我還真沒在 Linux 實際使用過 BT... :P

用搜尋引擎查了一下, 似乎找不到關於 Linux BT 比較慢的內容. 不過, 就一般使用 BT 軟體的觀點而言, 會影響下載速度的不外乎是「防火牆」(未開放 tcp port 6881 ~ 6889) 和「網路設置」 (BT 本身允許的上載頻寬太小、其他會影響傳輸速度的網路設定) 的問題, 也許您可以朝這些方向進行調整.

Posted by: Jamyy at 2006年09月11日 15:42

您好~
謝謝您的囬答。

其實關于Linux下的BT軟件我試了幾個。
用C寫的Libbt(libbt-1.05)和ctorrent(ctorrent-1.3.4)
還有就是這個Python寫的BitTorrent。
比較了一下下載速度,髮現好像BitTorrent的速度稍快,不過也隻有幾個KB。而前面兩個用C寫的軟件幾乎沒有下載速度。而且好像每次都是剛啓動的時候會有個很快的下載速度,但是在瞬間就降為0。之后就沒有任何反應。

我檢查了port是打開的,而防火牆我也是關閉的~

Posted by: Ivan at 2006年09月14日 15:25

您好!

關於防火牆的部份,
除非您的電腦直接擁有 Public IP, 否則只有開放自己本身的防火牆是不夠的.
如果您是透過 IP 分享器上網, 那麼就得在 IP 分享器中設置 Virtual Server 或 Port Forwarding, 將 TCP 6881 ~ 6889 port 指向內部 BT 電腦.
如果您是透過自行架設的 Linux NAT 上網, 就在 Linux NAT 設置 iptables:
iptables -t nat -A PREROUTING -p tcp --dport 6881:6889 -j DNAT --to-destination 192.168.1.2
其中, 192.168.1.2 係指內部 BT 電腦 IP, 以上一樣是 Port Forwarding 的意思.
簡而言之, 就是設定成從外部連結您的 Public IP:6881 就能直接連入 BT 電腦.

P2P 這玩意真的是越多人分享, 下載速度就越快 (或者說越能以穩定的進度下載成功)
熱門的檔案或許一兩天就能下載完成, 冷門的東西也許掛上一個禮拜也不見得下載得成. 我覺得這才是真正影響下載速度的因素... :)

Posted by: Jamyy at 2006年09月14日 23:19

Hi

I want to make an auto tracker to my PHP web server, but the following command cannot put in to background:

bittorrent-console case28.pdf.torrent > /dev/null 2>&1 &

Posted by: Tao at 2006年11月10日 17:59

應該是操作錯誤所致. 請將 "> /dev/null 2>&1 &" 拿掉, 以查看錯誤訊息.

如果您要產生種子, 請記得使用 --save_in 參數, 將其指向檔案所在的路徑.

Posted by: Jamyy at 2006年11月13日 10:32

Hi~
透過google 找到這
我是想問問有關Azureus 的問題
因為我在RH9 上使用 Azureus , 我也發生了連線一段時間
Azureus 跳出了 類似 127.0.0.1:6881 disconnection 的字眼(詳細有點忘了) 然後全部下載跟上傳都停止了.
Router 方面我是有開 virtual server and Special App
但是我在想我是不是也要打開iptable 加上
iptables -A INPUT -p tcp --dport 6881:6889 -j ACCEPT

這一串, 因為我感覺我好像是被自己的防火牆 檔下來了.

Posted by: RL at 2006年12月06日 11:16

我在 Fedora Core 6 使用 Azureus 2.5.0.0
IP 分享器不做 Virual Server
甚至在 FC6 本機設置 iptables -A INPUT -p tcp --dport 6881:6889 -j DROP 都沒有發生你說的問題

謝謝你告訴我這個好用的 BT 軟體 :)

Posted by: Jamyy at 2006年12月06日 13:54

請問bittorrent-console 是否支援內函中文檔名的torrent檔?
我之前試著要下載中文的torrent檔, 結果bittorrent像當掉一樣,毫無反應,最後只能下kill關掉

Posted by: davy at 2007年11月08日 10:29

davy 您好,

中文的網址要使用編碼過的 (%EA%57...)
而且網址要用引號括起來才行
以 fkee.com 搜尋到的 bt 種子為例
在檔案連結按右鍵, 點選 "複製捷徑"
再到 putty 畫面輸入 bittorrent-console --save_in /tmp/ "(把 URL 貼進這裡)"
整個就像:
bittorrent-console --save_in /tmp/ "http://xx.../file=4%d0%a1..."

Posted by: Jamyy at 2007年11月08日 14:50

Hi Jamyy,

沒想到這麼快就有回覆,
我想是我沒說清楚問題,
我是用bittorrent-console去下載一個英文檔名的.torrent,
這個torrent檔內包了數個中文檔,所以在指令輸入的部份沒有問題,有問題的是在bt開始下載後會出現錯誤,不知你有沒有發生一樣的問題.

Posted by: davy at 2007年11月13日 10:14

davy 您好,

請提供您所說的種子路徑, 我再來試試看, 謝謝

Posted by: Jamyy at 2007年11月13日 10:24

Hi Jamyy,

種子是我自己做的,用utorrent(xp)做的,隨便包個中文檔案,然後將torrent改成英文檔名,在執行後,bittorrent-console出現錯誤,錯誤訊息"Failed to start torrent"

Posted by: davy at 2007年11月13日 13:44

davy 您好,

這應該是操作上的問題, 以下是我的實驗結果:

1. 在 µTorrent 畫面點選: File → Create New Torrent
2. 選擇要建立種子的中文檔名檔案, 並勾選 "Start seeding", 然後在 "Trackers" 填入 Web Server 的資料, 例如: http://your.web.server:6969/announce
3. 按下 "Create and save as..."
4. 隨便存一個中文檔名.torrent
5. 將這個 .torrent 檔案複製到 Web Server 的根目錄, 並將檔名改成英文 (Web Server 那台記得先執行 bittorrent-tracker)
6. 使用 bittorrent-console 下載那個 .torrent, 成功

Posted by: Jamyy at 2007年11月13日 17:32

Hi Jamyy,

可以下載了,可能是我改了source code改壞掉的關係..^^|

另外你在下載包含中文檔名的torrent時,下載完成的中文檔案會不會變成 "%D0%A1%E5" 這種檔名..

Posted by: davy at 2007年11月13日 17:58

davy 您好,

我下載的中文檔名都是正常的, 我的 LANG=zh_TW.UTF-8

Posted by: Jamyy at 2007年11月13日 18:13