BT是BitTorrent(比特流)的简称,BT的特点是用户下载的同时,也在为其它用户提供上传,所以不会像FTP服务器那样随着用户数的增加而导致下载速度降低。恰恰相反,对于BT下载而言,下载的人越多速度越快。 BT下载首先在第一个共享端(或称为Downloader)把一个文件分成N个部分,A用户可以从Downloader上随机下载第M个部分,B用户可以在Downloader服务器随机下载第K个部分。而A用户的BT客户端下载程序会根据情况从B用户下载第K个部分,同样的,B用户也可以从A用户下载第M个部分,通过这种方式减轻服务器端负荷,加快用户的下载速度, 例如,C用户直接从服务器下载,速度可能只有几Kbps,而从A、B用户处下载,速度将快很多。用户在下载的同时,也在上传文件,在享受别人提供下载服务的同时,每个用户也同时在上载并贡献自己的带宽,所以造成使用BT下载服务的人越多,大家的速度就越快。BT下载的优越性就在这里体现,下面简要介绍下BitTorrent的安装,感谢胡帅哥的精彩分享…
- 一:安装Python
- [root@jsb-ylw-5024 ~]# cd /usr/local/src/tarbag/
- [root@jsb-ylw-5024 tarbag]# wgethttp://downloads.activestate.com/ActivePython/releases/2.7.0.2/ActivePython-2.7.0.2-linux-x86_64.tar.gz
- [root@jsb-ylw-5024 tarbag]# tar -zxvf ActivePython-2.7.0.2-linux-x86_64.tar.gz -C ../software/
- [root@jsb-ylw-5024 tarbag]# cd ../software/ActivePython-2.7.0.2-linux-x86_64/
- [root@jsb-ylw-5024 ActivePython-2.7.0.2-linux-x86_64]# ./install.sh
- Enter directory in which to install ActivePython. Leave blank and
- press 'Enter' to use the default [/opt/ActivePython-2.7].
- Install directory: /usr/local/python
- ()
- Installing ActivePython to '/usr/local/python'...
- Relocating dir-dependent files...
- Pre-compiling .py files in the standard library...
- ActivePython has been successfully installed to:
- /usr/local/python
- [root@jsb-ylw-5024 ActivePython-2.7.0.2-linux-x86_64]# ls /usr/local/python/
- bin doc include lib share
- [root@jsb-ylw-5024 ~]# env |grep PATH
- PATH=/root/bin:/usr/local/mysql/bin:/usr/local/python/bin/:/usr/local/rlwarp/bin/:/usr/local/java/bin:/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/sbin:/usr/local/bin:/sbin:/
- bin:/usr/sbin:/usr/bin
- 二:下载,安装BitTorrent
- [root@jsb-ylw-5024 ~]# cd /usr/local/src/tarbag/
- [root@jsb-ylw-5024 tarbag]# wgethttp://download.bittorrent.com/dl/archive/BitTorrent-3.9.1.tar.gz
- [root@jsb-ylw-5024 tarbag]# tar -zxvf BitTorrent-3.9.1.tar.gz -C ../software
- [root@jsb-ylw-5024 tarbag]# cd ../software/BitTorrent-3.9.1
- [root@jsb-ylw-5024 BitTorrent-3.9.1]# python2.7 setup.py install
- [root@jsb-ylw-5024 BitTorrent-3.9.1]# ls /usr/local/python/bin/bt*
- /usr/local/python/bin/btdownloadcurses.py /usr/local/python/bin/btlaunchmany.py /usr/local/python/bin/btrename.py
- /usr/local/python/bin/btdownloadgui.py /usr/local/python/bin/btmaketorrentgui.py /usr/local/python/bin/btshowmetainfo.py
- /usr/local/python/bin/btdownloadheadless.py /usr/local/python/bin/btmaketorrent.py /usr/local/python/bin/bttest.py
- /usr/local/python/bin/btlaunchmanycurses.py /usr/local/python/bin/btreannounce.py /usr/local/python/bin/bttrack.py
- 三:启动BT
- [root@jsb-ylw-5024 ~]# /usr/local/python/bin/python2.7 /usr/local/python/bin/bttrack.py --port 6969 --dfile /tmp/bttrack.log &
- [1] 22603
- [root@jsb-ylw-5024 ~]# ps -ef |grep python
- root 22670 22614 1 15:32 pts/1 00:00:00 /usr/local/python/bin/python2.7 /usr/local/python/bin/bttrack.py --port 6969 --dfile /tmp/bttrack.log
- root 22679 22614 0 15:32 pts/1 00:00:00 grep python
- [root@jsb-ylw-5024 ~]# netstat -ntpl |grep 6969
- tcp 0 0 0.0.0.0:6969 0.0.0.0:* LISTEN 22670/python2.7
- 四:制作BT种子
- [root@jsb-ylw-5024 ~]# /usr/local/python/bin/btmaketorrent.pyhttp://192.168.50.24:6969/announce /root/resoucre/ubuntu.pdf
- [root@jsb-ylw-5024 ~]# mv /root/resoucre/ubuntu.pdf.torrent /www/
- [root@jsb-ylw-5024 ~]# ln /root/resoucre/ubuntu.pdf /www/
- [root@jsb-ylw-5024 ~]# ll /root/resoucre/ubuntu.pdf
- -rwxr-xr-x 2 root root 60334729 10-25 15:36 /root/resoucre/ubuntu.pdf
- [root@jsb-ylw-5024 ~]# /usr/local/python/bin/btlaunchmany.py --data_dir /root/resoucre/ --torrent_dir /www > /dev/null 2>&1 &
- [2] 23354
- [root@jsb-ylw-5024 ~]# ps -ef |grep python |grep -v 'grep'
- root 22670 22614 0 15:32 pts/1 00:00:00 /usr/local/python/bin/python2.7 /usr/local/python/bin/bttrack.py --port 6969 --dfile /tmp/bttrack.log
- root 23354 22614 0 15:42 pts/1 00:00:00 /usr/local/python/bin/python2.7 /usr/local/python/bin/btlaunchmany.py --data_dir /root/resoucre/ --torrent_dir /www
五:下载测试
- 六:自动生成种子脚本
- [root@jsb-ylw-5024 ~]# cat auto_bt_seed.sh
- #!/bin/bash
- #function: auto generate bt seed ...
- #author: lw.yang
- #version: V.1.0
- MAKEBT=/usr/local/python/bin/btmaketorrent.py
- DOMAIN=http://192.168.50.24:6969/announce
- RESOURCE_DIR=/root/resource
- BTSEED_DIR=/www
- NUMBER=`ls $RESOURCE_DIR |grep -v resume |grep -v metainfo|wc -l`
- CONTENT=`ls $RESOURCE_DIR |grep -v resume |grep -v metainfo > /tmp/1.txt`
- for (( i=1; i<=$NUMBER; ii=i+1 ))
- do
- FILE=`sed -n "$i"p /tmp/1.txt`
- if [ ! -f $BTSEED_DIR/$FILE.torrent ] ;then
- $MAKEBT $DOMAIN $RESOURCE_DIR/$FILE
- ln $RESOURCE_DIR/$FILE $BTSEED_DIR
- /bin/mv $RESOURCE_DIR/$FILE.torrent $BTSEED_DIR
- fi
- done
本文转自斩月博客51CTO博客,原文链接http://blog.51cto.com/ylw6006/458067如需转载请自行联系原作者
ylw6006