设为首页收藏本站

ZMX - IT技术交流论坛 - 无限Perfect,追求梦想 - itzmx.com

 找回密码
 注册论坛

QQ登录

只需一步,快速开始

新浪微博账号登陆

只需一步,快速开始

用百度帐号登录

只需两步,快速登录

搜索
查看: 6824|回复: 2

一个linux vps中用C做的开源和免费的高性能BitTorrent Tracker通讯服务器 (OpenTracker中文教程)

[复制链接]
 成长值: 75

签到天数: 4486 天

[LV.Master]伴坛终老

发表于 2017/8/12 03:33 | 显示全部楼层 |阅读模式 |Google Chrome 60.0.3112.90|Windows 10
天涯海角搜一下: 百度 谷歌 360 搜狗 有道 雅虎 必应 即刻
[OpenTracker](https://erdgeist.org/arts/software/opentracker/)
=======

-------
That should leave you with an exectuable called opentracker and one debug version opentracker.debug.

Some variables in opentracker's Makefile control features and behaviour of opentracker. Here they are:

-DWANT_V6 makes opentracker an IPv6-only tracker. More in the v6-section below.
opentracker can deliver gzip compressed full scrapes. Enable this with -DWANT_COMPRESSION_GZIP option.
Normally opentracker tracks any torrent announced to it. You can change that behaviour by enabling ONE of -DWANT_ACCESSLIST_BLACK or  -DWANT_ACCESSLIST_WHITE. Note, that you have to provide a whitelist file in order to make opentracker do anything in the latter case. More in the closed mode section below.
opentracker can run in a cluster. Enable this behaviour by enabling -DWANT_SYNC_LIVE. Note, that you have to configure your cluster before you can use opentracker when this option is on.
Some statistics opentracker can provide are sensitive. You can restrict access to these statistics by enabling -DWANT_RESTRICT_STATS. See section statistics for more details.
Fullscrapes is bittorrent's way to query a tracker for all tracked torrents. Since it's in the standard, it is enabled by default. Disable it by commenting out -DWANT_FULLSCRAPE.
By default opentracker will only allow the connecting endpoint's IP address to be announced. Bittorrent standard allows clients to provide an IP address in its query string. You can make opentracker use this IP address by enabling -DWANT_IP_FROM_QUERY_STRING.
Some experimental or older, deprecated features can be enabled by the -DWANT_LOG_NETWORKS, -DWANT_SYNC_SCRAPE or -DWANT_IP_FROM_PROXY switch.
Currently there is some packages for some linux distributions and OpenBSD around, but some of them patch Makefile and default config to make opentracker closed by default. I explicitly don't endorse those packages and will not give support for problems stemming from these missconfigurations.


-------
Invocation
opentracker can be run by just typing ./opentracker. This will make opentracker bind to 0.0.0.0:6969 and happily serve all torrents presented to it. If ran as root, opentracker will immediately chroot to . (or any directory given with the -d option) and drop all priviliges after binding to whatever tcp or udp ports it is requested.

When options were few, opentracker used to accept all of them from command line. While this still is possible for most options, using them is quite unhandy: an example invocation would look like ./opentracker -i 23.23.23.7 -p 80 -P 80 -p 6969 -i 23.23.23.8 -p 80 -r http://www.mytorrentsite.com/ -d /usr/local/etc/opentracker -w mytorrents.list -A 127.0.0.1.

opentracker now uses a config file that you can provide with the -f switch.


-------
Config file
opentracker's config file is very straight forward and a very well documented example config can be found in the file opentracker.conf.sample.


-------
Closed mode
While personally I like my tracker to be open, I can see that there's people that want to control what torrents to track – or not to track. If you've compiled opentracker with one of the accesslist-options (see Build instructions above), you can control which torrents are tracked by providing a file that contains a list of human readable info_hashes. An example whitelist file would look like

0123456789abcdef0123456789abcdef01234567
890123456789abcdef0123456789abcdef012345
To make opentracker reload it's white/blacklist, send a SIGHUP unix signal.


-------
Statistics
Given its very network centric approach, talking to opentracker via http comes very naturally. Besides the /announce and /scrape paths, there is a third path you can access the tracker by: /stats. This request takes parameters, for a quick overview just inquire /stats?mode=everything`.

Statistics have grown over time and are currently not very tidied up. Most modes were written to dump legacy-SNMP-style blocks that can easily be monitored by MRTG. These modes are: peer, conn, scrp, udp4, tcp4, busy, torr, fscr, completed, syncs. I'm not going to explain these here.

The statedump mode dumps non-recreatable states of the tracker so you can later reconstruct an opentracker session with the -l option. This is beta and wildly undocumented.

You can inquire opentracker's version (i.e. CVS versions of all its objects) using the version mode.


下面中文的,方便讲解使用
Centos 6.9 x64位安装说明
  1. yum -y install unzip wget gcc zlib-devel make
  2. wget https://github.com/1265578519/OpenTracker/archive/master.zip -O /root/OpenTracker.zip
  3. unzip OpenTracker.zip
  4. mv OpenTracker-master /home
  5. cd /home
  6. cd OpenTracker-master
  7. cd libowfat
  8. make
  9. cd /home/OpenTracker-master
  10. cd opentracker
  11. make
复制代码



运行程序,并且监听tcp和udp端口的8080,并且自动后台工作
  1. ./opentracker -p 8080 -P 8080 &
复制代码


推荐使用8080端口,基本上免备案不会扫描,而且CloudFlare也支持使用CDN隐藏IP来使用。

多端口可以加多个即可
  1. ./opentracker -p 8080 -P 8080 -p 6961 -P 6961 -p 2710 -P 2710 &
复制代码


添加开机启动,执行一次即可,否则会启动多个进程。。。可以搭配下方的计划任务自动重启进程,如果centos 7未有killall命令可以用 yum -y install psmisc 安装,centos7要赋予开机启动文件执行权限 chmod +x /etc/rc.d/rc.local;ll /etc/rc.d/rc.local
  1. echo "cd /home/OpenTracker-master;cd opentracker;./opentracker -p 8080 -P 8080 -p 6961 -P 6961 -p 2710 -P 2710 &" >> /etc/rc.d/rc.local
复制代码


输入下方命令可以查看是否在工作中
  1. top -b -n 1 |grep opentracker
复制代码


查看进程当前并发连接数
  1. netstat -apn|grep opentracker |wc -l
复制代码


查看系统当前网络情况
  1. netstat -n | awk '/^tcp/ {++S[$NF]} END {for(a in S) print a, S[a]}'
复制代码


通过浏览器访问程序的统计功能
  1. http://ip:8080/stats
  2. http://ip:8080/stats?mode=everything
  3. http://ip:8080/stats?mode=top100
  4. http://ip:8080/scrape
复制代码


服务器里面可以
  1. curl http://localhost:8080/stats
复制代码


运行crontab -e
可以根据需要使用计划任务自动重启进程,下方意思,每天0点、4点、8点、12点、16点、20点整,自动重启进程。
  1. 0 0,4,8,12,16,20 * * * killall -9 opentracker;sleep 3;cd /home/OpenTracker-master;cd opentracker;./opentracker -p 8080 -P 8080 -p 6961 -P 6961 -p 2710 -P 2710 &
复制代码


方法二
使用计划任务自动监控进程是否存在然后重启恢复,不进行定时重启
  1. * * * * * /sbin/pidof opentracker||{ cd /home/OpenTracker-master;cd opentracker;./opentracker -p 8080 -P 8080 -p 6961 -P 6961 -p 2710 -P 2710 &}
复制代码


软件的自带帮助说明
Usage: ./opentracker [-i ip] [-p port] [-P port] [-r redirect] [-d dir] [-u user] [-A ip] [-f config] [-s livesyncport]
        -f config include and execute the config file
        -i ip     specify ip to bind to (default: *, you may specify more than one)
        -p port   specify tcp port to bind to (default: 6969, you may specify more than one)
        -P port   specify udp port to bind to (default: 6969, you may specify more than one)
        -r redirecturlspecify url where / should be redirected to (default none)
        -d dir    specify directory to try to chroot to (default: ".")
        -u user   specify user under whose priviliges opentracker should run (default: "nobody")
        -A ip     bless an ip address as admin address (e.g. to allow syncs from this address)

Example:   ./opentracker -i 127.0.0.1 -p 6969 -P 6969 -f ./opentracker.conf -i 10.1.1.23 -p 2710 -p 80



间隔可以在编译前进行修改,默认我改成了2小时,以便降低服务器宽带开销
trackerlogic.h:#define OT_CLIENT_TIMEOUT_SEND (60*15)#(60*30),客户端最小间隔请求时间,客户端可能不会遵守
trackerlogic.h:#define OT_CLIENT_REQUEST_INTERVAL (60*30)#(60*120),客户端默认间隔请求时间
trackerlogic.h:#define OT_CLIENT_REQUEST_VARIATION (60*6),服务端下发随机客户端间隔请求时间调整,提高性能,默认允许误差随机6分钟内,保持默认无修改
trackerlogic.h:#define OT_PEER_TIMEOUT 45#180,服务端删除peer时间,单位分钟


utorrent中制作种子过程tracker写
http://服务器ip:8080/announce

udp://服务器ip:8080/announce


我用这个在线八千多万用户还算很稳定
间隔2h,内存占用也才60多M。
1.png
2.jpg


-------
程序来自官网
https://erdgeist.org/arts/software/opentracker/
mail:erdgeist@erdgeist.org


已知BUG,开机后占用满一个核心99CPU,需要killall杀死进程重新启用进程即可,不知道什么原理所以建议计划任务一下。
而且这也是个单线程软件,,没办法利用多CPU,同时Fullscrape有BUG会产生内存泄漏,本贴教程已优化默认关闭此功能。
https://bbs.itzmx.com/thread-101068-1-1.html

有人可能会同时做种上千个任务 同一ip一瞬间的高请求是正常的,opentracker会返回下次随机间隔6分钟时间,客户端持续运行的时候,会把请求错开,主要高峰就是在启动全部任务的时候。基本很多人都是挂上千个任务的,所以一秒20次是很正常的啦
scrape作用不大,在连接tracekr之前查询服务器状态,目前只有几个少数客户端支持,而且产生full scrape时候会产生较大的内存,小机器内存不建议提供full scrape,甚至可以阻断整个scrape页面,关闭scrape不会影响tracker的正常运行,关闭full scrape需要源码重新编译
关于上面说的,主要就是这个Fullscrape,要关掉,不然消耗内存
QQ图片20230418204914.png

推荐Tracker服务器购买优惠注册地址:
https://www.vultr.com/?ref=6813695

注:2024年2月27日更新一次版本代码改动
centos6仅支持libowfat 0.31,centos7仅支持libowfat 0.32,请使用对应系统的版本编译opentracker,上方提供的安装代码当前版本为libowfat0.32
centos6在使用 cd libowfat 进入目录的上方插入并且运行这段代码
  1. rm -rf libowfat;mv libowfat-0.31 libowfat
复制代码


2024年3月6日
已知stats页面会导致空指针bug引起进程崩溃,并且这个stats页面访问时占用cpu也比较高,不带参数访问可能卡出BUG输出top的内容
可以考虑启用DWANT_RESTRICT_STATS 来关闭stats功能,正在尝试修复源代码,等会看看崩不崩溃吧

2024年3月16日
访问stats页面导致触发的崩溃问题已修复,原因是idx的问题,同时修复了stats_top_txt函数导致高cpu占用
总结:问题是有人拿top100的链接当tracker用,导致每分钟触发访问几十次top100页面,然后崩溃,崩溃问题修复了,现在也禁止这类异常访问用

2024年4月7日
完美版,修复崩溃(这里的崩溃指的是bep15 beta版本中clean代码发生的崩溃),支持bep15,udp实现ipv4与ipv6分离,使用bt协议规范开发避免udp响应错误ip地址(先用ipv6请求然后在用ipv4请求会响应3倍的错误数据包引起的bug,现已使用bep15修复),http保持原样,支持组合同时响应列表

2024年4月11日
这次是真的完美版,udp返回ipv4+ipv6所有数据显示,peer依旧按照bep15分别不同列表返回,修复stats?mode=everything触发8192字节崩溃,OT_STATS_TMPSIZE 8KB限制引发的崩溃改成智能化检测 OT_PEER_TIMEOUT

评分

参与人数 1樱币 +2 收起 理由
仁二 + 2 樱酱!厉害!我学会了

查看全部评分

欢迎光临IT技术交流论坛:http://bbs.itzmx.com/
回复

使用道具 举报

 成长值: 75

签到天数: 4486 天

[LV.Master]伴坛终老

发表于 2018/1/22 03:31 | 显示全部楼层 |Google Chrome 63.0.3239.132|Windows 10
A max number of peer user.
can be add to limit the memory usage of the process.

1500w peer, process 2GB memory. I want to limit no more than 300w peer. Reduce memory usage.

11.png

100w peer大约进程占用85MB内存
欢迎光临IT技术交流论坛:http://bbs.itzmx.com/
回复 支持 反对

使用道具 举报

 成长值: 75

签到天数: 4486 天

[LV.Master]伴坛终老

发表于 2019/4/18 02:51 | 显示全部楼层 |Google Chrome 73.0.3683.103|Windows 10
如何返回所有peer不受客户端numwant控制
You cant. You have to disable in ot_http.c:446
      if( numwant < 0 ) numwant = 50;
      if( numwant > 200 ) numwant = 200;

so that all larger values of numwant are allowed.

比如改成
      if( numwant < 0 ) numwant = 1200;
      if( numwant > 0 ) numwant = 1200;

同时还有411行不包含参数时候的默认返回值,numwant = 50;


ot_udp.c的话同理,但是对于numwant赋予设置值不要超过1200,超过运行软件会进程崩溃。
if (numwant > 200) numwant = 200;

改成
if (numwant > 0) numwant = 1200;

如果安装软件同时开启ipv4和ipv6时,本软件极限承受能力则不应该大于400(程序最大支持8KB输出,400*18=7.2KB)

注,启用ipv6编译会导致服务器宽带消耗三倍,如果不需要请在 Makefile 文件中编辑加#注释掉
#FEATURES+=-DWANT_V6

ipv4模式时,单用户6字节
ipv4与ipv6模式时,单用户18字节

[发帖际遇]: 小樱 乐于助人,奖励 1 贡献. 幸运榜 / 衰神榜
欢迎光临IT技术交流论坛:http://bbs.itzmx.com/
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册论坛 新浪微博账号登陆用百度帐号登录

本版积分规则

手机版|Archiver|Mail me|网站地图|IT技术交流论坛 ( 闽ICP备13013206号-7 )

GMT+8, 2024/4/16 17:19 , Processed in 0.151257 second(s), 23 queries , MemCache On.

Powered by itzmx! X3.4

© 2011- sakura

快速回复 返回顶部 返回列表