Dragon
国外主机测评国外主机测评  2019-08-21 16:24 国外主机测评 隐藏边栏  46 
文章评分 0 次,平均分 0.0

简介

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

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

 

1
2
3
4
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 的服务:

 

1
vi /etc/systemd/system/syncthing.service

写入:

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
[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

然后运行:

 

1
systemctl start syncthing

设置开机启动:

 

1
systemctl enable syncthing

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

 

1
vi ~/.config/syncthing/config.xml

在 GUI 设置的下面加入:

true

如图所示:
使用 Syncthing 自建私有同步盘教程
然后重启:

 

1
systemctl restart syncthing

安装 Nginx:

 

1
yum -y install nginx

新建一个 Nginx 站点配置文件:

 

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

写入:

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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 以及设置开机启动

 

1
2
systemctl start nginx
systemctl enable nginx

现在打开你的站点域名:

http://example.com:5862/syncthing

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

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

测试了一下功能,可以正常同步:
使用 Syncthing 自建私有同步盘教程

本文为原创文章,版权归所有,欢迎分享本文,转载请保留出处!

扫一扫二维码分享