Saturday, November 21, 2015

Clustering/Load balancing using Apache HTTP server

Simple step to cluster Web Service using Apache HTTP server. The HTTP server act as a load balancer for 2 or more resources.









A. Ensure that the following modules are enabled.
  LoadModule actions_module modules/mod_actions.so
  LoadModule alias_module modules/mod_alias.so
  LoadModule allowmethods_module modules/mod_allowmethods.so
  LoadModule asis_module modules/mod_asis.so
  LoadModule auth_basic_module modules/mod_auth_basic.so
  LoadModule authn_core_module modules/mod_authn_core.so
  LoadModule authn_file_module modules/mod_authn_file.so
  LoadModule authz_core_module modules/mod_authz_core.so
  LoadModule authz_groupfile_module modules/mod_authz_groupfile.so
  LoadModule authz_host_module modules/mod_authz_host.so
  LoadModule authz_user_module modules/mod_authz_user.so
  LoadModule autoindex_module modules/mod_autoindex.so
  LoadModule cgi_module modules/mod_cgi.so
  LoadModule dir_module modules/mod_dir.so
  LoadModule env_module modules/mod_env.so
  LoadModule include_module modules/mod_include.so
  LoadModule info_module modules/mod_info.so
  LoadModule isapi_module modules/mod_isapi.so
  LoadModule lbmethod_byrequests_module modules/mod_lbmethod_byrequests.so
  LoadModule log_config_module modules/mod_log_config.so
  LoadModule mime_module modules/mod_mime.so
  LoadModule negotiation_module modules/mod_negotiation.so
  LoadModule proxy_module modules/mod_proxy.so
  LoadModule proxy_balancer_module modules/mod_proxy_balancer.so 
  LoadModule proxy_html_module modules/mod_proxy_html.so
  LoadModule proxy_http_module modules/mod_proxy_http.so
  LoadModule setenvif_module modules/mod_setenvif.so
  LoadModule slotmem_shm_module modules/mod_slotmem_shm.so
  LoadModule socache_shmcb_module modules/mod_socache_shmcb.so
  LoadModule ssl_module modules/mod_ssl.so
  LoadModule status_module modules/mod_status.so
  LoadModule xml2enc_module modules/mod_xml2enc.so


B. Add httpd-proxy-balancer.conf.
  Include conf/extra/httpd-proxy-balancer.conf

C. Create httpd-proxy-balancer.conf inside extra folder.
<VirtualHost *>
    #--- Set to Off since it is not request forwarder.
     ProxyRequests Off
    #--- Display load balance status.
     ProxyStatus On
    #--- Not passing request to proxied host.
     ProxyPreserveHost Off
     ProxyPass /balancer-manager !
     ProxyPass /server-status !
    #-- Balancer cluster name.
     ProxyPass / balancer://mycluster/ STICKYSESSION=mysticky_session nofailover=Off
    #-- Logging.
     CustomLog C:/Apache24/logs/balancer_log.txt combined
    #-- Use as gateway.
     ProxyPassReverse / balancer://mycluster
 
    #-- Cluster / balancer.
     <Proxy balancer://mycluster>
      BalancerMember http://{hostname}:{port} route=first loadfactor=5
      BalancerMember http://{hostname}:{port} route=second loadfactor=5
    </Proxy>
 
    <Location /balancer-manager>
     SetHandler balancer-manager
    </Location>
 
    <Location /server-status>
     SetHandler server-status
    </Location>
</VirtualHost>
D. Start Apache HTTP server.
/bin/httpd.exe
E. Access the application via port 80 if using default port.
http://{host name}:{port}/{app web-context}
F. Status of balancer can be checked from accessing Balance Manager URL.
  http://{hostname}:{port}/balancer-manager

No comments:

Post a Comment