syncthing数据同步应用-docker部署

syncthing应用场景类似于rsync,在数据传输通道的两端都部署服务,再通过密钥验证的方式完成最终数据同步。而syncthing较之更加简单,因配备了Web UI,配置上难度降低了不少。

相关资料

  • https://syncthing.net/
  • https://github.com/syncthing/syncthing
  • https://github.com/syncthing/syncthing/blob/master/README-Docker.md

支持很多种类型终端

syncthing数据同步应用-docker部署_第1张图片

一般来说,syncthing可以定义一个 服务端,作为数据存储,然后在其他终端运行,设置数据目录同步。

  • 将syncthing容器服务定义为数据存储服务,当容器启动后,将自动打开tcp8384端口,用于Web UI的访问*“Access the GUI via the following URL: http://127.0.0.1:8384”*

在syncthing工作的过程中,开放了两个tcp端口。

  • 端口8384:主要用于Remote web UI的访问
  • 端口22000:是用做同步协议的端口
#下载官方镜像
docker pull syncthing/syncthing
#运行容器,将数据目录映射到本地/home/admin/syncthing:/var/syncthing 
docker run -p 8384:8384 -p 22000:22000 -v /home/admin/syncthing:/var/syncthing syncthing/syncthing:latest
[monitor] 22:52:33 INFO: Starting syncthing
[start] 22:52:33 INFO: syncthing v1.2.2 "Fermium Flea" (go1.12.9 linux-amd64) [email protected] 2019-08-15 13:51:09 UTC
[XOTLZ] 22:52:33 INFO: My ID: XOTLZLV-FTJXL3J-ND7UG2J-4TMURL3-2HB5XI5-C2C6WGF-7SDKDBC-FTUVQQS
[XOTLZ] 22:52:34 INFO: Single thread SHA256 performance is 254 MB/s using crypto/sha256 (251 MB/s using minio/sha256-simd).
[XOTLZ] 22:52:34 INFO: Hashing performance is 266.52 MB/s
[XOTLZ] 22:52:34 INFO: Ready to synchronize "Default Folder" (default) (sendreceive)
[XOTLZ] 22:52:34 INFO: Overall send rate is unlimited, receive rate is unlimited
[XOTLZ] 22:52:34 INFO: Using discovery server https://discovery.syncthing.net/v2/?noannounce&id=LYXKCHX-VI3NYZR-ALCJBHF-WMZYSPK-QG6QJA3-MPFYMSO-U56GTUK-NA2MIAW
[XOTLZ] 22:52:34 INFO: Using discovery server https://discovery-v4.syncthing.net/v2/?nolookup&id=LYXKCHX-VI3NYZR-ALCJBHF-WMZYSPK-QG6QJA3-MPFYMSO-U56GTUK-NA2MIAW
[XOTLZ] 22:52:34 INFO: Using discovery server https://discovery-v6.syncthing.net/v2/?nolookup&id=LYXKCHX-VI3NYZR-ALCJBHF-WMZYSPK-QG6QJA3-MPFYMSO-U56GTUK-NA2MIAW
[XOTLZ] 22:52:34 INFO: QUIC listener ([::]:22000) starting
[XOTLZ] 22:52:34 INFO: TCP listener ([::]:22000) starting
[XOTLZ] 22:52:34 INFO: Relay listener (dynamic+https://relays.syncthing.net/endpoint) starting
[XOTLZ] 22:52:34 INFO: Completed initial scan of sendreceive folder "Default Folder" (default)
[XOTLZ] 22:52:34 INFO: GUI and API listening on [::]:8384
[XOTLZ] 22:52:34 INFO: Access the GUI via the following URL: http://127.0.0.1:8384/
[XOTLZ] 22:52:34 INFO: My name is "b9a6f629f5a8"
[XOTLZ] 22:52:44 INFO: quic://0.0.0.0:22000 detected NAT type: Symmetric NAT
[XOTLZ] 22:52:44 INFO: quic://0.0.0.0:22000 resolved external address quic://218.240.148.51:16289 (via stun.syncthing.net:3478)
[XOTLZ] 22:52:55 INFO: Detected 1 NAT service
[XOTLZ] 22:54:02 INFO: Joined relay relay://x.x.x.x:22067
[XOTLZ] 22:57:54 INFO: quic://0.0.0.0:22000 detected NAT type: Symmetric NAT
[XOTLZ] 22:57:54 INFO: quic://0.0.0.0:22000 resolved external address quic://x.x.x.x:17640 (via stun.syncthing.net:3478)
  • 查看容器状态
docker ps -a
CONTAINER ID        IMAGE                        COMMAND                  CREATED             STATUS                   PORTS                                                            NAMES
fbc8950a123b        syncthing/syncthing:latest   "/bin/entrypoint.sh …"   6 minutes ago       Up 6 minutes (healthy)   0.0.0.0:8384->8384/tcp, 0.0.0.0:22000->22000/tcp, 21027/udp      romantic_jones
  • 直接访问http://ip:8384
    syncthing数据同步应用-docker部署_第2张图片

将一台Ubuntu Server作为终端进行测试

  • 安装syncthing
# Add the release PGP keys:
curl -s https://syncthing.net/release-key.txt | sudo apt-key add -

# Add the "stable" channel to your APT sources:
echo "deb https://apt.syncthing.net/ syncthing stable" | sudo tee /etc/apt/sources.list.d/syncthing.list

# Update and install syncthing:
sudo apt-get update
sudo apt-get install syncthing

  • 启动服务

    #0.0.0.0:8384,设置web UI访问为任何地址,测试时是没有认证,非常不安全,正式环境是需要设置账户密码验证的
    syncthing -no-browser -gui-address="0.0.0.0:8384" -no-restart -logflags=0
    [start] INFO: syncthing v1.2.2 "Fermium Flea" (go1.12.9 linux-amd64) [email protected] 2019-08-15 13:51:09 UTC
    [start] INFO: Generating ECDSA key and certificate for syncthing...
    [start] INFO: Default folder created and/or linked to new config
    [start] INFO: Default config saved. Edit /root/.config/syncthing/config.xml to taste (with Syncthing stopped) or use the GUI
    [3SUZI] INFO: My ID: 3SUZIJJ-KZN5BS6-PSS5BA5-3WU2ANE-66NACZQ-QY7V75K-NMRWK6L-ZGJ47AF
    [3SUZI] INFO: Single thread SHA256 performance is 328 MB/s using minio/sha256-simd (256 MB/s using crypto/sha256).
    [3SUZI] INFO: Hashing performance is 283.29 MB/s
    [3SUZI] INFO: No stored folder metadata for "default": recalculating
    [3SUZI] INFO: Ready to synchronize "Default Folder" (default) (sendreceive)
    [3SUZI] INFO: Overall send rate is unlimited, receive rate is unlimited
    [3SUZI] INFO: Using discovery server https://discovery.syncthing.net/v2/?noannounce&id=LYXKCHX-VI3NYZR-ALCJBHF-WMZYSPK-QG6QJA3-MPFYMSO-U56GTUK-NA2MIAW
    [3SUZI] INFO: Using discovery server https://discovery-v4.syncthing.net/v2/?nolookup&id=LYXKCHX-VI3NYZR-ALCJBHF-WMZYSPK-QG6QJA3-MPFYMSO-U56GTUK-NA2MIAW
    [3SUZI] INFO: Using discovery server https://discovery-v6.syncthing.net/v2/?nolookup&id=LYXKCHX-VI3NYZR-ALCJBHF-WMZYSPK-QG6QJA3-MPFYMSO-U56GTUK-NA2MIAW
    [3SUZI] INFO: QUIC listener ([::]:22000) starting
    [3SUZI] INFO: Loading HTTPS certificate: open /root/.config/syncthing/https-cert.pem: no such file or directory
    [3SUZI] INFO: Creating new HTTPS certificate
    [3SUZI] INFO: TCP listener ([::]:22000) starting
    [3SUZI] INFO: Relay listener (dynamic+https://relays.syncthing.net/endpoint) starting
    [3SUZI] INFO: Completed initial scan of sendreceive folder "Default Folder" (default)
    [3SUZI] INFO: GUI and API listening on [::]:8384
    [3SUZI] INFO: Access the GUI via the following URL: http://127.0.0.1:8384/
    [3SUZI] INFO: My name is "elk"
    [3SUZI] WARNING: Syncthing should not run as a privileged or system user. Please consider using a normal user account.
    [3SUZI] INFO: quic://0.0.0.0:22000 detected NAT type: Symmetric NAT
    [3SUZI] INFO: quic://0.0.0.0:22000 resolved external address quic:///x.x.x.x:30146 (via stun.syncthing.net:3478)
    [3SUZI] INFO: Detected 1 NAT service
    [3SUZI] INFO: Sent usage report (version 3)
    [3SUZI] INFO: Joined relay relay://x.x.x.x:22067
    [3SUZI] INFO: Listen (BEP/relay): joining session: Incorrect response code 2: already connected
    
  • 在终端上访问web UI获取设备ID“XOTLZLV-FTJXL3J-ND7UG2J-4TMURL3-2HB5XI5-C2C6WGF-7SDKDBC-FTUVQQS”
    syncthing数据同步应用-docker部署_第3张图片syncthing数据同步应用-docker部署_第4张图片

  • 默认共享的目录的路径

    /var/syncthing/Sync

  • 在syncthing docker服务端添加将终端作为远程设备添加。同时,还可以在Sharing设置需要共享的目录有哪些,以及同步数据时上传下载的速率

syncthing数据同步应用-docker部署_第5张图片syncthing数据同步应用-docker部署_第6张图片

  • 远程共享设备添加成功
    syncthing数据同步应用-docker部署_第7张图片

  • 测试数据同步

向终端syncthing的共享目录内复制一个文件

  • 正在自动同步
    syncthing数据同步应用-docker部署_第8张图片syncthing数据同步应用-docker部署_第9张图片syncthing数据同步应用-docker部署_第10张图片

你可能感兴趣的:(docker)