Hi Guys.
I've been given the task to create a load balanced high availability apache webserver. Since I didn't have any experience with this I investigated several projects suchs as Linux-HA, Heartbeat, Linux Virtual Server and ldirectord.
The examples and tutorials I found were all based on 4 servers:
- Server1: Main load balancer
- Server2: Backup load balancer
- Server3: Apache1
- Server4: Apache2
Based on the tutorials that I read, things looked pretty straightforward. However, I have been experiencing some problems, which I think, are due to the fact that I only have two servers:
- Server1: Main load balancer + Apache1
- Server2: Backup load balancer + Apache2
I have a virtual IP address 172.16.0.50 which eventually redirects to either server1 (172.16.0.30) or server2 (172.16.0.40).
I can see that the heartbeat infrastructure works, as server2 takes over from server1 if the latter goes down and vice versa. I can tell by executing:
It shows that the network card now has the virtual IP address (172.16.0.50) assigned, which was not the case when the main server was active.
Now according to the manuals I have read, I need to assign the virtual IP address to an alias on localhost, in order for the apache servers to accept traffic on the virtual IP.
Code:
ifconfig lo:0 172.16.0.50 netmask 255.255.254.0
ifconfig now shows that alias lo:0 has the virtual IP address.
For clarity, this is the current setup:
Code:
Server1:
eth0: 172.16.0.30
lo:0 172.16.0.50
Server2:
eth0: 172.16.0.40
lo:0 172.16.0.50
Now I have 2 problems:
1. The next time I start heartbeat, it fails to start because the virtual IP address already exists. After I remove alias lo:0, heartbeat starts normally again. But then I need to create the alias again, otherwise apache is not able to accept any connections.
2. When the apache server which resides on the same server as the load balancer goes down (server1), then heartbeat (ldirectord actually) sets apache2 on server2 as the main one. In this setup I'm unable to connect to the apache server through the virtual IP address.
Could it be that the linux internal routing is still trying to forward the traffic to the apache server that is down, due to the fact that the localhost alias lo:0 is still active?
server1 (has virtual ip set on lo:0) ---> apache2 (on server2)
Any help is kindly appreciated.
Thanks.
P.S.: I'm not able to post any config files atm since I'm not in front of the server. I will be able to do so in a couple of hours, if necessary.