Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to build Nginx+Tomcat High performance load balancing Cluster

Shulou Source: shulou.com Published: 2022-05-31 12:50:41 10月18日 Update

This article introduces the knowledge of "how to build a Nginx+Tomcat high-performance load balancing cluster". In the operation of practical cases, many people will encounter this dilemma. Next, let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

Nginx is a high performance http server / reverse proxy server and email (imap/pop3) proxy server. It occupies less memory and has strong concurrency ability, so it performs better in the same type of web server. Nginx can be compiled and run on most unix linux os, and there is a portable version of windows. In general, for new sites, it is recommended to use the latest stable version as the production version.

The maximum amount of online access supported by a single tomcat is about 500. it is impossible for a tomcat to inform it that it supports more visits. Here we use cluster deployment, using multiple tomcat and reverse proxy using nginx.

The architecture is as follows:

Preparatory work

Apache-tomcat-7.0.61

Nginx-1.12.2

Redis-x64-3.2.100

To simplify the example, I will only talk about the deployment and integration of nginx+tomcat.

Nginx installation

(1) go to the official website to download the latest stable version of windows nigx (version 1.12.2 I use).

(2) decompress to any directory on the disk. Here I unzip it at f:\ nginx-1.12.2

(3) start the service: start nginx.exe

Stop service: nginx-s stop

Reload configuration: nginx-s reload

Modify nginx.conf

1. Number of processes and maximum number of connections per process

The number of nginx processes, which is recommended to be equal to the total number of cores of cpu

The maximum number of connections per process. Then the maximum number of connections to the server = the number of connections * processes

Basic configuration of 2.nginx

The listening port is usually http port: 80

There can be multiple domain names, separated by spaces. For example, server_name www.sohu.com baidu,com

3. Basic configuration of load balancer list

Location / {}: what kind of suffix to load balance request? if we want to load balance all files with aspx suffix, we can write: location ~. *\ .aspx ${}

Proxy_pass: requests are directed to a custom server list. Here, we redirect requests to the list of load balancer servers identified as http://joannayan.com.

Weight weight, the higher the weight, the greater the probability of being assigned. You can define the weight according to the machine configuration (if a server has a good hardware configuration and can handle more requests, you can set a higher weight; and a server with a poor hardware configuration, so you can configure the weight of the former as weight=2 and the poor configuration of the latter as weight=1).

test

Deploy the testnginx.war web project to the tomcat servers of the two machines (in order to distinguish between accessing different web servers, the testnginx project deployed on the two machines is slightly different on the page).

Start tomcat on both machines, and start nginx.

Visit nginx: http://localhost/testnginx

Refresh, and then visit:

Due to the different weights, the "5.20 server" is more likely to be displayed in the process of constantly refreshing the page.

This is the end of the content of "how to build a Nginx+Tomcat high-performance load balancing cluster". Thank you for your reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Tags: Services servers configuration equalization processes maximum more machines clusters high performance differences weights agents content single suffix basic configuration multiple recommendations situations Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MySQL MariaDB Xiaomi Linux Shulou Information