Skip to content

How to Build HA/LB LAMP Cluster

June 5, 2009
How to Build HA/Load-Balanced LAMP Cluster

In this article i will tell my experience with building a High-Availability Load Balanced Linux+Apache+PHP+MySQL Cluster using 2 web servers + 2 DB servers.

first of all i would like to say ” Many Thanks Sun Microsystems for the great work and projects you are always donating to FOSS world and my Best wishs”, I used the great virtualization platform VirtualBox or Sun XVM to do the lab for this project.

I advice every one who want to test Clustering or HPC to use VirtualBox get it here it’s very easy to use and its perfomance is the best.

Cluster Description:
This cluster will contain 4 nodes as follows:
– 2 x Apache servers configured as Active/Active load-balanced cluster.
– 2 x MySQL servers configured as Master/Slave with Replication and also as Active/Active Load-Balanced Cluster !!! 😉 .

The Distro. used in this project is CentOS and the real project contained a SAN storage with 2TB Disk space divided as 1TB for backup, 400GB for each MySQL Server and 200 GB shared Document Root between Apache web servers and formated as GFS2.

here i would like to say “Many Thanks to the Great Red Hat company, without your great support to FOSS and specially to GNU/Linux there will never be this great HA/Clustering platform.

It’s almost easy to do this project using Conga and/or system-config-cluster utilities, i used these tools to configure the cluster storage only as there’s no need to configure fail-over’d services because the whole cluster will be load-balanced.

the most problematic part is the Piranha and LVS configuration part, till now i can’t configure load-balancing using piranha nor /etc/sysconfig/ha/lvs.conf.

the easiest way for me was configuring every thing from the command line using ipvsadm and iptables then make changes permanent by saving them to /etc/rc.local .

to do this cluster using virtual machines, i did make 2 CentOS virtual machines !!, yes only 2 my laptop can’t run fine with more than 3 VMs 😉 .
one will be publicly accessible from WAN which acting as Load-Balancer + router + web server + DB server.
the other will be web server + DB server.

the configuration goes like the following:
– configure Apache on the 2 nodes ( i did configure it on the 2nd node to use an exported NFS DocRoot form node1).
– configure MySQL Replication on the Master (node1) and the slave (node2).
– configure ip_forwarding on 2 nodes.
– configure firewall masquerading and NAT on the first node
– set node1 as the default gateway to node2
– set the virtual IP on node 1 using an alias/virtual network interface or using iproute2
– use ipvsadm to set the virtual server and real servers and load balancing algorithm

you will have to this for Apache and MySQL so you’ll have to have 2 virtual services assigned to one virtual server.

and it’s done 😉 now you can use a PC on the WAN of node1 to check the cluster.

I know you’re saying WTF is this shit where’s the configuration and commands :), it’ll be here soon.

To Be Continued and detailed….

Powered by ScribeFire.

Advertisements
One Comment leave one →
  1. Gabriel permalink
    September 16, 2011 9:35 pm

    Hello, i’m doing a work for university in wich i have a high-available LAMP application.
    Is it possible to have only 2 identical physical servers, having each one of them some linux distro with LVS running and 2 virtual machines: one for the apache and another for mysql?
    the database files would be located in a NAS connected to the same LAN as both servers.

    i’ve seen a lot of articles about LVS with LAMP but they all use dedicated hardware (main and backup) for the LVS. I want to avoid that and have the servers to balance themselves, similar as you did with your notebook.

    Do you think that’s possible? And recommendable for a high-availability application?
    How would you archieve that?

    Many thanks

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: