文章目录

  • 一、Syncthing
    • 0. 什么是Syncthing
    • 1. 开始
      • 第一步:安装
      • 第二步:启动
      • 第三步:配置
    • 2. 理解Syncthing同步原理
      • Blocks
      • Scanning 扫描
      • Syncing 同步

一、Syncthing

github: https://github.com/syncthing/syncthing/
官方文档: https://docs.syncthing.net/intro/getting-started.html
官方:https://forum.syncthing.net/

0. 什么是Syncthing

Syncthing is a continuous file synchronization program. It synchronizes files between two or more computers. We strive to fulfill the goals below. The goals are listed in order of importance, the most important one being the first. This is the summary version of the goal list - for more commentary, see the full Goals document.

Syncthing 是一个持续的文件同步程序。 它在两台或多台计算机之间同步文件。 我们努力实现以下目标。 目标按重要性顺序列出,最重要的是第一个。 这是目标列表的摘要版本 - 有关更多评论,请参阅完整的目标文档。

Syncthing should be:

  1. Safe From Data Loss
    Protecting the user’s data is paramount. We take every reasonable precaution to avoid corrupting the user’s files.

  2. Secure Against Attackers
    Again, protecting the user’s data is paramount. Regardless of our other goals we must never allow the user’s data to be susceptible to eavesdropping or modification by unauthorized parties.

  3. Easy to Use
    Syncthing should be approachable, understandable and inclusive.

  4. Automatic
    User interaction should be required only when absolutely necessary.

  5. Universally Available
    Syncthing should run on every common computer. We are mindful that the latest technology is not always available to any given individual.

  6. For Individuals
    Syncthing is primarily about empowering the individual user with safe, secure and easy to use file synchronization.

  7. Everything Else
    There are many things we care about that don’t make it on to the list. It is fine to optimize for these values, as long as they are not in conflict with the stated goals above.

Does Syncthing support syncing between folders on the same system? 同步支持同一系统上的文件夹之间的同步吗?
No. Syncthing is not designed to sync locally and the overhead involved in doing so using Syncthing’s method would be wasteful. There are better programs to achieve this such as rsync or Unison.

没有。Syncthing 并不是为本地同步而设计的,而且使用同步方法进行本地同步所涉及的开销是很浪费的。有更好的程序来实现这一点,比如 rsync 或者 Unison。

1. 开始

Getting Started
有一些示例可以让 Syncthing 在您系统的 etc 目录中的后台运行。 还有一些适用于 Windows、Mac 和 Linux 的 GUI 实现。

第一步:安装

官方的版本可以去这里下载:https://syncthing.net/

官方的版本提供基本的同步功能,如果您愿意玩一点花里胡哨的,可以去社区贡献版那里看看。

社区贡献版本里有NAS插件,版本控制工具,Docker等等,这里我给出链接。

https://docs.syncthing.net/users/contrib.html

第二步:启动

为您的操作系统获取最新版本的 Syncthing 并将其解压缩(如果您使用 Debian/Ubuntu,您可能希望使用 Debian 存储库)。 将有一个名为 syncthing(或 Windows 上的 syncthing.exe)的二进制文件。 以您最喜欢的任何方式开始; 双击应该适用于任何图形环境,但我将使用命令行来更好地说明会发生什么。 首先启动 Syncthing 会生成一个配置文件、一些密钥,然后在浏览器中启动管理 GUI。 类似下面的内容将打印在命令行中:

> syncthing
[monitor] 22:56:32 INFO: Log output saved to file "C:\Users\User\AppData\Local\Syncthing\syncthing.log"
[monitor] 22:56:32 INFO: Default folder created and/or linked to new config
[start] 22:56:32 INFO: syncthing v1.7.1 "Fermium Flea" (go1.14.4 windows-386) teamcity@build.syncthing.net 2020-07-11 18:17:41 UTC
[start] 22:56:32 INFO: Default folder created and/or linked to new config
[start] 22:56:32 INFO: Default config saved. Edit C:\Users\User\AppData\Local\Syncthing\config.xml to taste (with Syncthing stopped) or use the GUI
[6FOKX] 22:56:33 INFO: My ID: 6FOKXKK-SKUBWFW-GSKX6IQ-ZC4SYUZ-5IEVZKE-TC42AAX-HW7IBW4-GAZFAQ7
[6FOKX] 22:56:34 INFO: Single thread SHA256 performance is 123 MB/s using crypto/sha256 (108 MB/s using minio/sha256-simd).
[6FOKX] 22:56:34 INFO: Hashing performance is 106.31 MB/s
[6FOKX] 22:56:34 INFO: Overall send rate is unlimited, receive rate is unlimited
[6FOKX] 22:56:34 INFO: Using discovery server https://discovery.syncthing.net/v2/?noannounce&id=LYXKCHX-VI3NYZR-ALCJBHF-WMZYSPK-QG6QJA3-MPFYMSO-U56GTUK-NA2MIAW
[6FOKX] 22:56:34 INFO: Using discovery server https://discovery-v4.syncthing.net/v2/?nolookup&id=LYXKCHX-VI3NYZR-ALCJBHF-WMZYSPK-QG6QJA3-MPFYMSO-U56GTUK-NA2MIAW
[6FOKX] 22:56:34 INFO: Using discovery server https://discovery-v6.syncthing.net/v2/?nolookup&id=LYXKCHX-VI3NYZR-ALCJBHF-WMZYSPK-QG6QJA3-MPFYMSO-U56GTUK-NA2MIAW
[6FOKX] 22:56:34 INFO: Ready to synchronize "Default Folder" (default) (sendreceive)
[6FOKX] 22:56:34 INFO: QUIC listener ([::]:22000) starting
[6FOKX] 22:56:34 INFO: TCP listener ([::]:22000) starting
[6FOKX] 22:56:34 INFO: Relay listener (dynamic+https://relays.syncthing.net/endpoint) starting
[6FOKX] 22:56:34 INFO: Completed initial scan of sendreceive folder "Default Folder" (default)
[6FOKX] 22:56:34 INFO: GUI and API listening on 127.0.0.1:8384
[6FOKX] 22:56:34 INFO: Access the GUI via the following URL: http://127.0.0.1:8384/
[6FOKX] 22:56:34 INFO: My name is "This computer"
[6FOKX] 22:56:45 INFO: quic://0.0.0.0:22000 detected NAT type: Symmetric NAT
[6FOKX] 22:56:45 INFO: quic://0.0.0.0:22000 resolved external address quic://125.190.151.7:59296 (via stun.syncthing.net:3478)
[6FOKX] 22:56:46 INFO: Detected 0 NAT services

此时 Syncthing 还将为您设置一个名为 Default Folder 的文件夹,位于您主目录中名为 Sync 的目录中。 您可以将此作为起点,然后将其删除或稍后添加更多文件夹。

第三步:配置

管理 GUI 自动启动并在 http://localhost:8384/ 上保持可用。 Cookie 对于 GUI 的正常运行至关重要; 请确保您的浏览器接受它们。 它应该是这样的:左侧是要同步的“文件夹”或目录列表。 您可以看到默认文件夹是为您创建的,它目前标记为“未共享”,因为它尚未与任何其他设备共享。 右侧是设备列表。 目前只有一种设备:运行它的计算机。

为了让 Syncthing 能够与另一台设备同步文件,它必须被告知该设备。 这是通过交换“设备 ID”来实现的。 设备 ID 是唯一的、加密安全的标识符,它在您第一次启动 Syncthing 时作为密钥生成的一部分生成。 它打印在上面的日志中,您可以通过选择“操作”(右上角)和“显示 ID”在 Web GUI 中看到它。

如果两个设备都配置了彼此的设备 ID,则它们只会相互连接和通话。 由于配置必须是相互的才能发生连接,因此设备 ID 不需要保密。 它们本质上是公钥的一部分。

要让您的两个设备相互通信,请单击两者右下角的“添加远程设备”,然后输入另一端的设备 ID。 您还应该选择要共享的文件夹。 设备名称是可选的,纯粹是装饰性的。 如果需要,可以稍后更改。
单击“保存”后,新设备将出现在 GUI 的右侧(尽管已断开连接),然后在一分钟左右后连接到新设备。 请记住对其他设备重复此步骤。
此时两台设备共享一个空目录。 将文件添加到任一设备上的共享目录都会将这些文件同步到另一端。

如果您在连接设备时遇到问题,请首先查看防火墙设置,然后查看 GUI 或控制台上的所有错误消息。 不要忘记配置更改不会立即反映 - 给 Syncthing 一点时间,尤其是在重新启动之后。

2. 理解Syncthing同步原理

Blocks

Files are divided into blocks. The blocks making up a file are all the same size (except the last one in the file which may be smaller). The block size is dependent on the file size and varies from 128 KiB up to 16 MiB. Each file is sliced into a number of these blocks, and the SHA256 hash of each block is computed. This results in a block list containing the offset, size and hash of all blocks in the file.

文件被分成块。构成一个文件的块都是相同的大小(除了文件中最后一个可能更小的块)。块大小取决于文件大小,从128 KiB 到16 MiB 不等。每个文件被分割成若干个这样的块,并计算每个块的 SHA256散列。这将导致一个块列表,其中包含文件中所有块的偏移量、大小和散列。

To update a file, Syncthing compares the block list of the current version of the file to the block list of the desired version of the file. It then tries to find a source for each block that differs. This might be locally, if another file already has a block with the same hash, or it may be from another device in the cluster. In the first case the block is simply copied on disk, in the second case it is requested over the network from the other device.

为了更新文件,Syncthing 将文件的当前版本的块列表与文件的所需版本的块列表进行比较。然后,它会尝试为每个不同的块寻找一个源。这可能是本地的,如果另一个文件已经有一个具有相同散列值的块,或者它可能来自集群中的另一个设备。在第一种情况下,块只是简单地复制到磁盘上,在第二种情况下,它是通过网络从其他设备请求的。

When a block is copied or received from another device, its SHA256 hash is computed and compared with the expected value. If it matches the block is written to a temporary copy of the file, otherwise it is discarded and Syncthing tries to find another source for the block.

当从另一个设备复制或接收一个块时,计算其 SHA256散列并与期望值进行比较。如果匹配的块被写入文件的临时副本,否则它将被丢弃,Syncthing 将尝试为该块寻找另一个源。

Scanning 扫描

There are two methods how Syncthing detects changes: By regular full scans and by notifications received from the filesystem (“watcher”). By default the watcher is enabled and full scans are done once per hour. This behaviour can be changed by folder. Increasing the full scan interval uses less resources and is useful for example on large folders that change infrequently. To make sure that not all folders are rescanned at the same time, the actual scan interval is a random time between 3/4 and 5/4 of the given scan interval. Even with watcher enabled it is advised to keep regular full scans enabled, as it is possible that some changes aren’t picked up by it.

Syncthing 检测更改的方法有两种: 通过定期的完整扫描和从文件系统(“观察者”)接收的通知。默认情况下,观察者是启用的,全部扫描每小时进行一次。可以根据文件夹更改此行为。增加完整的扫描间隔使用的资源更少,对于不经常更改的大型文件夹来说非常有用。为了确保不同时重新扫描所有文件夹,实际的扫描间隔是给定扫描间隔的3/4到5/4之间的随机时间。即使启用了观察器,也建议保持定期的完整扫描,因为有些更改可能不会被它拾取。

During a rescan (regardless whether full or from watcher) the existing files are checked for changes to their modification time, size or permission bits. The file is “rehashed” if a change is detected based on those attributes, that is a new block list is calculated for the file. It is not possible to know which parts of a file have changed without reading the file and computing new SHA256 hashes for each block.

在重新扫描期间(不管是完整的还是观察者的) ,将检查现有文件的修改时间、大小或权限位的更改。如果基于这些属性检测到更改,则该文件将被“重散列”,即为该文件计算一个新的块列表。如果不读取文件并为每个块计算新的 SHA256散列,就不可能知道文件的哪些部分已经更改。

The watcher does not immediately schedule a scan when a change is detected. It accumulates changes for 10s (adjustable by fsWatcherDelayS) and deleted files are further delayed for 1min. Therefore it is expected that you experience a slight delay between making the change and it appearing on another device.

当检测到更改时,观察者不会立即安排扫描。它累积10秒的更改(可由 fswatcher 延迟调整) ,被删除的文件进一步延迟1分钟。因此,在进行更改和在其他设备上显示更改之间,预计您会经历一个轻微的延迟。

Changes that were detected and hashed are transmitted to the other devices after each rescan.

每次重新扫描之后,检测到并散列的更改都会传送到其他设备。

Syncing 同步

Syncthing keeps track of several versions of each file - the version that it currently has on disk, called the local version, the versions announced by all other connected devices, and the “best” (usually the most recent) version of the file. This version is called the global version and is the one that each device strives to be up to date with.

Syncthing 跟踪每个文件的多个版本——当前在磁盘上的版本,称为本地版本,所有其他连接设备公布的版本,以及文件的“最佳”(通常是最新的)版本。这个版本被称为全局版本,是每个设备都努力追求的最新版本。

This information is kept in the index database, which is stored in the configuration directory and called index-vx.y.z.db (for some version x.y.z which may not be exactly the version of Syncthing you’re running).

此信息保存在索引数据库中,该数据库存储在配置目录中,称为 index-vx。Db (用于某些版本的 x.y.z,该版本可能不完全是您正在运行的 Syncthing 的版本)。

When new index data is received from other devices Syncthing recalculates which version for each file should be the global version, and compares this to the current local version. When the two differ, Syncthing needs to synchronize the file. The block lists are compared to build a list of needed blocks, which are then requested from the network or copied locally, as described above.

当从其他设备接收到新的索引数据时,Syncthing 会重新计算每个文件的哪个版本应该是全局版本,并将其与当前的本地版本进行比较。 当两者不同时,Syncthing 需要同步文件。将块列表进行比较,以构建所需块的列表,然后从网络请求这些块或在本地复制这些块,如上所述。

Syncthing - P2P文件同步工具 - 快速开始相关推荐

  1. Syncthing - P2P文件同步工具使用

    1 简介 随着数据的增长,我们对于文件的同步和备份需求也日趋强烈.各种网盘为我们在文件同步备份提供便利的同时,也在速度.安全和隐私等方面带来不小的限制和风险. Syncthing是一款开源免费跨平台的 ...

  2. 用树莓派搭建全功能NAS服务器(06):自带穿透的文件同步工具

    写在前面 说完了nextcloud,大家已经对于个人网盘不再陌生.但想要做到随时随地同步文件,还需要公网IP/内网穿透. 其实说到文件同步,还有一款自带内网穿透的P2P文件同步工具必须介绍一下,就是s ...

  3. 4.2w Star的文件同步工具,比VIP网盘还好用!

    关注TJ君,回复"武功秘籍"免费获取计算机宝典书籍 昨天圣诞夜TJ君却做了一件烦心的事情,是什么事情呢? 其实就是TJ君平时有时候会偷懒,把微信当作存储工具,一些小伙伴传过来的文件 ...

  4. Syncthing-P2P文件同步工具学习

    Syncthing-P2P文件同步工具学习 简介 windows安装 其他 linux安装 linux vps安装配置 linux vps内安装syncthing 简介 开源的文件同步工具,基于P2P ...

  5. Syncing文件同步工具(详解)

    简介: Syncthing是一种开源的文件同步工具,旨在实现跨多个设备之间的安全和私密的文件同步.它提供了一种去中心化的方法来同步文件,并通过点对点(P2P)技术直接在设备之间进行通信,而无需传统的云 ...

  6. linux有哪些实时同步工具,rsync文件同步工具常见模式有哪些?linux系统

    互联网时代发展迅速,Linux运维技术的需求更多推进不少.市场对于Linux运维人才的需求也在逐渐加大.Linux行业崛起,在云计算大环境下,市场上对高级运维人员的需求将越来越大.文件同步工具rsyn ...

  7. Linux日常运维管理技巧(四)文件同步工具-rsync、Linux系统日志、dmesg命令、lastb命令查看登录失败的用户、screen工具虚拟屏幕

    目录 Linux文件同步工具-rsync Linux系统日志 dmesg命令 lastb命令 screen工具 Linux文件同步工具-rsync rsync命令是一个远程数据同步工具,可通过LAN/ ...

  8. 远程文件同步工具--rsync

    远程文件同步工具--rsync rsync rsync同步简介 rsync同步方式 配置源的两种方法 rsync常用命令 rsync实验 1.本地复制 2.远程复制 1.配置rsync服务器 2.为备 ...

  9. 遥望星空FTP文件同步工具(附源码)1.0 发布

    FTP文件同步工具1.0 发布 主要功能: 1.支持多任务多线程 2.支持自动启动 3.支持2种时间触发方式 4.支持任务进度显示 5.支持WinFtp Server.ftpserver.exe.Se ...

最新文章

  1. win 64位系统安装带有c编写的python模块出现ValueError: [u'path']解决
  2. html 传参数 菜单自动展开,【HTML5】Jquery打造竖向伸缩/展开菜单
  3. VHDL硬件描述语言(二)——子程序
  4. 3维DEMO: 抽奖圆盘
  5. 机器学习中的度量—— 向量距离
  6. linux mysql导出乱码问题_[MYSQL]将数据从5.0版本导入到4.1.7版本中出现乱码问题解决方案...
  7. VMware虚拟机克隆或复制linux后无法上网的解决方案
  8. 同济大学《高等数学》上册答案
  9. 苹果录屏没声音_通过AppleALC,轻松解决黑苹果没声音问题
  10. Linux之/etc/fstab文件详解及实践
  11. 计算机无法写入U盘,电脑无法拷贝U盘文件怎么办|解除U盘写保护设置的方法
  12. 基于SVPWM的无刷直流电机矢量控制系统研究
  13. 数字电路28(设计步骤及十进制加计数器设计)
  14. 解决计算机主机与打印机共享,教您解决打印机无法共享的方法
  15. 数字电视机顶盒的工作原理
  16. html星空炫彩粒子,炫彩粒子模拟器游戏
  17. 如何选择一款最好的硬盘对拷工具
  18. 消耗cpu资源的脚本
  19. (一)mplayer与ffmpeg的调用过程
  20. 逻辑回归模型在R中实践

热门文章

  1. Python中Dataframe通过print输出多行时显示省略号
  2. 开启电脑自带的远程控制
  3. 二分法实例应用(一)
  4. 程序设计天梯赛选拔 大炮打蚊子(刷水题就变傻,确实,感觉自己变傻了)
  5. Android Studio 实战干货例程
  6. maven指定本地仓库
  7. element-ui快速使用(使用element-ui做一个表格)
  8. Monitor(管程)是什么意思?Java中Monitor(管程)的介绍
  9. ListView实现item局部刷新
  10. python里面的爬虫爬取网页