@rafacorre
The configuration file for lsyncd
would look something like this for multiple servers. The following is an example of what you’d use on the “master” server, or the primary.
/etc/lsyncd/lsyncd.conf.lua
settings = {
logfile = "/var/log/lsyncd/lsyncd.log",
statusFile = "/var/log/lsyncd/lsyncd.status"
}
targetlist = {
"root@DROPLET_IP_02:/path/to/data",
"root@DROPLET_IP_03:/path/to/data"
}
for _, server in ipairs( targetlist ) do
sync {
default.rsync,
source = "/path/to/data",
target = server,
rsync = {
rsh = "ssh -i ~/.ssh/id_rsa"
}
}
end
In the above:
DROPLET_IP_02
and DROPLET_IP_03
would be the IP’s or Hostnames of the Droplets that you’d be mirroring data to.
/path/to/data
under targetlist
would be the path where all content to be mirrored.
/path/to/data
under source
is the path to where the data to be mirror exists.
rsh = "ssh -i ~/.ssh/id_rsa"
would need to be changed to the location of the private key that you’ll be using to login to the other servers.
…
If the source and destination are both the same (as would be the case in most configurations), then you’d just change /path/to/data
to be the same in all three instances.
…
As an important note, you will need to use ssh-copy-id
or physically login to the servers from one another to get the initial setup done. If you don’t, the connection will fail as initial authentication has to be done first.
…
I just tested the above configuration using a DigitalOcean LB and 3x 1GB Droplets and it does work, though I’ve not setup multi-directional syncing just yet. To do this, the same configuration would essentially exist on each server with lsyncd
installed on each.
You would need to change the root@DROPLET_IP
to make sure each sever syncs to the correct server and that ~/.ssh/id_rsa
is correctly set for each one as well.
So is it flat files, databases or ?
If it’s databases, then you want master-master replication like MariaDB Galera.
If it’s flat files, then it depends on how important the lag is. So if it needs to be real time use something like GlusterFS. If a few seconds delay is okay, then Syncthing or rsync might be a solution.
Hi @hansen, thakyou very much!
I thought of replicating only the files, I did not know this option of MariaDB Galera.
I was thinking of doing something similar to what I saw on Amazon, I wanted to leave the database and the images in separate locations of the web server.
And then I would replicate the files from this server to other droplets.
I will test Syncthing and rsync also to see which of these options meet my needs.