I am currently working on a web cluster project using CentOS. In this project, I have 2 web servers running on Apache and mounted the same document root to serve the HTTP content. I also have 2 servers in front of it to become the load balancer and failover to increase high availability of the two-node web server cluster. The virtual IP will be hold by load balancer #1 with auto failover to load balancer #2.
You may refer to diagram below to get clearer picture:
I am using following variables:
All servers’ OS: CentOS 6.2 64bit
Web server #1: 192.168.0.221
Web server #2: 192.168.0.222
Load balancer #1: 192.168.0.231
Load balancer #2: 192.168.0.232
Virtual IP: 192.168.0.220
Load Balancer Server
1. All steps should be done in both servers unless specified. We will install Piranha and other required packages using yum:
2. Open firewall ports as below:
- Piranha: 3636
- HTTP: 80
- Hearbeat: 539
4. Run following command to set password for user piranha. This will be used when accessing the web-based configuration tools:
5. Turn on IP forwarding. Open /etc/sysctl.conf and make sure following line has value 1:
And run following command to activate it:
Load Balancer #1
1. Open Piranha web-based configuration tools at http://192.168.0.231:3636 and login as piranha with respective password. We start with configuring Global Settings as below:
2. Then, go to the Redundancy tab and enter the secondary server IP. In this case, we will put load balancer #2 IP as the redundant server in case load balancer #1 is down:
3. Under Virtual Servers tab, click Add and enter required information as below:
4. Now we need to configure the virtual IP and virtual HTTP server to map into the real HTTP server. Go toVirtual Servers > Real Server and add into the list as below:
Make sure you activate the real server once the adding completed by clicking the (DE)ACTIVATE button.
5. Now copy the configuration file to load balancer #2 to as below:
6. Restart Pulse service to apply the new configuration:
You can monitor what is happening with Pulse by tailing the /var/log/message output as below:
Load Balancer #2
No need to configure anything in this server. We just need to restart Pulse service to get affected with the new configuration changes which being copied over from LB1.
If you see the /var/log/message, pulse in this server will report that it will run on BACKUP mode.
Web Servers
1. Since we are using direct-routing method, regards to your Apache installation, we also need to install another package called arptables_jf. Here is some quote from RedHat documentation page:
Using the arptables_jf method, applications may bind to each individual VIP or port that the real server is servicing. For example, the arptables_jf method allows multiple instances of Apache HTTP Server to be running bound explicitly to different VIPs on the system. There are also significant performance advantages to usingarptables_jf over the IPTables option.However, using the arptables_jf method, VIPs can not be configured to start on boot using standard Red Hat Enterprise Linux system configuration tools.
We will instsall using yum:
2. Configure arptables_jf by executing following command:
In web server #1:
In web server #2:
3. Save the arptables rules and make sure the service is started on boot:
4. Add the virtual IP address in the servers:
5. Since the IP cannot be started during sysinit (boot time), we can automatically start the IP after sysinit complete. Open /etc/rc.local using text editor:
And add following line:
Warning: Every time you restart your network service, please make sure to run step #4 to bring up the virtual IP in real server.
Done. You can now point your website to the virtual IP and you will see that the load balancer #1 will report as below:
0 comments:
Post a Comment