Score:0

Synchronizing load balanced Linux servers

me flag

I want to load-balance two dedicated linux servers, I'm planning to do that using round robin DNS, but I can't find a way to synchronize the servers to be identical. The servers are running a perl script (minimum change) and I think it's possible to synchronize that with a simple bash script of rsync on a cron job. But the problem is that script depends on a mariadb database that changes a lot and I don't think it's possible to run rsync on two running mysql databases because it will create conflicts in the destination server.

I think it's possible to connect the second server to the first server's database remotely but that doesn't actually balance the load because the first server will have to process the queries of two servers.

Is there a simple solution I'm missing?

Score:0
za flag

Yes, there is a better solution. A proper load balancer in front of your servers.

Any load distribution without feedback like DNS round-robin does spread the load but can't possibly do this evenly. To have an even load on all backend servers, you need to have a load feedback from servers to the balancer so it knows the actual load on each back end and can use that info when it decides where to send the connection.

Also notice that in master-slave configuration it is impossible to load master and slaves the same way, due to different roles they perform. MySQL/MariaDB has a Galera multi-master cluster solution, where it is possible to distribute load evenly.

Lastly, DNS "load balancing" is susceptible to easy bypass. One can simply use a literal IP address of one of servers instead of DNS name and they will always load that server. With a proper load balancer, it is impossible, since only balancer's IP can be made available for connections so it always able to decide where to forward the connection.

Try haproxy; for your case you'll obviously need a TCP mode and an agent (a simple script with a simple protocol) running on each backend which will be queried regularly by the balancer to obtain information about that server's current load. Start here for the basic setup, and then you'll need to create an agent and add agent-check to haproxy configuration.

I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.