使用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默认只监听本地,所以我们要用Nginx做一下反向代理,但是syncthing新版本加入了一个服务器头检测的功能,这个要关闭,不然Nginx无法进行反代:

vi ~/.config/syncthing/config.xml

在GUI设置的下面加入:

true

如图所示: 然后重启:

systemctl restart syncthing

安装Nginx:

yum -y install nginx

新建一个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都可以的。

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

systemctl start nginx systemctl enable nginx

现在打开你的站点域名:

http://example.com:5862/syncthing

应该可以访问到这个同步盘的首页: 现在你应该立即给这个WEBUI设置密码: Windows客户端的话,我个人推荐这个:https://github.com/canton7/SyncTrayzor

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

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

推荐站内搜索:已备案域名查询、国外免费空间、双线服务器托管、域名空间代理、服务器租赁、备案域名查询、万网域名空间、vps主机、工信部备案网址、国外服务器vps、