Syncthing - P2P文件同步工具 - 快速开始

一、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 需要同步文件。将块列表进行比较,以构建所需块的列表,然后从网络请求这些块或在本地复制这些块,如上所述。

Windows 安装版 1.5.0 beta 大小:4.4MB 更新:2014-12-20 XP/Vista/Win7/Win8 自同步是一款由国内创业团队推出的局域网P2P免费文件同步工具。处在同一个局域网下的多台电脑,可通过自同步来建立电脑里文件夹之间的同步关系,做到文件夹中文件的数量、内容相一致,并且不需要云和外网。此外,自同步特有的密钥加密更保证了数据的安全性。并且,其特有的分享功能又可以做到轻轻松松将同步目录分享给周围的朋友们。 软件特点 1. 无需网盘,局域同步 与市面上流行的网盘不同,自同步不需要您的设备时时刻刻连接互联网完成文件同步工作,而只需要在同一个局域网内就能完成文件同步工作。 2. 实时同步,多台互联 处于同步中的目录,只要其中一个目录发生变化,如文件/目录添加、修改、删除等操作,那么与该目录建立同步关系的其它目录也会迅速反应,进行相应的修改,保持与原目录的文件一致;此外,只需将文件放到同步目录,程序将自动上传这些文件,同时其它电脑登陆自同步时自动下载到新电脑,实现多台电脑的文件同步。 3. 目录分享,轻松同步 同步目录分享功能,可以轻松将同步目录分享给周围的朋友(无需同步口令相同)。 4. 密钥加密,保护数据 在局域网内采用AES加密方式传输数据并建立密钥,防止处于同一局域网内的非法设备窃取数据。 5. 优化传输,极速速度 千兆路由的局域网环境下传输速度最高可达70MB/s,同步过程犹如硬盘间的复制粘贴一样方便快捷。
Android 1.5.1 beta 大小:6.3MB 更新:2014-12-24 Android 4.0.4 自同步是一款由国内创业团队推出的局域网P2P免费文件同步工具。处在同一个局域网下的多台电脑,可通过自同步来建立电脑里文件夹之间的同步关系,做到文件夹中文件的数量、内容相一致,并且不需要云和外网。此外,自同步特有的密钥加密更保证了数据的安全性。并且,其特有的分享功能又可以做到轻轻松松将同步目录分享给周围的朋友们。 软件特点 1. 无需网盘,局域同步 与市面上流行的网盘不同,自同步不需要您的设备时时刻刻连接互联网完成文件同步工作,而只需要在同一个局域网内就能完成文件同步工作。 2. 实时同步,多台互联 处于同步中的目录,只要其中一个目录发生变化,如文件/目录添加、修改、删除等操作,那么与该目录建立同步关系的其它目录也会迅速反应,进行相应的修改,保持与原目录的文件一致;此外,只需将文件放到同步目录,程序将自动上传这些文件,同时其它电脑登陆自同步时自动下载到新电脑,实现多台电脑的文件同步。 3. 目录分享,轻松同步 同步目录分享功能,可以轻松将同步目录分享给周围的朋友(无需同步口令相同)。 4. 密钥加密,保护数据 在局域网内采用AES加密方式传输数据并建立密钥,防止处于同一局域网内的非法设备窃取数据。 5. 优化传输,极速速度 千兆路由的局域网环境下传输速度最高可达70MB/s,同步过程犹如硬盘间的复制粘贴一样方便快捷。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

西京刀客

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值