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
- Tomcat Installation - server1
Download and install Tomcat server and listen on 8080
- Tomcat Installation - server2
Download and install Tomcat server and listen on 8081
- Tomcat Installation - server3
Download and install Tomcat server and listen on 8082
- Tomcat server1:8080
Install and deploy both HCL Unica Platform and Campaign and make it work with 8080 port.
- Tomcat server2:8081
Install and deploy HCL Unica Platform only and make it work with 8081 port.
- Tomcat server3:8082
Install and deploy HCL Unica Platform only and make it work with 8082 port.
Nginx installation
- wget http://nginx.org/download/nginx-1.2.6.tar.gz
- tar -xzf nginx-1.2.6.tar.gz
- cd nginx-1.2.6/
- ./configure --prefix=/opt/Tomcat/nginx (Ex:- ./configure --prefix=/opt/Tomcat/nginx --without-http_gzip_module --with-http_stub_status_module )
- Make
- Make install
Nginx Configuration
- Update
<NGINX_HOME>/conf/ nginx.conf
- To start and stop nginx
<NGINX_HOME>/sbin/ngin
<NGINX_HOME>/sbin/nginx -s stop
- 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.
- 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
- 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
- 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.
- 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; }
- 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.