Beruflich Dokumente
Kultur Dokumente
Directory
Helpdesk
Contact Us
Login
CTRIP
Home People News Articles Publications Funded Projects Services Collab Tools
Search
192.168.1.1 [ loadb1 ] 192.168.1.2 [ loadb2 ] 192.168.1.3 [ apachenode1 ] 192.168.1.4 [ apachenode2 ] 192.168.1.5 [ apachenode3 ] 192.168.1.99
In this example, we will use 5 Debian Lenny servers. You should start with a clean operating system installation for this tutorial. All steps below should be performed as root unless otherwise specified.
Configure the apache servers to log the original IP of the visiting user. Since we're using load balancers, by default the IP address of the load balancer would be used. Thus, causing problems when we want to log visits for statistics and other purposes.
nano /etc/apache2/apache2.conf
Locate the following line, comment it out with # and add new line as shown below. Make sure the line is on one line in the file unlike shown here: #LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\"... LogFormat "%{X-Forwarded-For}i %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined Create a haproxytest.txt file in the webroot directory. HAProxy will use this file as a test to see if the server is running and accessible. If it is inaccessible, HAProxy will know the server is down and will redirect traffic to the remaining Apache nodes.
touch /var/www/haproxytest.txt
Since this file will be accessed many times per minute, we don't want to log access to it. Therefore, we need to edit the virtual host file.
nano /etc/apache2/sites-available/default
Add the following and comment out any other "CustomLog" lines in the file. SetEnvIf Request_URI "^/haproxytest\.txt$" dontlog CustomLog /var/log/apache2/access.log combined env=!dontlog Restart apache for your settings to take effect.
/etc/init.d/apache2 restart
global log 127.0.0.1 log 127.0.0.1 #log loghost maxconn 4096 #debug #quiet user haproxy group haproxy local0 local1 notice local0 info
defaults log global mode http option httplog option dontlognull retries 3 redispatch maxconn 2000 contimeout 5000 clitimeout 50000 srvtimeout 50000 listen webfarm 192.168.1.99:80 mode http stats enable stats auth someuser:somepassword balance roundrobin cookie JSESSIONID prefix option httpclose option forwardfor option httpchk HEAD /haproxytest.txt HTTP/1.0 server apachenode1 192.168.1.3:80 cookie A check server apachenode2 192.168.1.4:80 cookie B check server apachenode3 192.168.1.5:80 cookie B check
nano /etc/default/haproxy
ENABLED=1
nano /etc/sysctl.conf
Change to:
net.ipv4.ip_nonlocal_bind=1
sysctl -p
Edit authkeys.
nano /etc/ha.d/authkeys
Add the following and replace "somerandomstring" with a string of unique characters. This file must be identical on loadb1 and loadb2.
nano /etc/ha.d/ha.cf
# # keepalive: how many seconds between heartbeats # keepalive 2 # # deadtime: seconds-to-declare-host-dead # deadtime 10 # # What UDP port to use for udp or ppp-udp communication? # udpport 694 bcast eth0 mcast eth0 225.0.0.1 694 1 0 ucast eth0 192.168.1.2 # What interfaces to heartbeat over? udp eth0 # # Facility to use for syslog()/logger (alternative to log/debugfile) # logfacility local0 # # Tell what machines are in the cluster # node nodename ... -- must match uname -n node loadb1.example.com node loadb2.example.com
nano /etc/ha.d/ha.cf
# # keepalive: how many seconds between heartbeats # keepalive 2 # # deadtime: seconds-to-declare-host-dead # deadtime 10 # # What UDP port to use for udp or ppp-udp communication? # udpport 694 bcast eth0 mcast eth0 225.0.0.1 694 1 0 ucast eth0 192.168.1.1 # What interfaces to heartbeat over? udp eth0 # # Facility to use for syslog()/logger (alternative to log/debugfile) # logfacility local0 # # Tell what machines are in the cluster # node nodename ... -- must match uname -n node loadb1.example.com node loadb2.example.com
nano /etc/ha.d/haresources
loadb1.example.com 192.168.1.99
nano /etc/ha.d/haresources
loadb2.example.com 192.168.1.99
/etc/init.d/haproxy stop
Now try loading your web site. If it loads, then the node failed over to the secondary load balancer. Let's start the primary back up.
/etc/init.d/haproxy start
/etc/init.d/apache2 stop
/etc/init.d/apache2 stop
Now you should still be able to browse your site, knowing the first 2 nodes are down. The third node should be handling the requests. Let's start our web servers back up: apachenode1: Start apache2.
/etc/init.d/apache2 start
/etc/init.d/apache2 start
Conclusion
Configuring an Apache2 cluster in this way eliminates a single point of failure. This allows you to disable servers for maintenance without any down time. Something not covered in this article is critical. Your three Apache servers should be mirrors of each other. Therefore, you need to come up with a solution for making sure your files are consistent on all three web servers including your Apache configuration files. This can be done by using RSync. Also, if your application uses sessions for allowing Logins, you must store the sessions in a database. If you do not, sessions will be lost as users are bounced around to the different Apache nodes. Back to Introduction | Cluster Part 2: Howto Build a MySQL Cluster in Debian Lenny Author: Narayan D. Raum Group: Software Design & Engineering
2011 University of Florida, Gainesville, FL 32611 College of Medicine | Health Science Center | Disclaimer & Permitted Use | Security Policies | Privacy Policy | Social Security Number Privacy Report problems with this site.