使用 Syncthing 2.0 搭建私有同步服务器

介绍

一款同步协议和代码完全开源的数据同步应用。支持主流操作系统,可以到多个用户和设备之间同步数据。其非基于 IP ,而是基于 ID,在 LAN 与 Internet 网络基于 UPnP 发现和传输。

数据只存储在个人私有设备上,没有公共服务器,不会有公共服务器的数据泄露风险。使用加密传输和用户认证。

配置服务

docs.syncthing.net/users/confi...

启动

普通应用启动

sql 复制代码
You can make Syncthing start when you log into your desktop environment (DE) in two ways.

Using DE tools:

1.  Search for and launch a tool related to autostart or startup applications.
1.  Add a new autostart application and search for and choose "Start Syncthing".

If you don't find "Start Syncthing" in the steps above or just prefer doing it manually:

1.  Find the file `syncthing-start.desktop`: Either from the package you downloaded from GitHub in `etc/linux-desktop/`, in `/usr/share/applications/` if installed from your package manager or [from our repository](https://github.com/syncthing/syncthing/tree/main/etc/linux-desktop).
1.  Copy `syncthing-start.desktop` to `~/.config/autostart/`.

For more information relating to `.desktop` files e.g. for application menus, refer to <https://github.com/syncthing/syncthing/tree/main/etc/linux-desktop>.

命令行

scss 复制代码
* --config 和 --data 配合使用设置 config 和 默认数据目录
* --home 等同于 --config --data 两个的效果,其默认设在 `$XDG_STATE_HOME/syncthing` or `$HOME/.local/state/syncthing` (Unix-like), `$HOME/Library/Application Support/Syncthing` (Mac) and `%LOCALAPPDATA%\Syncthing` (Windows).
ini 复制代码
syncthing [serve]
          [--audit] [--auditfile=<file|-|-->] [--browser-only] [--device-id]
          [--generate=<dir>] [--gui-address=<address>] [--gui-apikey=<key>]
          [--home=<dir> | --config=<dir> --data=<dir>]
          [--logfile=<filename>] [--logflags=<flags>]
          [--log-max-old-files=<num>] [--log-max-size=<num>]
          [--no-browser] [--no-console] [--no-restart] [--paths] [--paused]
          [--no-default-folder] [--skip-port-probing]
          [--reset-database] [--reset-deltas] [--unpaused] [--allow-newer-config]
          [--upgrade] [--no-upgrade] [--upgrade-check] [--upgrade-to=<url>]
          [--verbose] [--version] [--help] [--debug-*]

syncthing generate
          [--home=<dir> | --config=<dir>]
          [--gui-user=<username>] [--gui-password=<password|->]
          [--no-default-folder] [--skip-port-probing] [--no-console]
          [--help]

syncthing decrypt (--to=<dir> | --verify-only)
          [--password=<pw>] [--folder-id=<id>] [--token-path=<file>]
          [--continue] [--verbose] [--version] [--help]
          <path>

syncthing cli
          [--home=<dir> | --config=<dir> --data=<dir>]
          [--gui-address=<address>] [--gui-apikey=<key>]
          [--help]
          <command> [command options...] [arguments...]

systemd

docs.syncthing.net/users/autos... systemd is a suite of system management daemons, libraries, and utilities designed as a central management and configuration platform for the Linux computer operating system.

ini 复制代码
sudo tee /etc/systemd/system/syncthing.service <<EOF                           
[Unit]                                                 
Description=Syncthing - Open Source Continuous File Synchronization
Documentation=man:syncthing(1)                               
StartLimitIntervalSec=60                                   
StartLimitBurst=4                                         
[Service]                                              
ExecStart=/usr/bin/syncthing serve --no-browser --no-restart --logflags=0   
Restart=on-failure                                                 
RestartSec=1                                                   
SuccessExitStatus=3 4                                   
RestartForceExitStatus=3 4                     
# Hardening                                           
SystemCallArchitectures=native                      
MemoryDenyWriteExecute=true                          
NoNewPrivileges=true                    
# Elevated permissions to sync ownership (disabled by default), 
# see https://docs.syncthing.net/advanced/folder-sync-ownership 
# AmbientCapabilities=CAP_CHOWN CAP_FOWNER               
[Install]                                        
WantedBy=default.target                                     
EOF                                                               

How to set up a system service

  1. Create the user who should run the service, or choose an existing one.

  2. (Skip if your distribution package already installs these files, see above.) From git location copy the syncthing@.service file into the load path of the system instance.

  3. Enable and start the service. Replace "myuser" with the actual Syncthing user after the @:

    sql 复制代码
    systemctl enable syncthing@myuser.service
    systemctl start syncthing@myuser.service

How to set up a user service

  1. Create the user who should run the service, or choose an existing one. Probably this will be your own user account.

  2. (Skip if your distribution package already installs these files, see above.) From git location copy the syncthing.service file into the load path of the user instance. To do this without root privileges you can just use this folder under your home directory: ~/.config/systemd/user/.

  3. Enable and start the service:

    css 复制代码
    systemctl --user enable syncthing.service
    systemctl --user start syncthing.service
  4. If your home directory is encrypted with eCryptfs on Debian/Ubuntu, then you will need to make the change described in Ubuntu bug 1734290. Otherwise the user service will not start, because by default, systemd checks for user services before your home directory has been decrypted.

Automatic start-up of systemd user instances at boot (before login) is possible through systemd's "lingering" function, if a system service cannot be used instead. Refer to the enable-linger command of loginctl to allow this for a particular user.

容器启动

bash 复制代码
docker run -d -p 8384:8384 -p 22000:22000 -v /home/xxx/syncthing:/var/syncthing --restart=always syncthing/syncthing:latest

参数解释:

  • -d:后台运行
  • -p 8384:8384: 暴露 8384 端口,8384 是 Web 界面端口
  • -p 22000:22000:暴露 22000 端口,22000 是通讯端口
  • -v /home/xxx/syncthing/:/var/syncthing:映射文件夹,将备份的文件映射至宿主机的/home/xxx/syncthing 目录下
  • --restart=always:容器随着 Docker 的启动而启动
  • syncthing/syncthing:latest:镜像版本

docker 国内源配置:juejin.cn/post/750524... docker-compose 安装

shell 复制代码
$ sudo curl -L "https://github.com/docker/compose/releases/download/v2.38.1/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose

docker-compose.yml

yaml 复制代码
# yaml 配置实例
version: '3'
services:
  syncthing:
    image: syncthing/syncthing:latest
    container_name: syncthing
    ports:
    - "8384:8384"
    - "22000:22000"
    volumes:
    - //home/liang/workspace/tools/syncthing/docker:/var/syncthing
    restart: unless-stopped

如果你购买的服务器有控制面板,需要在控制面板开放8384(TCP)和22000(TCP 和 UDP 都要开)

至此,syncthing 服务已经启动,下一步我们只需要在本地也启动一个 syncthing,与服务器进行实时同步即可。

GUI 配置

默认配置监听地址 127.0.0.1:8384 只能本机方法。用户名与密码为空,需要手动设置。

添加设备

通过设备 ID 则可以添加统一 LAN 网络中的启动了 syncthing 服务的其他设备。

文件同步

  1. 添加文件,设在文件路径

  2. 设置共享设备,如果同步明文则不要设置密码。设置密码后,同步的数据是加密数据,不可查看,只用作备份。

  3. 版本控制,有多个策略可选,这里选择简单文本版本控制

相关推荐
NocoBase1 小时前
GitHub 上 Star 数量前 8 的开源 MCP 项目
开源·openai·mcp
zkmall1 小时前
ZKmall开源商城架构工具链:Docker、k8s 部署与管理技巧
docker·架构·开源
智源研究院官方账号2 小时前
国际标准组织共聚,智源推动全球AI开源与国际标准双轮驱动人工智能普惠化发展
人工智能·开源
Points3 小时前
开源分享程序员专用作品集网站 - StudioX
开源·交互设计
倔强的石头1063 小时前
[源力觉醒 创作者计划]_文心大模型4.5开源:从技术突破到生态共建的国产AI解读与本地部署指南
人工智能·开源·文心一言·文心大模型
baozj3 小时前
🚀我靠!AI 帮我“摸鱼”摸成了腾讯开源组件库 TDesign 的贡献者!
前端·开源·github
算家计算4 小时前
单卡10分钟部署MiniCPM4-0.5B:轻量级大模型本地运行指南
人工智能·开源
MarkGosling4 小时前
【开源项目】轻量加速利器 HubProxy 自建 Docker、GitHub 下载加速服务
运维·git·docker·容器·开源·github·个人开发
····懂···4 小时前
开源数据库PostgreSQL专家技术
数据库·postgresql·开源
zzywxc7878 小时前
编程算法在金融、医疗、教育、制造业的落地应用。
人工智能·深度学习·算法·机器学习·金融·架构·开源