ubuntu 下搭建BT下载服务器
简介
使用 bittorrent + nginx + 脚本实现自动化的BT服务端
目录:/data
文件目录:/data/resource
web目录:/data/wwwroot
域名:
track.xxx.com # track 服务域名
bt.xxx.com #bt 的web服务域名
第一步、下载bt服务端
apt install bittorrent
安装完成后,会有如下程序列表
btcompletedir
btcompletedir.bittorrent
btdownloadcurses
btdownloadcurses.bittorrent
btdownloadheadless
btdownloadheadless.bittorrent
btlaunchmany
btlaunchmany.bittorrent
btlaunchmanycurses
btlaunchmanycurses.bittorrent
btmakemetafile # bt下载服务
btmakemetafile.bittorrent
btreannounce
btreannounce.bittorrent
btrename
btrename.bittorrent
btshowmetainfo
btshowmetainfo.bittorrent
bttrack # tracker 服务
bttrack.bittorrent
第二步、开启Tracker服务
# 开启track服务的目的在于,跟踪种子信息
bttrack --port 26001 --dfile dstate>/dev/null 2>&1 &
第三步、安装/配置nginx
apt install nginx
vim /etc/nginx/conf.d/bt.conf
server {
listen 80;
server_name bt.xxx.com;
root /data/wwwroot;
index index.html index.htm;
location / {
autoindex on;
autoindex_exact_size off;
autoindex_localtime on;
try_files $uri $uri/ =404;
}
}
#重启使配置生效
service nginx restart
第四步、启动/测试下载服务
#制作种子
btmakemetafile /data/wget http://track.xxx.com:26001/announce
#启动种子下载服务
btdownloadheadless --url http://bt.xxx.com/wget.torrent --saveas /data/resource/wget
#下载服务启动后会读取文件完成后提示 percent done: 100 并不断刷新
#此时下载 http://bt.xxx.com/wget.torrent 在客户端进行下载即可正常下载
第五步、脚本化处理
#!/bin/bash
BT_BIN="/usr/bin"
# track 配置
TRACK_PORT=6969
TRACK_DFILE_PATH="/data/dstate"
TRACK_LOG_FILE_PATH="/data/logs/track.log"
# 资源文件夹
RESOURCE_DIR="/data/resource"
RESOURCE_LOG_FILE_PATH="/data/logs/resource.log"
# 种子配置
DOMAIN="http://track.xxx.com:6969/announce"
BTSEED_DIR=/data/wwwroot
track_start() {
${BT_BIN}/bttrack --port ${TRACK_PORT} --dfile ${TRACK_DFILE_PATH}>${TRACK_LOG_FILE_PATH} 2>&1 &
}
download_start() {
${BT_BIN}/btlaunchmany ${RESOURCE_DIR}>${RESOURCE_LOG_FILE_PATH} 2>&1 &
}
update_torrent() {
NUMBER=`ls $RESOURCE_DIR |grep -v resume |grep -v metainfo | grep -v ".torrent"|wc -l`
CONTENT=`ls $RESOURCE_DIR |grep -v resume |grep -v metainfo | grep -v ".torrent" > /tmp/1.txt`
for (( i=1; i<=$NUMBER; i=i+1 ))
do
FILE=`sed -n "$i"p /tmp/1.txt`
if [ ! -f $BTSEED_DIR/$FILE.torrent ] ;then
${BT_BIN}/btmakemetafile ${RESOURCE_DIR}/$FILE ${DOMAIN}
/bin/cp $RESOURCE_DIR/$FILE.torrent $BTSEED_DIR
fi
done
}
case "$1" in
up)
update_torrent
;;
start)
track_start
download_start
;;
stop)
ps -ef |grep /usr/bin/bt | grep -v "grep" |awk '{print $2}'| xargs kill -9
;;
esac