Apache mod_proxy as Load Balancer
This article presents an example of load balancing using Apache2.
For example take the host 192.168.1.100 as a balancer, this host will install the apache front end acting for all requests and will balance the load on other hosts.
The load is redirected to the host 192.168.1.101,192.168.1.102,192.168.1.103 and 192.168.1.104.
Configuring apache2
First of all we need to install apache server on the host server acting principal
On 192.168.1.100, install Apache2:
yum install httpd httpd-devel
yum intall mod_proxy
grep -i proxy /etc/httpd/conf/httpd.conf
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_balancer_module modules/mod_proxy_balancer.so
LoadModule proxy_ftp_module modules/mod_proxy_ftp.so
LoadModule proxy_http_module modules/mod_proxy_http.so
LoadModule proxy_connect_module modules/mod_proxy_connect.s
proxy Settings
On 192.168.1.100, add the /etc/httpd/conf.d/proxy.conf, this file will contain the nodes that will balance the incoming load.
<Proxy balancer://mycluster>
BalancerMember http://192.168.1.101
BalancerMember http://192.168.1.102
BalancerMember http://192.168.1.103
BalancerMember http://192.168.1.104
Options Follow
SymLinksOrder allow,denyAllow from all
</Proxy>
ProxyPass /myCluster balancer://mycluster
root@www1 ~]#
vi /etc/httpd/conf.d/proxy.conf
# create new
<IfModule mod_proxy.c>
ProxyRequests Off
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
# specify the way of load balancing with “lbmethod”. it’s also possible to set “bytraffic”.
ProxyPass /proxy balancer://cluster lbmethod=byrequests
<proxy balancer://cluster>
BalancerMember http://www1.rmohan.com loadfactor=1
BalancerMember http://www2.rmohan.com loadfactor=1
</proxy>
</IfModule>
[root@www ~]#
/etc/rc.d/init.d/httpd restart
Stopping httpd:
[ OK ]
Starting httpd:
[ OK ]
Recent Comments