Configure Syncthing. Blue electrical tape in small business and home
- Tutorial
I suddenly had a syncthing tuning guide lying around. I am sure that this can come in handy for many.
About the revolution in file distribution made by the torrent protocol to tell too much. The classic version of the technology had one problem - static. If the data in the directory changed, you had to re-create and transfer to everyone a new torrent file. And suddenly, all of a sudden, BitTorrentSync appears. There is universal happiness, now you can synchronize entire arrays of changing data. However, over time, proprietary software translates into a strong reduction in functionality, binding to its servers and quite aggressive monetization. This is where the ideologically kosher free successor - Syncthing - enters the scene.
Syncthing, like regular torrent, can crawl through almost any barrier in the form of firewalls, NAT, and the like. In the case of gray IP addresses, relies on centralized relays and announcement servers. At the same time, you can safely raise them yourself, which gives complete independence from the infrastructure of developers. All nodes in the cluster are peers. You can specify two-way and one-way synchronization when changes to deleted copies do not affect the original. Able to versioning. Beauty, in a word.
In my case, the task of creating daily backups of the databases was solved. 3 independent branches in different parts of the city. Internet via Yota-modem, stuck in Mikrotik. The channel is narrow and unstable in width. The main idea that was implemented was the exchange of copies of the databases on the basis of the torrent protocol at night, when the load on the network is minimal and no one is touching the database. As a result, each unit stores copies of two neighboring ones. Good redundancy and geographical distribution, which once saved once, when the server was suddenly killed by a lightning strike.
Install. By default, I mean a server based on deb-based Linux, although syncthing also has versions for Windows and Android. For production, add the repositories from the stable branch and install:
# 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
Now we need to deal with the demons. Such software should not work as root. All files created as a result of synchronization must belong to the local user. Therefore, there are two options - automatic launch as a system service or as a user service. The second option will work only when the user logged in via ssh or logged in to the local system. We are interested in the system daemon and for this, the publicd systemd, beloved by the public, is best suited. The paths may vary slightly between distributions. This manual applies to Debian and Ubuntu 16.04 Server. To start, create a unit:
sudo nano /etc/systemd/system/syncthing@.service
And we add the following contents there: Now it remains only to activate the service on behalf of the desired user and you can configure the node.
[Unit]
Description=Syncthing - Open Source Continuous File Synchronization for %I
Documentation=man:syncthing(1)
After=network.target
Wants=syncthing-inotify@.service
[Service]
User=%i
ExecStart=/usr/bin/syncthing -no-browser -no-restart -logflags=0
Restart=on-failure
SuccessExitStatus=3 4
RestartForceExitStatus=3 4
[Install]
WantedBy=multi-user.target
sudo systemctl enable syncthing@username.service
sudo systemctl start syncthing@username.service
The interface is available at 127.0.0.1:8384. If you want to log in from another machine, you will have to fix the ~ / .config / syncthing / config.xml config. Further settings are extremely simple - trusted nodes are added using a unique key, and then the necessary directories are shared in the mode of one- or two-way synchronization. If necessary, you can manually specify the ip address and port of the node; without this, a network of announcement servers and relays will be used to establish communication. Moreover, you can raise announcements and relays on your infrastructure, which allows you to use the software in the framework of a branched LAN of the company.
At any time, you can conveniently view the list of synchronized files. Extremely useful and easy to configure turned out software. Consumes resources economically enough. Right now, in standby mode, eating about 15 megabytes of RAM and a fraction of a percent of the processor time. The total amount of data in the cluster in the region of 500 GB.
Good luck to everyone in the experiments. Durable electrical tape.
Update 1
Thanks datacompboy . Found an interesting flag to ignore deletion in the master node.
ignoreDelete is an advanced folder setting that affects the handling of incoming index updates. When set, incoming updates with the delete flag set are ignored.
Some problem is that from the point of view of other nodes, this will be out of sync.
Assume two devices, “Alice” and “Bob”, are sharing a folder. Bob has set ignoreDelete..
New and updated files are synchronized as usual between Alice and Bob. When Bob deletes a file, it is deleted for Alice as well. When Alice deletes a file, Bob ignores that update and does not delete the file.
In this state, Bob is fully up to date from his own point of view, as is Alice from her own point of view.
However from the point of view of Alice, who deleted a file and propagated the update, Bob is now out of date because he is yet to remove the file that was deleted.
From the point of view of Bob, who ignored the delete entry from Alice, Alice is now out of date because she is missing the file that was deleted
Update 2
Supplement from Stam_emg .
In order to automatically confirm customers, you can do this:
It is necessary to enable Introducer mode on the distributing server, then when adding a folder on the client, it will be added to the server without confirmation.
docs.syncthing.net/users/introducer.html