Nginx – Setting Up a Load Balancer on VPS with Replication

haproxyMySQLnginxvps

I'm looking for some expert advice on how to go about setting up a load balancer across a VPS, configuring two other VPS for PHP/MySQL replication and then linking them together. I've looked into HAProxy and Nginx, both of which are fairly straight forward to setup – just a few queries I'd love anybody to help answer:

1) Currently I'm running a single VPS, it's specs are: (Knownhost, VPS #7)

5632MB Guaranteed RAM
150GB RAID-10 Disk Space
8x Priority 8+ CPUs
10000GB Premium Bandwidth

I'm looking at purchasing two additional VPS' that are mid-spec of my main VPS – so would I want to install the load balancer on the most powerful VPS, thus my primary one at the moment?

2) Once I have the load balancer setup, and I know the IPs of my other VPS' – am I right in assuming I just configure the load balancer to them IPs? How do I then go about the code replication and database replication? Would the load balancer become the master DB, or would I assign one of the other VPS' for this?

3) In terms of scalability, if the code is updated on A, would I consequently update it on B and C? Or do I need some sort of automatic replication utility setup?

I'm not well-versed in servers or hardware, so I appreciate any help.

Thank you!

Best Answer

In a 3 server setup I would personally consolidate the db server and any other backend services to 1 machine and use the 2 lesser VMs as frontend nodes. DRBD could be used to failover a "primary" IP between your nodes and can also be used to replicate shared storage between the systems. Nginx would be used to proxy webtraffic between the 2 web frontends.