静看光阴荏苒
不管不顾不问不说也不念

使用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设置的下面加入:

<insecureSkipHostcheck>true</insecureSkipHostcheck>

如图所示:

然后重启:

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

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

赞(2)
未经允许不得转载:荒岛 » 使用Syncthing自建私有同步盘
分享到: 更多 (0)

评论 1

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

分享创造快乐

广告合作资源投稿