Docker自建Syncthing发现及中继服务器
本文最后更新于 5 天前,其中的信息可能已经过时,如有 错误/失效 请发送邮件到qimeng9420@foxmail.com或留言。

背景引入

Syncthing是开源的文件同步程序,利用Syncthing项目的服务器,可以在多台计算机之间同步文件。具体分布可以查看Syncthing项目的中继服务器的分布

但为了提高文件同步的效率,我们可以通过自建发现服务器(discovery-server)和中继服务器(relay-server)的方法。

发现服务器:用于发现互联网上的同伴

Syncthing relies on a discovery server to find peers on the internet.

中继服务器:当双方无法直接建立数据连接时,才会利用中继服务器进行数据连接,若用中继服务器进行连接,则流量会流过服务器

Relaying is enabled by default but will only be used if two devices are unable to communicate directly with each other. When connected via a relay, Syncthing will periodically retry a direct connection and, if one is established, stop communicating via the relay.

docker部署发现服务器和中继服务器

docker-compose.yml

version: "3"
services:
  # 自建syncthing的发现服务器 syncthing-discovery-server
  syncthing_discovery_server:
    image: syncthing/discosrv:latest
    container_name: syncthing-discovery-server
    command: --debug --listen=":8443"
    environment:
      - PUID=1000
      - PGID=1000
    volumes:
      - ./syncthing/discosrv:/var/stdiscosrv
    ports:
      - 8443:8443 # 数据监听的端口 (默认为:8443)
    restart: always

  # 自建syncthing的中继服务器 syncthing-relay-server
  syncthing_relay_server:
    image: syncthing/relaysrv:latest
    container_name: syncthing-relay-server
    command: -debug -pools="" -listen=":22067"
    environment:
      - PUID=1000
      - PGID=1000
    volumes:
      - ./syncthing/strelaysrv:/var/strelaysrv
    ports:
      - 22067:22067  # 中继服务器的数据连接端口(必须开启)
      #- 22070:22070  # 用于公用的中继服务器池,显示数据传输、客户端数量等状态,可不开启
    restart: always

command命令的配置部分说明:

-debug:表示启动debug输出(建议开启)
-listen:表示数据监听的端口,默认为:8443
-pools:加入的中继服务器池,若为空,则表示该为个人私有,不允许其他人使用该中继服务(建议为空)

- GLOBAL_RATE=100000000 # 全局速率限制 单位为bytes/s
- PER_SESSION_RATE=10000000 # 每个会话速率限制 单位为bytes/s
- MESSAGE_TIMEOUT=1m30s #等待相关消息到达的最长时间
- NATWORK_TIMEOUT=3m0s # 客户端和中继服务器之间的操作超时时间
- PING_INTERVAL=1m30s # ping的发送频率

启动服务

将上述内容保存为 docker-compose.yml 文件,然后在该文件所在的目录下运行以下命令启动服务:

docker-compose up -d

在服务器防火墙放行相对应的端口,此处放行所有的port端口,即8443,22067端口

建好后,发现服务器和中继服务器各自会生成device ID,同时,会生成自签名的证书和数据库。

Every device is identified by a device ID. The device ID is used for address resolution, authentication and authorization. The term “device ID” could interchangeably have been “key ID” since the device ID is a direct property of the public key in use.At first start, stdiscosrv will generate certificate files and database in the current directory

At first start, stdiscosrv will generate certificate files and database in the current directory

查看服务状态

启动后,可以通过以下命令查看服务状态和日志:

docker-compose ps
docker-compose logs syncthing_discovery_server
docker-compose logs syncthing_relay_server

查看服务日志

运行以下命令查看发现服务器的日志:

docker-compose logs syncthing_discovery_server

运行以下命令查看中继服务器的日志:

docker-compose logs syncthing_relay_server

配置客户端

在 Syncthing 客户端中,需要将自建的发现服务器和中继服务器的地址添加到配置中:

  • 发现服务器

    https://<服务器IP>:8443/?id=<发现服务器ID>

    推荐写成:

    default,https://公网IP:8443/?id=自建发现服务器device ID

    default等价于https://discovery-v4.syncthing.net/v2/, https://discovery-v6.syncthing.net/v2/https://discovery.syncthing.net/v2/也就是利用Syncthing项目的发现服务

  • 中继服务器

    relay://<服务器IP>:22067?id=<中继服务器ID>

    推荐写成:

    default,relay://公网IP:22067/?id=自建中继服务器device ID

    default等价于tcp://0.0.0.0:22000, quic://0.0.0.0:22000dynamic+https://relays.syncthing.net/endpoint.同样也是利用Syncthing项目的发现服务 的中继服务

如果觉得本文对您有帮助,可以支持下博主,谢谢啦!!!

留言板 | 博客主页
暂无评论

发送评论 编辑评论


|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
上一篇