what the blog?

{upgrade in progress..}

Apache Web Load Balancing howto

Setup Overview

A apache load balancer www.mydomain.com setup for redirect incoming request to two underlying web server www1.mydomain.com, www2.mydomain.com.

Hosts

Host#1 www1.mydomain.com: 192.168.1.1
Host#2 www2.mydomain.com: 192.168.1.2
The apache load balancer instance www.mydomain.com running on RedHat Cluster floating IP 192.168.1.3 or you can activate it on either one server using IP alias without using Cluster Suit.

Load balancer setup www.mydomain.com

Parameters Value Description
ProxyPass balancer://<NAME>/ Define your cluster name
stickysession BALANCEID | PHPSESSIONID | JSESSIONID Define your preferred session sticky method,
BALANCEID likely by source IP

PHP|JSESSIONID require to add extra session header on the node member web server

nofailover On | Off If your web servers do not support session replication, turn this flag on in order to NOT failovering the current session to other member while the node is failed.
route node name
lbmethod byrequests | bytraffic | bybusyness
ProxyPreserveHost On | Off While application using mod_rewrite for friendly URL and it rely on the REQUEST_URI , set this On to preserve the URL request header to www.mydomain.com

<VirtualHost 192.168.1.3:80>
        ServerName www. mydomain. com
        ServerAlias mydomain.com
        DocumentRoot /u01/mydomain.com/wwwroot/www
        ProxyRequests Off
        ProxyPreserveHost On
        <Proxy *>
          Order deny,allow
          Allow from all
        </Proxy>
        ProxyPass /balancer-manager !
        ProxyPass / balancer://mycluster/ stickysession=BALANCEID nofailover=On
        ProxyPassReverse / http:// www1. mydomain. com/
        ProxyPassReverse / http:// www2. mydomain. com/
        <Proxy balancer://mycluster>
          BalancerMember http:// www1. mydomain. com/ route=www1
          BalancerMember http:// www2. mydomain. com/ route=www2
          ProxySet lbmethod=byrequests
        </Proxy>
        CustomLog /u01/mydomain.com/logs/lb-www-access.log combined
        ErrorLog /u01/mydomain.com/logs/lb-www-error.log
        <Location /balancer-manager>
          SetHandler balancer-manager
          Order deny,allow
          Allow from 127.0.0.1
        </Location>
</VirtualHost>

Web Server #1 www1.mydomain.com

Parameters Value Description
RewriteRule .* – [CO=BALANCEID:balancer.www1:.www.mydomain.com Rewrite the URL from www1.mydomain.com to www.mydomain.com
<VirtualHost 192.168.1.1:80>
    ServerName www1. mydomain. com
    ServerAlias www. mydomain. com
    DocumentRoot "/u01/mydomain/wwwroot/www"
    CustomLog /u01/mydomain.com/logs/www1.mydomain-access.log combined
    ErrorLog /u01/mydomain.com/logs/www1.mydomain-error.log
    RewriteEngine On
    RewriteRule .* - [CO=BALANCEID:balancer.www1:.www.mydomain.com]
</VirtualHost>

Web Server #2 www2.mydomain.com

Parameters Value Description
RewriteRule .* – [CO=BALANCEID:balancer.www2:.www.mydomain.com Rewrite the URL from www2.mydomain.com to www.mydomain.com
<VirtualHost 192.168.1.2:80>
    ServerName www2. mydomain. com
    ServerAlias www. mydomain. com
    DocumentRoot "/u01/mydomain/wwwroot/www"
    CustomLog /u01/mydomain.com/logs/www2.mydomain-access.log combined
    ErrorLog /u01/mydomain.com/logs/www1.mydomain-error.log
    RewriteEngine On
    RewriteRule .* - [CO=BALANCEID:balancer.www2:.www.mydomain.com]
</VirtualHost>
apache

levin • May 24, 2010


Previous Post

Next Post

Leave a Reply