32

搭建 Syncthing 发现与中继服务器并使用 systemd 管理

 3 years ago
source link: https://blog.maolu.one/syncthing-stdiscosrv-strelaysrv-systemd-service/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

搭建 Syncthing 发现与中继服务器并使用 systemd 管理

由于众所周知的原因,使用 Syncthing 同步文件会遇到连不上的问题,所以最好是自己搭建发现与中继服务器。搭建 Syncthing 的发现与中继服务器比较简单,都是单个可执行文件,可在服务器上从 Github (发现服务 | 中继服务)上下载后,直接执行就可以了。

要保持后台运行,有多种方式,比如 nohup 或者使用 supervisor。我个人偏好 systemd。在安装和配置 systemd 服务前,需要先分别手动运行一次发现服务器和中继服务器程序,以便自动在当前目录生成证书和查看记录两项服务各自的服务器 ID。

一、配置服务

发现服务器 systemd 配置(/usr/lib/systemd/system/syncdiscovery.service):

[Unit]
Description=SyncthingDiscoveryServer
After=network.target
Wants=network-online.target
[Service]
Restart=always
Type=simple
ExecStart=/root/stdiscosrv-linux-amd64-v1.8.0/stdiscosrv -cert /root/stdiscosrv-linux-amd64-v1.8.0/cert.pem -key /root/stdiscosrv-linux-amd64-v1.8.0/key.pem -db-dir=/root/stdiscosrv-linux-amd64-v1.8.0
Environment=
[Install]
WantedBy=multi-user.target

需要修改的为 ExecStart 语句。需要将相关目录替换为实际保存 stdiscosrv 的目录,以及对应的证书路径,前文提到手动运行一次自动生成证书。

中继服务器 systemd 配置(/usr/lib/systemd/system/syncrelay.service):

[Unit]
Description=SyncthingRelayServer
After=network.target
Wants=network-online.target
[Service]
Restart=always
Type=simple
ExecStart=/root/strelaysrv-linux-amd64-v1.8.0/strelaysrv -keys /root/strelaysrv-linux-amd64-v1.8.0 -pools="" -global-rate 0 -protocol=tcp4
Environment=
[Install]
WantedBy=multi-user.target

也需要将 ExecStart 语句中相关目录修改为实际的目录。

如果需要自定义配置,可以参考官方文档:

https://docs.syncthing.net/users/stdiscosrv.html

https://docs.syncthing.net/users/strelaysrv.html

二、管理服务

使用 systemctl 管理服务。

# 启动服务
systemctl start syncdiscovery.service
systemctl start syncrelay.service
# 停止服务
systemctl stop syncdiscovery.service
# 开机自启动
systemctl enable syncdiscovery.service
# 查看状态
systemctl status syncdiscovery.service

服务安装好后,需要在防火墙中开放 8443、22067、22070 三个 TCP 端口。

三、客户端设置

如果是 Windows 的 SyncthingTrayzor 客户端,则在【 操作 > 设置 > 连接】中设置发现和中继服务器。

协议监听地址,即发现服务器地址。如图所示根据服务器的 IP 和 ID 填写。发现服务器则需要勾选【全球发现】,然后根据服务器的 IP 和 ID 填写。注意:发现服务器与中继服务器的 ID 是不同的,这个在前文有提到,需要手动运行一次记录下来,因为 ID 较长,通过 systemctl status 命令的输出看不全。

49c5853ade1f1b60986c615dd24b42b1?s=49&d=mm&r=g作者 茅庐老道发布于 2021年2月24日2021年2月24日分类 技术笔记标签 syncthingsystemd

发表评论 取消回复

您的电子邮箱地址不会被公开。 必填项已用*标注

评论

显示名称 *

电子邮箱地址 *

网站网址

在此浏览器中保存我的显示名称、邮箱地址和网站网址,以便下次评论时使用。


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK