Apache Module mod_proxy_balancer

available Languages : en | francium | ja

Description: mod_proxy extension for load balancing
Status: Extension
Module Identifier: proxy_balancer_module
Source File: mod_proxy_balancer.c
Compatibility: Available in version 2.1 and later

Summary

This faculty requires the service of mod_proxy and it provides load balancing for all the back protocols. The most important ones are :

  • HTTP, using mod_proxy_http
  • FTP, using mod_proxy_ftp
  • AJP13, using mod_proxy_ajp
  • WebSocket, using mod_proxy_wstunnel

The Load balancing scheduler algorithm is not provided by this module but from other ones such as :

  • mod_lbmethod_byrequests
  • mod_lbmethod_bytraffic
  • mod_lbmethod_bybusyness
  • mod_lbmethod_heartbeat

thus, in arrange to get the ability of load reconciliation, mod_proxy, mod_proxy_balancer and at least one of load balancing scheduler algorithm modules have to be present in the server.

Warning

Do not enable proxying until you have secured your server. candid proxy servers are dangerous both to your net and to the Internet at large .

Load balancer scheduler algorithm

At stage, there are 4 load balancer scheduler algorithm available for use : request Counting ( mod_lbmethod_byrequests ), Weighted Traffic Counting ( mod_lbmethod_bytraffic ), Pending Request Counting ( mod_lbmethod_bybusyness ) and Heartbeat Traffic Counting ( mod_lbmethod_heartbeat ). These are controlled via the lbmethod value of the Balancer definition. See the ProxyPass directing for more data, specially regarding how to configure the Balancer and BalancerMembers .

Load balancer stickyness

The balancer supports stickyness. When a request is proxied to some back-end, then all following requests from the same user should be proxied to the same back-end. many load balancers implement this feature via a table that maps node IP addresses to back-ends. This approach is guileless to clients and back-ends, but suffers from some problems : unequal load distribution if clients are themselves hidden behind proxies, stickyness errors when a node uses a dynamic IP address that changes during a session and loss of stickyness, if the function table overflows .
The faculty mod_proxy_balancer implements stickyness on top of two option means : cookies and URL encoding. Providing the cookie can be either done by the back-end or by the Apache web server itself. The URL encoding is normally done on the back-end .

Examples of a balancer configuration

Before we dive into the technical details, here ‘s an example of how you might use mod_proxy_balancer to provide load balancing between two back-end servers :


    BalancerMember "http://192.168.1.50:80"
    BalancerMember "http://192.168.1.51:80"

ProxyPass        "/test" "balancer://mycluster"
ProxyPassReverse "/test" "balancer://mycluster"

Another model of how to provide warhead balancing with stickyness using mod_headers, even if the back-end server does not set a suitable session cookie :

Header add Set-Cookie "ROUTEID=.%{BALANCER_WORKER_ROUTE}e; path=/" env=BALANCER_ROUTE_CHANGED

    BalancerMember "http://192.168.1.50:80" route=1
    BalancerMember "http://192.168.1.51:80" route=2
    ProxySet stickysession=ROUTEID

ProxyPass        "/test" "balancer://mycluster"
ProxyPassReverse "/test" "balancer://mycluster"

Exported Environment Variables

At portray there are 6 environment variables exported :

BALANCER_SESSION_STICKY
This is assigned the stickysession value used for the current request. It is the name of the cookie or request parameter used for sticky sessions
BALANCER_SESSION_ROUTE
This is assigned the route parsed from the current request .
BALANCER_NAME
This is assigned the appoint of the balancer used for the current request. The respect is something like balancer://foo .
BALANCER_WORKER_NAME
This is assigned the name of the worker used for the current request. The value is something like http://hostA:1234 .
BALANCER_WORKER_ROUTE
This is assigned the route of the worker that will be used for the current request.

BALANCER_ROUTE_CHANGED
This is set to 1 if the school term route does not match the proletarian path ( BALANCER_SESSION_ROUTE ! = BALANCER_WORKER_ROUTE ) or the session does not so far have an established route. This can be used to determine when/if the client needs to be sent an updated route when muggy sessions are used .

Enabling Balancer Manager Support

This module requires the serve of mod_status. Balancer director enables active update of balancer members. You can use balancer director to change the balance wheel component of a particular penis, or put it in the off line mood .
thus, in decree to get the ability of load balancer management, mod_status and mod_proxy_balancer have to be award in the waiter .
To enable load balancer management for browsers from the example.com knowledge domain add this code to your httpd.conf shape file


    SetHandler balancer-manager
    Require host example.com

You can now access load halter director by using a Web browser to access the page http://your.server.name/balancer-manager. Please note that only Balancers defined outside of containers can be dynamically controlled by the Manager .

Details on load balancer stickyness

When using cookie based stickyness, you need to configure the name of the cookie that contains the information about which back-end to use. This is done via the stickysession assign added to either ProxyPass or ProxySet. The name of the cookie is case-sensitive. The balancer extracts the value of the cookie and looks for a penis worker with path adequate to that value. The road must besides be set in either ProxyPass or ProxySet. The cookie can either be set by the back-end, or as shown in the above example by the Apache world wide web server itself .
Some back-ends use a slightly different mannequin of stickyness cookie, for exemplify Apache Tomcat. Tomcat adds the name of the Tomcat exemplify to the end of its school term id cookie, separated with a acid ( . ) from the school term id. therefore if the Apache world wide web server finds a dot in the value of the stickyness cookie, it only uses the character behind the dot to search for the path. In order to let Tomcat know about its exemplify name, you need to set the impute jvmRoute inside the Tomcat shape charge conf/server.xml to the value of the path of the actor that connects to the respective Tomcat. The name of the seance cookie used by Tomcat ( and more broadly by Java world wide web applications based on servlets ) is JSESSIONID ( amphetamine shell ) but can be configured to something else .
The second way of implementing stickyness is URL encoding. The web server searches for a question argument in the URL of the request. The name of the parameter is specified again using stickysession. The prize of the parameter is used to lookup a member worker with route equal to that value. Since it is not easy to extract and manipulate all URL links contained in responses, generally the work of adding the parameters to each connect is done by the back-end generating the content. In some cases it might be feasible doing this via the web server using mod_substitute or mod_sed. This can have negative impact on performance though .
The Java standards implement URL encoding slenderly different. They use a path information appended to the URL using a semicolon ( ; ) as the centrifuge and add the session id behind. As in the cookie case, Apache Tomcat can include the configured jvmRoute in this path information. To let Apache find this sort of path information, you need to set scolonpathdelim to On in ProxyPass or ProxySet .
last you can support cookies and URL encoding at the same time, by configuring the name of the cookie and the name of the URL parameter separated by a upright bar ( | ) as in the be example :

ProxyPass "/test" "balancer://mycluster" stickysession=JSESSIONID|jsessionid scolonpathdelim=On

    BalancerMember "http://192.168.1.50:80" route=node1
    BalancerMember "http://192.168.1.51:80" route=node2

If the cookie and the request parameter both provide routing information for the like request, the information from the request parameter is used .

Troubleshooting load balancer stickyness

If you experience stickyness errors, e.g. users lose their application sessions and need to login again, you first want to check whether this is because the back-ends are sometimes unavailable or whether your configuration is wrong. To find out about potential stability problems with the back-ends, check your Apache erroneousness logarithm for proxy error messages.

To verify your shape, first check, whether the stickyness is based on a cookie or on URL encoding. following dance step would be logging the appropriate data in the access log by using an enhance LogFormat. The following fields are useful :

%{MYCOOKIE}C
The value contained in the cookie with name MYCOOKIE.
The name should be the same given in the stickysession
attribute.
%{Set-Cookie}o
This logs any cookie set by the back-end. You can track,
whether the back-end sets the session cookie you expect, and
to which value it is set.
%{BALANCER_SESSION_STICKY}e
The name of the cookie or request parameter used
to lookup the routing information.
%{BALANCER_SESSION_ROUTE}e
The route information found in the request.
%{BALANCER_WORKER_ROUTE}e
The route of the worker chosen.
%{BALANCER_ROUTE_CHANGED}e
Set to 1 if the route in the request
is different from the route of the worker, i.e.
the request couldn’t be handled sticky.

park reasons for loss of school term are session timeouts, which are normally configurable on the back-end server .
The halter besides logs detail information about handling stickyness to the error logarithm, if the log level is set to debug or higher. This is an easy way to troubleshoot stickyness problems, but the log book might be besides eminent for production servers under high load .

Leave a Reply

Your email address will not be published.