Tomcat clustering guidelines

Tomcat Cluster with nginx (Load Balancer)

Nginx(pronounced "engine X") is an HTTP and reverse proxy server. It is well known for its high performance and stability.

It is pretty feature-rich and very simple to configure. Nginx hosts nearly 12.18 percent (22.2M) of active sites across all domains.

Nginx uses event-driven architecture to handle requests. When compared to a thread-per-request model, event-driven is highly scalable with a low and predictable memory footprint.

Pre-Requisites

  • Tomcat server (server1, server2, sever3,…,etc.)
  • Tomcat 1: HCL Unica Platform and Campaign (web & listener)
  • Tomcat 2: HCL Unica Platform
  • Tomcat 3: HCL Unica Platform
  • Nginx load balancer (server4)
  • Client browser to access Unica application

Architecture

Steps to Follow
  1. Tomcat Installation - server1

    Download and install Tomcat server and listen on 8080

  2. Tomcat Installation - server2

    Download and install Tomcat server and listen on 8081

  3. Tomcat Installation - server3

    Download and install Tomcat server and listen on 8082

  4. Tomcat server1:8080

    Install and deploy both HCL Unica Platform and Campaign and make it work with 8080 port.

  5. Tomcat server2:8081

    Install and deploy HCL Unica Platform only and make it work with 8081 port.

  6. Tomcat server3:8082

    Install and deploy HCL Unica Platform only and make it work with 8082 port.

Note: Another way to implement clustering for unica is to have shared mount point across all the clusters and perform the installation at the shared point. This way the installation will be done just once, but will be shared across all the clusters. With this way the file system including war files and log files will be shared among the participating clusters.

Nginx installation

Download nginx & Install:
  1. wget http://nginx.org/download/nginx-1.2.6.tar.gz
  2. tar -xzf nginx-1.2.6.tar.gz
  3. cd nginx-1.2.6/
  4. ./configure --prefix=/opt/Tomcat/nginx (Ex:- ./configure --prefix=/opt/Tomcat/nginx --without-http_gzip_module --with-http_stub_status_module )
  5. Make
  6. Make install

Nginx Configuration

After completion of installation, to configure nginx:
  1. Update <NGINX_HOME>/conf/ nginx.conf
  2. To start and stop nginx

    <NGINX_HOME>/sbin/ngin

    <NGINX_HOME>/sbin/nginx -s stop

  3. Nginx Logs directory: <NGINX_HOME>/logs/

Test nginx

In this example, nginx is listening on 80 port, hence URL is http://rhel7:80. With the above screen, can confirm that nginx is running without any issues.

Nginx Load Balancer Algorithams
  1. Round-robin

    requests to the application servers are distributed in a round-robin fashion.

    Here is the sample configuration (<NGINX_HOME>/conf/ nginx.conf) with round robin fashion

  2. Ip_hash

    With ip-hash, the client’s IP address is used as a hashing key to determine what server in a server group should be selected for the client’s requests.

    This method ensures that the requests from the same client will always be directed to the same server except when this server is unavailable.

    Here is the sample configuration (<NGINX_HOME>/conf/nginx.conf) with round robin fashion

  3. Least_conn

    With the least-connected load balancing, nginx will try not to overload a busy application server with excessive requests, distributing the new requests to a less busy server instead.

  4. Weight Distribution (weigth n)

    With this configuration, every 5 new requests will be distributed across the application instances as the following: 3 requests will be directed to srv1, one request will go to srv2, and another one — to srv3.

    Ex:-
         Upstream tomcatcluster
          {
                  Server server1:8080 weight 3;
                  Server server2:8081;
                  Server server4:8082;
           }
    
  5. Max Fails configuration

    Max fails refers to the maximum number of failed attempts to connect to a server should occur before it is considered inactive. Fall_timeout specifies the length of that the server is considered inoperative. Once the time expires, new attempts to reach the server will start up again. The default timeout value is 10 seconds.

    Ex:-
    Upstream tomcatcluster
          {
                  Server server1:8080 max_fails=3 fail_timeout=15s;
                  Server server2:8081;
                  Server server4:8082;
           }
    

Unica configuration with nginx:

Change the Platform navigation URL with nginx server host and actual context.