使用Syncthing自建私有同步盘

时间:2022-07-26
本文章向大家介绍使用Syncthing自建私有同步盘,主要内容包括其使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

syncthing应该是目前开源界人气最高的一款了,这个主打私有,真的完全私有。。。没有公开分享的功能,并且同步必须要两端相互添加对方许可才行。

毕竟是基于GO开发的,搭建都很简单,并且官方提供了二进制文件,下载即用:

wget https://github.com/syncthing/syncthing/releases/download/v1.0.0/syncthing-linux-amd64-v1.0.0.tar.gz
tar -xzvf syncthing-linux-amd64-v1.0.0.tar.gz
cd syncthing-linux-amd64-v1.0.0
cp syncthing /usr/bin

这里我还是按照自己的习惯把配置成systemd的服务:

vi /etc/systemd/system/syncthing.service

写入:

[Unit]
Description=Syncthing - Open Source Continuous File Synchronization
After=network.target

[Service]
User=root
ExecStart=/usr/bin/syncthing -no-restart -logflags=0
Restart=on-failure
SuccessExitStatus=3 4
RestartForceExitStatus=3 4
ProtectSystem=full
PrivateTmp=true
SystemCallArchitectures=native
MemoryDenyWriteExecute=true
NoNewPrivileges=true

[Install]
WantedBy=default.target

然后运行:

systemctl start syncthing

设置开机启动:

systemctl enable syncthing

因为syncthing默认只监听本地,所以我们要用做一下,但是syncthing新版本加入了一个主机头检测的功能,这个要关闭,不然无法进行反代:

vi ~/.config/syncthing/config.xml

在GUI设置的下面加入:

<insecureSkipHostcheck true</insecureSkipHostcheck

如图所示:

然后重启:

systemctl restart syncthing

安装:

yum -y install nginx

新建一个站点配置文件:

vi /etc/nginx/conf.d/syncthing.conf

写入:

server {
    listen       5862;
    client_max_body_size 100000m;
    server_name  example.com;

location /syncthing/ {
    proxy_set_header        Host $host;
    proxy_set_header        X-Real-IP $remote_addr;
    proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header        X-Forwarded-Proto $scheme;

    proxy_pass              http://127.0.0.1:8384/;

    proxy_read_timeout      600s;
    proxy_send_timeout      600s;
    }
}

这里我把syncthing监听在了5862端口,不是常规端口,因为这个WEBUI初次启动的时候是没有密码验证的,为防止滥用建议监听一个高位端口,后续我们登录进去设置了密码再修改回80都可以的。

现在启动以及设置开机启动:

systemctl start nginx
systemctl enable nginx

现在打开你的站点:

http://你的地址:5862/syncthing

应该可以访问到这个的首页:

现在你应该立即给这个WEBUI设置密码:

客户端的话,我个人推荐这个:://github./canton7/SyncTrayzor

下载:://github./canton7/SyncTrayzor/releases/download/v1.1.22/SyncTrayzorSetup-x64.exe

测试了一下功能,可以正常同步: