Administrator

Configuring Apache as a Load Balancer for a Cluster

When you use Apache as a load balancer for an SAP Mobile Platform cluster....

Procedure

  1. Install Apache on a separate server, outside the SAP Mobile Platform cluster.
  2. Configure Apache.
    1. Use a text editor to open the <Apache_home>\conf file.
    2. Enable the following modules:
      • mod_proxy
      • mod_proxy_http
      • mod_proxy_balancer
      • slotmem_shm_module
      • lbmethod_byrequests_module
    3. Set up a basic proxy.
      The sample below shows:
      • The Apache load balancer listening on port 80.
      • The Apache load balancer cluster identified as balancer://my_smpcluster.
      • Two SAP Mobile Platform Server nodes (my_smpserver1 and my_smpserver2, both listening on port 8080, making up the Apache load balancer cluster.
      • Use Apache header and stickysession.
      Listen 80
      <VirtualHost *:80>
      ServerName loadbalancer-server
      Header add Set-Cookie "ROUTEID=.%{BALANCER_WORKER_ROUTE}e; path=/" env=BALANCER_ROUTE_CHANGED
      <Proxy balancer://my_smpcluster>
       BalancerMember http://my_smpserver1.my_co.com:8080 route=node01
       BalancerMember http://my_smpserver2.my_co.com:8080 route=node02
       ProxySet stickysession=ROUTEID
      </Proxy>
      ProxyPass /  balancer://my_smpcluster/
      ProxyPassReverse /  balancer://my_smpcluster/ 
      </VirtualHost>
    4. Set up a one-way HTTPS proxy.
      In the sample below:
      • The Apache load balancer listens on port 443.
      • The Apache load balancer cluster is identified as balancer://my_smpclusterhttps.
      • Two SAP Mobile Platform nodes, my_smpserver1 and my_smpserver2, both listen on port 8081, making up the Apache load balancer cluster.
      Listen 443
      <VirtualHost *:443>
      ServerName loadbalancer-server
      # activate HTTPS on the reverse proxy 
      SSLEngine on
      SSLCertificateFile "C:/Apache24/conf/proxy-server.crt"
      SSLCertificateKeyFile "C:/Apache24/conf/proxy-server.key"
      SSLCertificateChainFile "C:/Apache24/conf/proxy-server-ca.crt"
      SSLProxyEngine On
      SSLProxyCACertificateFile C:/Apache24/conf/sup-server-ca.crt
      Header add Set-Cookie "ROUTEID=.%{BALANCER_WORKER_ROUTE}e; path=/" env=BALANCER_ROUTE_CHANGED
      <Proxy balancer://my_smpclusterhttps>
      BalancerMember https://my_smpserver1.my_co.com:8081 route=node01
      BalancerMember https://my_smpserver2.my_co.com:8081 route=node02
      ProxySet stickysession=ROUTEID
      </Proxy>
      ProxyPass / balancer://my_smpclusterhttps/
      ProxyPassReverse / balancer://my_smpclusterhttps/ 
      </VirtualHost>
      
    5. Set up a two-way HTTPS proxy.
      In the sample below:
      • The Apache load balancer listens on port 8443.
      • The Apache load balancer cluster is identified as balancer://my_smpclusterhttps2.
      • Two SAP Mobile Platform nodes, my_smpserver1 and my_smpserver2, both listen on port 8082, making up the Apache load balancer cluster.
      Listen 8443
      <VirtualHost *:8443>
      ServerName loadbalancer-server
      # activate HTTPS on the reverse proxy 
      SSLEngine on
      SSLCertificateFile "C:/Apache24/conf/proxy-server.crt"
      SSLCertificateKeyFile "C:/Apache24/conf/proxy-server.key"
      SSLCertificateChainFile "C:/Apache24/conf/proxy-server-ca.crt" 
      # activate the client certificate authentication
      SSLCACertificateFile "C:/Apache24/conf/trusted-client-ca.crt"
      SSLVerifyClient require
      SSLVerifyDepth 10
      SSLProxyEngine On
      SSLProxyCACertificateFile C:/Apache24/conf/sup-server-ca.crt
      SSLProxyMachineCertificateFile C:/Apache24/conf/proxy-client.pem
      # initialize the special headers to a blank value to avoid http header forgeries
      RequestHeader set SSL_CLIENT_CERT "" 
      Header add Set-Cookie "ROUTEID=.%{BALANCER_WORKER_ROUTE}e; path=/" env=BALANCER_ROUTE_CHANGED
      <Proxy balancer://my_smpclusterhttps2>
      BalancerMember https://my_smpserver1.my_co.com:8082 route=node01
      BalancerMember https://my_smpserver2.my_co.com:8082 route=node02
      ProxySet stickysession=ROUTEID
      </Proxy>
      ProxyPass / balancer://my_smpclusterhttps2/
      ProxyPassReverse / balancer://my_smpclusterhttps2/ 
      </VirtualHost>
    6. Start up Apache:
      • Windows – use the Windows Services Control Panel.
      • Linux – enter the following command in a terminal window:
        apachectl start
  3. Verify that each SAP Mobile Platform Server node is configured correctly for session stickiness.
    Perform an OData proxy request to each SAP Mobile Platform Server node. The request should look something like this:
    GET http://my_smpserver1.my_co.com/odataproxy?fileName=my_test.txt
    Check the response headers to verify that the cookie is formed correctly:
    HTTP/1.1 200 OK
    Date: Wed, 29 Jan 2014 22:39:27 GMT
    Server: SAP
    Content-Encoding: gzip
    Content-Type: text/plain
    Content-Length: 3714
    Set-Cookie: ROUTEIDSSO=<long_hex_number>; Path=/; HttpOnly
    Set-Cookie: ROUTESESSID=<long_hex_number>.node01; Path=/; HttpOnly
    Keep-Alive: timeout=5, max=100
    Connection: Keep-Alive

    The response above shows .node01 appended to the ROUTEID cookie.

  4. Verify that session stickiness is working with the proxy.
    1. Use a text editor to open the <Apache_home>\httpd.conf file.
    2. Add the following lines to the <VirtualHost *:80> block:
      LogFormat "%h %l %u %t \"%r\" %>s %b duration:%T/%D balancer:%{BALANCER_WORKER_NAME}e Changed:%{BALANCER_ROUTE_CHANGED}e Sticky:%{BALANCER_SESSION_STICKY}e"
      TransferLog     enhancedlog.log

      This creates a new enhancedlog.log file in <Apache_home>. You can customize the file name and location.

    3. Restart Apache using the Windows Services Control Panel.
    4. Run a load test and look at the enhancedlog.log file. You should see something like this:
      10.172.218.23 - - [29/Jan/2014:09:40:11 -0800] "GET /odataproxy?fileName=50flights.txt HTTP/1.1" 200 3727 duration:0/140405 balancer:http://supdevperf02.oak.sap.corp:8080 Changed:1 Sticky:-10.172.218.23 - - [29/Jan/2014:09:40:11 -0800] "GET /odataproxy?fileName=50flights.txt HTTP/1.1" 200 3727 duration:0/124804 balancer:http://supdevperf02.oak.sap.corp:8080 Changed:- Sticky:X-SMP-SESSID
      10.172.218.23 - - [29/Jan/2014:09:40:11 -0800] "GET /odataproxy?fileName=50flights.txt HTTP/1.1" 200 3727 duration:0/156006 balancer:http://supdevperf02.oak.sap.corp:8080 Changed:- Sticky:ROUTEID
      
      The first request for a user when initial cookies are not set looks like this:
      Changed:1 Sticky:-
      Subsequent requests look like this:
      Changed:- Sticky:ROUTEID

      This verifies that Apache read the X-SMP-SESSID cookie and sent the request to the correct server.

      If you see Changed: 1 Sticky:X-SMP-SESSID, session stickiness did not work.

  5. (Optional) Configure Apache admin pages.
    If you want to set up additional servlets to monitor Apache HTTPD, add these lines to your httpd.conf file:
    ExtendedStatus On
    Listen 8080
    <VirtualHost *:8080>
    <Location /server-status>
        SetHandler server-status
    </Location>
    <Location /balancer-manager>
        SetHandler balancer-manager
    </Location>
    </VirtualHost>
  6. (Optional) Increase the number of threads for Apache.
    If you downloaded the Windows HTTPD version from Apache Lounge, you are using the mpm_winnt module (statically loaded).
    <Apache_home>>httpd.exe -l
    Compiled in modules:
      core.c
      mod_win32.c
      mpm_winnt.c
      http_core.c
      mod_so.c
    To increase the number of threads, add the following directive to the httpd.conf file:
    # WinNT MPM
    # ThreadsPerChild: constant number of worker threads in the server process
    # MaxConnectionsPerChild: maximum number of connections a server process serves
    <IfModule mpm_winnt_module>
        ThreadsPerChild        800
        MaxConnectionsPerChild   0
    </IfModule> 
    

    The ThreadsPerChild directive creates a static number of threads. Set this to the maximum number of concurrent connections that you expect.

  7. Validate the configuration by opening a browser and testing these URLs:
    • http://<loadbalancer-server>:80
    • https://<loadbalancer-server>:443
    • https://<loadbalancer-server>:8443

    Each URL should return a page with the product name, version number, and build number.

Next Steps

More information about using Apache as a load balancer is available from:
  • http://<apachehost>:8080/server-status, and
  • http://<apachehost>:8080/balancer-manager