0

First of all, i'm sorry if this question has been answered before, but i've been searching for a while now and couldn't seem to find (or understand) an answer.

So, i have two physical servers with centOS on them. 1 of them is already hosting some websites and databases. Now i want to make a redundant environment by using load balancing with failover. so basically, i want to have both servers running, dividing the work by the amound of connections that are open at that moment and when 1 of them crashes let the other server take over all the work.

Every example i came across had a 3th server for haproxy in front of 2 webservers. But would it be possible with just the 2 servers (by installing haproxy on both webservers for example)? Or is there a better way of handling this problem?

thanks in advance.

Lars Behrens
  • 53
  • 1
  • 6

2 Answers2

1

There are multiple solutions for this.

The easiest setup is probably this:

  • Synchronize website data between the servers with DRBD

  • Run a MySQL master-slave set-up between the 2 servers. This will mean all database connections will go to one server. If that one fails, you have to switch to the slave (and promote it to master). You can automate this. Master-master replication is probably too much work, unless you are also the developer on all websites.

  • Do round-robin DNS loadbalancing (works fine with most new browsers, it will keep trying until it found a working IP). The other solution is using HAProxy. In that case one server will also act as the loadbalancer for both servers. You can use a keepalived to automatically switch to the second HAProxy instance (on server 2) when the primairy goes down.

Jeroen
  • 1,341
  • 7
  • 16
0

I'm not sure that I would call DRBD easy, awesome maybe but not easy. As suggested by Jeroen: Round robin DNS or HAProxy can be used to route the traffic to both nodes, but yes your actual problem is that your database is only in one place. So hitting both servers may not be what you want. DRBD would ensure storage is replicated between the servers (solving the problem). Or the standard architecture is 2*HAProxy in front of N+1 Web Servers with the database on a separate and highly available platform (maybe master/slave maybe shared storage maybe DRBD or maybe memched).

  • True, DRBD is not that easy. It is however one of the very few ways to keep directories in sync realtime. What I do all the time is 2 HAProxy servers infront of about 10 webserver and multiple mysql master-slave clusters behind it. For storage I use (redundant) centralized storage (ZFS). – Jeroen Sep 02 '15 at 09:51
  • Thanks guys for replying. It was very helpfull. I'm going for a single Haproxy server (later on i'll probably use a failover with keepalived). i'll sync my webcontent with unison and fsmonitor.py for realtime syncing, and using the master-slave setup for mysql. – Lars Behrens Sep 04 '15 at 07:41