使用syncthing进行双机文件同步
使用syncthing进行双机文件同步
syncthing是一款开源的文件同步软件,可以
syncthing安装
tar -zxvf syncthing-linux-amd64-v0.12.15.tar.gz
cd syncthing-linux-amd64-v0.12.15
cp syncthing /usr/local/bin
syncthing
[monitor] 08:54:46 INFO: Starting syncthing
[start] 08:54:46 INFO: Generating ECDSA key and certificate for syncthing...
[3TU4X] 08:54:46 INFO: syncthing v0.12.15 "Beryllium Bedbug" (go1.5.3 linux-amd64) unknown-user@build2.syncthing.net 2016-01-17 09:57:20 UTC
[3TU4X] 08:54:46 INFO: My ID: 3TU4XGI-2MDZT5C-A2I67IT-WMXOV6F-ULJPSVA-XKG3A6U-H6LDFBX-XMAX5AA
[3TU4X] 08:54:46 INFO: Single thread hash performance is ~76 MB/s
[3TU4X] 08:54:46 INFO: Error loading config file; using defaults for now
[3TU4X] 08:54:46 INFO: Default folder created and/or linked to new config
[3TU4X] 08:54:46 INFO: Defaults saved. Edit /root/.config/syncthing/config.xml to taste or use the GUI
[3TU4X] 08:54:46 OK: Ready to synchronize default (read-write)
[3TU4X] 08:54:46 INFO: Using discovery server https://discovery-v4-1.syncthing.net/?id=SR7AARM-TCBUZ5O-VFAXY4D-CECGSDE-3Q6IZ4G-XG7AH75-OBIXJQV-QJ6NLQA
[3TU4X] 08:54:46 INFO: Using discovery server https://discovery-v4-2.syncthing.net/?id=DVU36WY-H3LVZHW-E6LLFRE-YAFN5EL-HILWRYP-OC2M47J-Z4PE62Y-ADIBDQC
[3TU4X] 08:54:46 INFO: Using discovery server https://discovery-v4-3.syncthing.net/?id=VK6HNJ3-VVMM66S-HRVWSCR-IXEHL2H-U4AQ4MW-UCPQBWX-J2L2UBK-NVZRDQZ
[3TU4X] 08:54:46 INFO: Using discovery server https://discovery-v6-1.syncthing.net/?id=SR7AARM-TCBUZ5O-VFAXY4D-CECGSDE-3Q6IZ4G-XG7AH75-OBIXJQV-QJ6NLQA
[3TU4X] 08:54:46 INFO: Using discovery server https://discovery-v6-2.syncthing.net/?id=DVU36WY-H3LVZHW-E6LLFRE-YAFN5EL-HILWRYP-OC2M47J-Z4PE62Y-ADIBDQC
[3TU4X] 08:54:46 INFO: Using discovery server https://discovery-v6-3.syncthing.net/?id=VK6HNJ3-VVMM66S-HRVWSCR-IXEHL2H-U4AQ4MW-UCPQBWX-J2L2UBK-NVZRDQZ
[3TU4X] 08:54:46 INFO: Completed initial scan (rw) of folder default
[3TU4X] 08:54:46 INFO: Loading HTTPS certificate: open /root/.config/syncthing/https-cert.pem: no such file or directory
[3TU4X] 08:54:46 INFO: Creating new HTTPS certificate
[3TU4X] 08:54:47 INFO: Device 3TU4XGI-2MDZT5C-A2I67IT-WMXOV6F-ULJPSVA-XKG3A6U-H6LDFBX-XMAX5AA is "test.xxx.net" at [dynamic]
[3TU4X] 08:54:47 INFO: API listening on 127.0.0.1:8384
[3TU4X] 08:54:47 INFO: GUI URL is http://127.0.0.1:8384/
修改配置,实现web远程登录
cd /root/.config/syncthing/
vi config.xml
<address>0.0.0.0:8384</address>
而后就可以使用web页面进行配置。初始页面如下:
然后就可以点击右上角的Action->Setting选项进行配置,如果我们在内网使用,就可以关闭发现、中继和升级等的选项。
点击首页Folder栏目下的Add Folder按钮,用以添加同步的目录。在需要同步的两台服务器上都进行文件夹配置,此处我们使用Syncthing同步http访问的session信息。
下面的步骤就是用于连接两台的服务器了。首先在其中一台查看device id,也在右上角的Action-> Show ID菜单下。
复制到Device ID后,到另一台服务器的控制页面,点击右下角的Add Device按钮。按如下输入对端的信息。其中Addresses栏直接填写对端服务器的IP地址加22000端口。22000端口为默认配置,可以在cconfig.xml文件中进行更改。
一旦配置完成一台服务器,起来去上个厕所,回来后就可以发现另一条服务器的控制页面会出现连接请求,直接点击Add Device即可。
然后,按照同步的时间间隔,默认为60秒,等看到Device和Folder状态都变成Up to Date之后,就表明两台服务器之间的同步机制就建立完成了。