Skip to main content

Configuring a local load balancer

note

This example demonstrates the tasks involved — it is not a recommendation for a production environment. Supporting a production load-balancing setup is outside iGrafx's scope and depends on your network and IT infrastructure.

This worked example uses Apache as a load balancer with mod_jk and sticky sessions, in front of two Tomcat cluster nodes on one Windows machine. SimpleTcpCluster (included with Tomcat) provides clustering, and DeltaManager replicates sessions across all nodes.

Prerequisites

  • The iGrafx platform installed with the pre-deployed Tomcat (one installation per node).

Steps

Configure the Tomcat nodes

Edit each node's server.xml (in its \conf directory).

First node — keep the default ports (Connector 8080, Shutdown 8005, AJP 8009, Redirect 8443). If you change them, keep them unique across nodes. Uncomment the <Cluster> section so it reads:

<Engine name="Catalina" defaultHost="localhost" jvmRoute="worker1">
<Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster" channelSendOptions="8">
<Manager className="org.apache.catalina.ha.session.DeltaManager" expireSessionsOnShutdown="false" notifyListenersOnReplication="true"/>
<Channel className="org.apache.catalina.tribes.group.GroupChannel">
<Membership className="org.apache.catalina.tribes.membership.McastService" address="228.0.0.4" port="45564" frequency="500" dropTime="3000"/>
<Sender className="org.apache.catalina.tribes.transport.ReplicationTransmitter">
<Transport className="org.apache.catalina.tribes.transport.nio.PooledParallelSender"/>
</Sender>
<Receiver className="org.apache.catalina.tribes.transport.nio.NioReceiver" address="auto" port="4000" autoBind="100" selectorTimeout="5000" maxThreads="6"/>
<Interceptor className="org.apache.catalina.tribes.group.interceptors.TcpFailureDetector"/>
<Interceptor className="org.apache.catalina.tribes.group.interceptors.MessageDispatch15Interceptor"/>
<Interceptor className="org.apache.catalina.tribes.group.interceptors.ThroughputInterceptor"/>
</Channel>
<Valve className="org.apache.catalina.ha.tcp.ReplicationValve" />
<ClusterListener className="org.apache.catalina.ha.session.ClusterSessionListener" />
</Cluster>

Second node — if using the defaults, increase each port by 1 (Connector 8081, Shutdown 8006, AJP 8010, Redirect 8444). On different machines you don't need different ports. Uncomment the same <Cluster> section, but change jvmRoute to worker2.

You should now have two Tomcats running, reachable directly at ports 8080 and 8081.

Set up the Apache HTTP server

  1. Download Apache (this example uses 2.4.18 x64) and unzip the Apache24 folder to C:\.

  2. Download the mod_jk binary (this example uses x86_64-httpd-2.4.x) and unzip it into \modules.

  3. In \logs, add two empty files: mod_jk.shm and mod_jk.log (skip if they're created automatically).

  4. In \conf\httpd.conf, change Listen 80 to Listen 8079 and ServerName localhost:80 to ServerName localhost:8079 (or your preferred unique port). Add these lines at the top:

    LoadModule jk_module C:\Apache24\modules\tomcat-connectors-1.2.40-windows-x86_64-httpd-2.4.x\mod_jk.so
    # Path to the worker configuration file
    JkWorkersFile C:\Apache24\conf\workers.properties
    # Where to store logging and memory-usage information
    JkShmFile C:\Apache24\logs\mod_jk.shm
    JkLogFile C:\Apache24\logs\mod_jk.log
    JkLogLevel info
    # Monitoring of the cluster
    JkMount /jkmanager/* jkstatus
    <Location /jkmanager>
    Require all granted
    </Location>
    # Map all requests to the web application to the load balancer
    JkMount /* LoadBalancer

    Then uncomment #LoadModule access_compat_module modules/mod_access_compat.so.

  5. In \conf, add a workers.properties file:

    # Virtual worker list
    worker.list=jkstatus, LoadBalancer
    # Enable virtual workers
    worker.jkstatus.type=status
    worker.LoadBalancer.type=lb
    # Add Tomcat instances as workers (2 in this example)
    worker.worker1.type=ajp13
    worker.worker1.host=localhost
    worker.worker1.port=8009
    worker.worker2.type=ajp13
    worker.worker2.host=localhost
    worker.worker2.port=8010
    # Provide the worker list to the load balancer
    worker.LoadBalancer.balance_workers=worker1,worker2
    worker.LoadBalancer.sticky_session=true

    The worker ports must match the AJP ports in each Tomcat's server.xml. This also sets sticky sessions — mod_jk defaults to true, but it's safer to set it explicitly.

  6. From Apache24's \bin directory, run httpd -k install.

  7. Run httpd -k start (use httpd -k stop to shut down).

  8. Open http://localhost:8079/ (or your load-balancer port) to reach the application through the load balancer. http://localhost:8079/jkmanager/ shows the load balancer and worker status; http://localhost:8079/managerServer Status shows which node you're on by its port.

Add more nodes

  1. Stop the Apache load balancer.
  2. Duplicate one of your Tomcat instance folders.
  3. Configure the new Tomcat node with unique ports (add 1 to the previous node's values).
  4. Add three lines to \conf\workers.properties for the new worker node.
  5. Start Apache again. Repeat as needed.