docker部署syncthing

环境配置

新建用户组和用户 backup

groupadd backup
useradd -r -g backup backup

编排

查询用户backup的PUID和PGID

id backup

syncthing加入nextcloud网络或自定义网络

映射路径:/var/syncthing

version: '3'

networks:
  default:
    name: nextcloud
    driver: bridge
    #external: true开启加入已经存在网络
    external: true
    
services:
  syncthing:
    image: syncthing/syncthing
    restart: unless-stopped
    volumes:
      - /vmw/syncthing:/var/syncthing
    environment:
      - PUID=985
      - PGID=1000      
    ports:
      #- 8384:8384
      - 22000:22000/tcp
      - 22000:22000/udp
      - 21027:21027/udp
    expose:
      - 8384
    networks:
      - default  
    #network_mode: "host"
    container_name: syncthing
    hostname: syncthing

指定路径编排

docker-compose -f /xxx/syncthing.yml up -d

反向代理

使用nginx进行反向代理,并限制访问ip

server {  
    listen 8080;  
    server_name localhost;  
  
    location / {  
        proxy_pass http://syncthing:8384;  
        proxy_set_header Host $host;  
        proxy_set_header X-Real-IP $remote_addr;  
        allow 10.2.1.15;
        deny all;
    }  
    
}

中继和发现服务器部署

github下载最新版本

#discosrv发现服务器
https://github.com/syncthing/discosrv/releases/
#relaysrv中继服务器
https://github.com/syncthing/relaysrv/releases/

解压

tar -zxvf strelaysrv-linux-amd64-v1.29.0-rc.1.tar.gz
tar -zxvf stdiscosrv-linux-amd64-v1.29.0-rc.1.tar.gz

拷贝放到可执行目录下

cp stdiscosrv-linux-amd64-v1.29.0-rc.1/stdiscosrv /usr/bin/
cp strelaysrv-linux-amd64-v1.29.0-rc.1/strelaysrv /usr/bin/

创建log日志文件

touch stdiscosrv.log strelaysrv.log

使用 nohup 启动

nohup stdiscosrv > stdiscosrv.log 2>&1 &
nohup strelaysrv > strelaysrv.log -pools="" 2>&1 &

随后看对应的日志文件中,有打印 ID,自行找到即可

注意,一定要去看日志,比如启动中继服务时候,要加上 -pools="",不然的话会去注册到公共的池子,加上这个之后就不会了,单单是自己私有的

放开相关端口

发现服务器:8443

中继服务器:22067 22070

客户端使用地址

发现服务器:discosrv

https://ip_address:port/?id=your_idc

中继服务器地址:relaysrv

relay://ip_address:port/?id=your_id

客户端配置

上面的“协议监听地址”填的是中继服务器的地址:

tcp4://0.0.0.0:22000, relay://xxx.xxx.xxx.xxx:22067/?id=your_id

也可以加上 default,中间用英文逗号分割,代表两个都用,哪个能用用哪个

下面的全局发现服务器填的是发现服务器的地址:

https://xxx.xxx.xxx.xxx:8443/?id=your_id

同样也可以加上 default,如:

https://xxx.xxx.xxx.xxx:8443/?id=your_id,default