Configuring Apache as a load balancer
This tutorial will walk you through configuring Apache as a load
balancer to direct client requests to a group of PowerServer Web APIs. You
will have to configure Apache as a load balancer and use the “Request
Counting” load balancer scheduler algorithm and the cookie in order to
support sticky sessions.
Step 1: Follow the sections below to install Apache 2.4 (The load
balancing feature is available in Apache 2.2 or later) and configure
Apache as a reverse proxy server.
-
Configuring
Apache reverse proxy server (Windows) > “Preparations” and “Configuring Apache” sections -
Configuring
Apache reverse proxy server (Linux) > “Preparations” and “Configuring Apache” sections
Step 2: Configure Apache to direct requests to the PowerServer Web
APIs group using the “Request Counting” load balancer scheduler algorithm
and the cookie.
-
For Windows Apache, make sure the following lines are NOT
commented out in the httpd.conf file.mod_proxy, mod_proxy_http, mod_proxy_balancer,
mod_lbmethod_byrequests (the “Request Counting” algorithm), and
mod_headers (stickyness cookie) must be enabled in order to have the
load-balancing ability.1234567LoadModule headers_module modules/mod_headers.soLoadModule status_module modules/mod_status.soLoadModule slotmem_shm_module modules/mod_slotmem_shm.soLoadModule lbmethod_byrequests_module modules/mod_lbmethod_byrequests.soLoadModule proxy_module modules/mod_proxy.soLoadModule proxy_balancer_module modules/mod_proxy_balancer.soLoadModule proxy_http_module modules/mod_proxy_http.so -
Add the following lines to the end of the httpd.conf
file.The “Header” directive provides load balancing with stickyness
using mod_headers.The “Max-Age” attribute specifies the number of seconds until
the cookie expires. This value must be greater than the session
timeout value (which is 3600 seconds by default).The “BalancerMember” directive specifies the URL of the server
instance in the group.The “stickysession” attribute specifies the name of the
cookie.For more information, refer to https://httpd.apache.org/docs/2.4/mod/mod_proxy_balancer.html.
12345678910111213141516171819202122<VirtualHost *:8080>ProxyPreserveHost OnProxyrequests offSetEnv force-proxy-request-1.0.1SetEnv proxy-nokeepalive 1ErrorLog logs/ps-error.logCustomLog logs/ps-access.log common<Proxy *>Require all granted</Proxy>ProxyPass / balancer://mycluster/ProxyPassReverse / balancer://mycluster/</VirtualHost>Header add Set-Cookie "ROUTEID=.%{BALANCER_WORKER_ROUTE}e; Max-Age=3700; path=/" env=BALANCER_ROUTE_CHANGED<Proxy balancer://mycluster>BalancerMember https://172.16.100.34:6000 route=server1BalancerMember https://172.16.100.35:6000 route=server2BalancerMember https://172.16.100.36:6000 route=server3ProxySet stickysession=ROUTEID</Proxy>