Veroeros amet dolor
When creating a production LAMP environment, ensuring maximum uptime requires creating a fault tolerant environment. Fault tolerance should be attained at all levels of the stack, but today I’ll be focusing on the web layer.
One way of achieving this is to use Apaches built in Load Balancer, mod_proxy_balancer. Or another option would be to use round robin DNS. The preferred way would be to use a commercial load balancer.
The objective is to have a multiple node web layer, that is getting traffic distributed evenly across all nodes. In the event that all the nodes fail, you should have a failover mechanism that sends traffic to another cluster. If not there should be a redirect in place that will redirect the user to a maintenance page; and this should happen all happen automatically. The ultimate goal is to never have a DOS (denial of service) situation presented to the customer.
Most commercial load balancers allow you to check if a host is available by various methods. The most simple would be a ping check. A better method would be a port check. (Port 80 in this case) The best way would be to do a content check. You should create a static page that is very small in size, and the page should contain a simple phrase such as “content_check_ok” or “keepmeinthepool”. If the application depends on a database, the content page should do a simple database query and display your OK phrase if the query was successful. This will enable the load balancer to do a quick end to end test every time it checks the host.
For example, if you are using a F5 BigIP Load Balancer, then you would do this by creating a HTTP profile for your servers. Your profile would have the Fallback Host setting enabled, and the fallback host should be your maintenance page. (i.e. http://elysol.com/temp_maint.html) You need to set up a HTTP monitor that has a “Send String” of “GET /status/monitor_check.pl HTTP/1.0 “ and a “Receive String” of “keepmeinthepool” or whatever string that you are returning. Finally you should set your new Virtual Server or (Virtual IP) to use this new HTTP monitor and HTTP profile.
You can use PHP or a simple perl script in you cgi-bin directory. I prefer to use perl, as most linux distros already have perl installed. If you need to install PHP on your web server just for this, it probably isn’t worth it. Below is a quick perl script you can use that will :
*Don't forget to create the database! an mysql statement like... "create database testdb;grant all on testdb.* to testuser identified by 'testpw';flush privileges;" will suffice.
**Disclaimer- there are many ways to do this. Some people may argue that you shouldn't create a table and that you shouldn't create data to test- as it can be destructive. My argument is that you should create something, as you need to know if the database/filesystem has dropped into read only mode. But there may be repercussions- (for example recovering space from an innodb database) Please do your research and consult a DBA!
################