前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >【玩转Lighthouse】docker自建Syncthing的发现服务器和中继服务器

【玩转Lighthouse】docker自建Syncthing的发现服务器和中继服务器

原创
作者头像
Super2022
修改2022-04-18 10:19:35
6.4K0
修改2022-04-18 10:19:35
举报
文章被收录于专栏:小确幸

一、背景引入

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部署发现服务器和中继服务器

代码语言:javascript
复制
version: "3"
services:
    # 自建syncthing的发现服务器 discovery-servier
  syncthing_discovery_server:
    image: syncthing/discosrv
    container_name: syncthing-discovery-server
    command: -debug -listen=":8443" 
    environment:
      - PUID=1000
      - PGID=1000
    volumes:
      - ./syncthing/discosrv:/var/stdiscosrv
    ports:
      - 8443:8443 # Listen address (default “: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

sudo docker-compose up -d 运行该docker-compose文件

在Lighthouse中防火墙放行相对应的端口,此处放行所有的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

command命令的配置部分说明:

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

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

三、客户端Syncthing的设置

在每个Syncthing Client上进行设置:

绿框全部开启,红框填入对应自建服务的地址

自建服务的写法:

1. 自建发现服务器地址(写在全局发现服务器,即第二个红框处)

代码语言:javascript
复制
https://公网IP:8443/?id=自建发现服务器device ID

推荐写成:

代码语言:javascript
复制
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项目的发现服务

2. 自定义中继服务器地址(写在协议监听地址,即第一个红框处)

代码语言:javascript
复制
relay://公网IP:22067?id=自建中继服务器device ID

推荐写成:

代码语言:javascript
复制
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项目的发现服务 的中继服务

通过侦听程序设备发现的数量,可以判断客户端是否成功连接上了自建服务

关于发现服务器的https证书来源

为了安全起见,发现服务器是利用https来提供服务的。官网提到了三种证书的选择:

第一种就是用CA机构发布的证书

第二种就是自建发现服务器在建好后根据device ID自动生成的证书(推荐)

第三种就是利用反向代理

前两种证书,对应的发现服务器地址,需要传递device ID,而第三种无需传递device ID

Use a CA-signed certificate pair for the domain name you will use for the discovery server. This is like any other HTTPS website; clients will authenticate the server based on its certificate and domain name. Use any certificate pair and let clients authenticate the server based on its “device ID” (similar to Syncthing-to-Syncthing authentication). This option can be used with the certificate automatically generated by the discovery server. Pass the -http flag if the discovery server is behind an SSL-secured reverse proxy. See below for configuration.

四、两个客户端Syncthing进行同步

两个客户端在进行连接前,均已连上自建服务。

同步的基本步骤:互相添加对方为远程设备 ——> 选择共享文件夹

具体步骤(下面假设有Syncthing客户端A和客户端B):

1 互相添加对方为远程设备

在客户端A中,点击添加远程设备,输入客户端B的device ID

高级中设置的地址列表表示寻找其他设备的发现服务器,用默认的 dynamic即可, dynamic表示用局域网发现和全球发现服务器寻找设备

The word dynamic (without any prefix) means to use local and global discovery to find the device.

2 选择共享文件夹

参考来源

syncthing官方说明

搭建和配置Syncthing发现和中继服务器

论多设备同步文件,它说第二,没人敢说第一:Syncthing 使用笔记

群晖nas自用johngong

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 一、背景引入
  • 二、docker部署发现服务器和中继服务器
    • command命令的配置部分说明:
    • 三、客户端Syncthing的设置
      • 自建服务的写法:
        • 1. 自建发现服务器地址(写在全局发现服务器,即第二个红框处)
        • 2. 自定义中继服务器地址(写在协议监听地址,即第一个红框处)
        • 关于发现服务器的https证书来源
        • 1 互相添加对方为远程设备
        • 2 选择共享文件夹
    • 四、两个客户端Syncthing进行同步
    • 参考来源
    相关产品与服务
    轻量应用服务器
    轻量应用服务器(TencentCloud Lighthouse)是新一代开箱即用、面向轻量应用场景的云服务器产品,助力中小企业和开发者便捷高效的在云端构建网站、Web应用、小程序/小游戏、游戏服、电商应用、云盘/图床和开发测试环境,相比普通云服务器更加简单易用且更贴近应用,以套餐形式整体售卖云资源并提供高带宽流量包,将热门软件打包实现一键构建应用,提供极简上云体验。
    领券
    问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档