通过网络分享资源,是为了让人下载,但由于种种原因,放到商业网盘的资源经常会被删除,于是我只好自建简易的http文件下载服务,比如frp.v2fy.com
[外链图片转存中…(img-XUIqiXwK-1672121846415)]
内网穿透搭建http文件下载服务教程 https://www.v2fy.com/p/2021-10-01-pi-server-1633066843000/
但http文件下载服务的流量成本是很高的,用户下载的数据都要通过服务器,下载的人一多,下载的速度就会非常慢,那么有没有一种方法,下载的人越多,下载速度越快呢?
当然是有的,我们可以制作一个bt种子,然后使用固定IP的服务器生成种子,并保持做种,这样使用种子下载的用户,彼此之间就可以直接交换数据,下载的用户越多,下载速度就越快。
我选的24元每月的香港阿里云 https://common-buy.aliyun.com/?commodityCode=swas®ionId=cn-hongkong
这里建议每次购买一个月,如果某个月IP出了问题,下个月直接换主机。
小技巧:为了避免记ip, 我用子域名hk.v2fy.com直接解析绑定了主机IP, 方便ssh登陆主机
推荐一波ssh连接服务器的软件FinalShell https://www.hostbuf.com/t/988.html, 特色是ssh登陆主机后,支持实时查看服务状态, 支持本地文件拖拽上传到服务器(相当于sftp),非常方便文件管理。
[外链图片转存中…(img-ESOJkpku-1672121846415)]
sudo apt update
# 安装 transmission ;transmission包含三个子包; transmission-show(查看种子信息) transmission-create(创建种子) transmission-edit(编辑种子)
sudo apt install transmission -y
# 安装 transmission-cli; transmission-cli 为客户端,支持做种seeding
sudo apt install transmission-cli -y
# 安装transmission-daemon;transmission-daemon 支持开机后台启动,守护transmission运行
sudo apt install transmission-daemon -y
# 查看是否安装成功
transmission-show --version
transmission-create --version
transmission-edit --version
transmission-cli --version
transmission-daemon --version
[外链图片转存中…(img-nLO3AMSh-1672121846416)]
sudo cat /var/lib/transmission-daemon/info/settings.json
{
"alt-speed-down": 50,
"alt-speed-enabled": false,
"alt-speed-time-begin": 540,
"alt-speed-time-day": 127,
"alt-speed-time-enabled": false,
"alt-speed-time-end": 1020,
"alt-speed-up": 50,
"bind-address-ipv4": "0.0.0.0",
"bind-address-ipv6": "::",
"blocklist-enabled": false,
"blocklist-url": "http://www.example.com/blocklist",
"cache-size-mb": 4,
"dht-enabled": true,
"download-dir": "/var/lib/transmission-daemon/downloads",
"download-limit": 100,
"download-limit-enabled": 0,
"download-queue-enabled": true,
"download-queue-size": 5,
"encryption": 1,
"idle-seeding-limit": 30,
"idle-seeding-limit-enabled": false,
"incomplete-dir": "/var/lib/transmission-daemon/Downloads",
"incomplete-dir-enabled": false,
"lpd-enabled": false,
"max-peers-global": 200,
"message-level": 1,
"peer-congestion-algorithm": "",
"peer-id-ttl-hours": 6,
"peer-limit-global": 200,
"peer-limit-per-torrent": 50,
"peer-port": 51413,
"peer-port-random-high": 65535,
"peer-port-random-low": 49152,
"peer-port-random-on-start": false,
"peer-socket-tos": "default",
"pex-enabled": true,
"port-forwarding-enabled": false,
"preallocation": 1,
"prefetch-enabled": true,
"queue-stalled-enabled": true,
"queue-stalled-minutes": 30,
"ratio-limit": 2,
"ratio-limit-enabled": false,
"rename-partial-files": true,
"rpc-authentication-required": true,
"rpc-bind-address": "0.0.0.0",
"rpc-enabled": true,
"rpc-host-whitelist": "",
"rpc-host-whitelist-enabled": true,
"rpc-password": "{de9da53fcab4b2c6219f143c8b19ae505e614256rmsFzRvZ",
"rpc-port": 9091,
"rpc-url": "/transmission/",
"rpc-username": "transmission",
"rpc-whitelist": "127.0.0.1",
"rpc-whitelist-enabled": true,
"scrape-paused-torrents-enabled": true,
"script-torrent-done-enabled": false,
"script-torrent-done-filename": "",
"seed-queue-enabled": false,
"seed-queue-size": 10,
"speed-limit-down": 100,
"speed-limit-down-enabled": false,
"speed-limit-up": 100,
"speed-limit-up-enabled": false,
"start-added-torrents": true,
"trash-original-torrent-files": false,
"umask": 18,
"upload-limit": 100,
"upload-limit-enabled": 0,
"upload-slots-per-torrent": 14,
"utp-enabled": true
}
从download-dir
可知默认下载路径为 /var/lib/transmission-daemon/downloads
如果我们把bt种子和对应的文件都放在/var/lib/transmission-daemon/downloads
目录,则transmission会进行持续做种(按照BT协议,客户端会在下载的同时,进行上传,如果下载完成,依然可以将下载好的资源上传给其它用户,供其它用户下载,我们将这种文件下载完成后,持续上传给其它用户的行为称为做种,只要做种的人足够多,资源下载就会很快)。
/var/lib/transmission-daemon/downloads
目录为避免目录权限不足,上传失败,我们运行命令,让目录支持读写
sudo chmod 755 -R /var/lib/transmission-daemon/downloads/
上传资源
[外链图片转存中…(img-5HmBbanc-1672121846416)]
上传成功
[外链图片转存中…(img-CqPQm6S1-1672121846416)]
通过以下命令,可以为 /var/lib/transmission-daemon/downloads/macOS龙神Switch模拟器.zip 文件生成了种子,生成种子的位置在文件同级目录下,种子名为 macOS龙神Switch模拟器.torrent
transmission-create -s 2048 -t http://1337.abcvg.info:80/announce -t http://bt.okmp3.ru:2710/announce -t http://bz.tracker.bz:80/announce -t http://fxtt.ru:80/announce -t http://nyaa.tracker.wf:7777/announce -t http://open.acgnxtracker.com:80/announce -t http://p2p.0g.cx:6969/announce -t udp://v1046920.hosted-by-vdsina.ru:6969/announce -t udp://v2.iperson.xyz:6969/announce -t udp://vibe.sleepyinternetfun.xyz:1738/announce -t udp://www.torrent.eu.org:451/announce -t http://frp.v2fy.com:8000/announce -o /var/lib/transmission-daemon/downloads/macOS龙神Switch模拟器.torrent /var/lib/transmission-daemon/downloads/macOS龙神Switch模拟器.zip
所谓种子,就是包含了文件哈希值的记录文件,不同的文件的哈希值是不同的,下载文件的哈希值相同,那下载的文件也会是同一份。另外种子还会包含Tracker服务器的信息,Tracker服务器并不存储文件,只是为用户之间进行信息交换提供沟通渠道。
我们可以使用transmission-show查看种子内容
transmission-show /var/lib/transmission-daemon/downloads/macOS龙神Switch模拟器.torrent
得到的内容如下,包含12个traker服务器地址,以及文件名文件大小和哈希值
Name: macOS龙神Switch模拟器.zip
File: macOS龙神Switch模拟器.torrent
GENERAL
Name: macOS龙神Switch模拟器.zip
Hash: cb0eedb23ff16a0693d5c27356bd262e8a21c9b5
Created by: Transmission/2.94 (d8e60ee44f)
Created on: Sun Dec 25 15:21:58 2022
Piece Count: 199
Piece Size: 2.00 MiB
Total Size: 416.0 MB
Privacy: Public torrent
TRACKERS
Tier #1
http://1337.abcvg.info:80/announce
Tier #2
http://bt.okmp3.ru:2710/announce
Tier #3
http://bz.tracker.bz:80/announce
Tier #4
http://fxtt.ru:80/announce
Tier #5
http://nyaa.tracker.wf:7777/announce
Tier #6
http://open.acgnxtracker.com:80/announce
Tier #7
http://p2p.0g.cx:6969/announce
Tier #8
udp://v1046920.hosted-by-vdsina.ru:6969/announce
Tier #9
udp://v2.iperson.xyz:6969/announce
Tier #10
udp://vibe.sleepyinternetfun.xyz:1738/announce
Tier #11
udp://www.torrent.eu.org:451/announce
Tier #12
http://frp.v2fy.com:8000/announce
FILES
macOS龙神Switch模拟器.zip (416.0 MB)
如果需要更多稳定的Tracker,可以查看开源项目 https://github.com/XIU2/TrackersListCollection
接下来我们配置transmission-deamon ,使其可以自动监听 /var/lib/transmission-daemon/downloads/
目录,当目录内存在文件时,则自动做种
首先保证关闭transmission-daemon
sudo systemctl stop transmission-daemon.service
然后修改settings.json
vim /var/lib/transmission-daemon/info/settings.json
在settings.json末尾添加
"watch-dir": "/var/lib/transmission-daemon/downloads",
"watch-dir-enabled": true
设置downloads目录权限
sudo chmod 777 -R /var/lib/transmission-daemon/downloads
启动transmission-daemon
sudo systemctl start transmission-daemon.service
查看transmission-daemon状态
sudo systemctl status transmission-daemon
在 /etc/sysctl.conf
追加
net.core.rmem_max = 16777216
net.core.wmem_max = 4194304
然后运行sysctl -p
[外链图片转存中…(img-saYZTMcd-1672121846416)]
然后重启transmission-daemon 查看状态即可
sudo systemctl restart transmission-daemon.service
sudo systemctl status transmission-daemon
[外链图片转存中…(img-aRI74sQf-1672121846417)]
进入云服务器后台,开放几个端口
以上几个端口为transmission-daemon默认配置
"rpc-port": 9091,
"peer-port": 51413,
"peer-port-random-high": 65535,
"peer-port-random-low": 49152,
其中 49152-65535端口端,包含了51413,所以51413可以不单独配置开启,这里为了做演示,所以多加了51413端口开启的配置。
此刻我们将macOS龙神Switch模拟器.torrent.added
下载到本地, 移除 .added
后缀,将macOS龙神Switch模拟器.torrent
添加到BT种子下载软件,比如 qBittorrent ,即可开始BT资源下载
为了保证服务器重启后,依然自动做种,我们需要将 transmission-daemon 设置为开机启动项
sudo systemctl enable transmission-daemon.service
如果你不需要Web界面,我们的教程就到此结束了,如果需要一个Web界面,查看当前做种的状态,还需要看教程(继续调教transmission-deamon)。
当前我们未做rpc的配置,所以直接访问 9091 端口会直接403
# 关闭transmission-daemon
sudo systemctl stop transmission-daemon.service
sudo vim /var/lib/transmission-daemon/info/settings.json
"rpc-whitelist-enabled": false,
浏览器访问9091端口,需要输入用户名密码
默认用户名和密码都为 transmission
如果需要修改默认用户名密码, 关闭transmission-daemon, 修改settings.json 中的 rpc-password 和 rpc-username即可
sudo vim /var/lib/transmission-daemon/info/settings.json
"rpc-password": "新密码",
"rpc-username": "新用户名",
修改完成后,记得重启开启
sudo systemctl start transmission-daemon.service
至此,固定IP的服务器BT做种折腾完成。
BT技术特色是去中心化,只要有人做种,就能保证文件在互联网存活,文件留个备份,换个服务器,依然可以继续做种。
为了便于分发我们可以通过 https://nutbread.github.io/t2m/ (工具开源地址: https://github.com/nutbread/t2m)将BT种子在线转为磁力链接
转换后的磁力链接为(相当于把BT种子内的有效信息转换为字符串):
magnet:?xt=urn:btih:ZMHO3MR76FVANE6VYJZVNPJGF2FCDSNV&dn=macOS%E9%BE%99%E7%A5%9ESwitch%E6%A8%A1%E6%8B%9F%E5%99%A8.zip&xl=416012391&tr.1=http%3A%2F%2F1337.abcvg.info%3A80%2Fannounce&tr.2=http%3A%2F%2F1337.abcvg.info%3A80%2Fannounce&tr.3=http%3A%2F%2Fbt.okmp3.ru%3A2710%2Fannounce&tr.4=http%3A%2F%2Fbz.tracker.bz%3A80%2Fannounce&tr.5=http%3A%2F%2Ffxtt.ru%3A80%2Fannounce&tr.6=http%3A%2F%2Fnyaa.tracker.wf%3A7777%2Fannounce&tr.7=http%3A%2F%2Fopen.acgnxtracker.com%3A80%2Fannounce&tr.8=http%3A%2F%2Fp2p.0g.cx%3A6969%2Fannounce&tr.9=udp%3A%2F%2Fv1046920.hosted-by-vdsina.ru%3A6969%2Fannounce&tr.10=udp%3A%2F%2Fv2.iperson.xyz%3A6969%2Fannounce&tr.11=udp%3A%2F%2Fvibe.sleepyinternetfun.xyz%3A1738%2Fannounce&tr.12=udp%3A%2F%2Fwww.torrent.eu.org%3A451%2Fannounce&tr.13=http%3A%2F%2Ffrp.v2fy.com%3A8000%2Fannounce
BT做种本是一件很简单的事,但由于中国用户缺少IPV4的固定IP, 所以门槛抬高了,BT是一项很有互联共享精神的技术,人人为我,我为人人,我们只需付出极低的服务器成本,就可以搭建一套分发大型文件的服务,可以称得上是对抗无良网盘的优秀技术。
https://www.v2fy.com/p/2022-12-25-bt-1671963832000