Nginx+Tomcat high-performance load balancing cluster construction

Nginx is a high-performance HTTP server/reverse proxy server and email (IMAP/POP3) proxy server. It occupies less memory, has strong concurrency capability, and performs better in web servers of the same type. Nginx can be compiled and run on most Unix Linux OS, and there is a Windows port. In general, for new sites, it is recommended to use the latest stable version as the production version.

The maximum number of online visits supported by a single Tomcat is about 500. It is impossible for a Tomcat to support more visits. Here we adopt the cluster deployment method, use multiple Tomcats, and use Nginx as the reverse proxy.

The architecture is as follows:

Ready to work

apache-tomcat-7.0.61

nginx-1.12.2

redis-x64-3.2.100

To simplify the example, only the deployment and integration of Nginx+Tomcat is discussed here.

Nginx installation

(1) Go to the official website to download the latest stable version of Nigx for Windows (version 1.12.2 I use). Official website

(2) Unzip to any directory on disk. Here I unzip it in F:\nginx-1.12.2

(3) Start the service: start nginx.exe

  Stop the service: nginx -s stop 

  Reload configuration: nginx -s reload

Modify nginx.conf

1. The number of processes and the maximum number of connections per process

  • The number of nginx processes, it is recommended to set it equal to the total number of CPU cores
  • The maximum number of connections for a single process. Then the maximum number of connections to the server = the number of connections * the number of processes

2. Basic configuration of Nginx

  • The listening port is generally 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 balancing list

  • location / {} : What kind of suffix to load balance requests, if we want to load balance all aspx files, we can write: location ~.*\.aspx${}
  • proxy_pass: Requests are redirected to a custom server list, here we redirect all requests to a list of load balancing servers identified as http://joannayan.com.
  • The weight of the weight, the higher the weight, the greater the probability of being assigned. The weight can be defined according to the machine configuration (if a server has a good hardware configuration and can handle more requests, a higher weight can be set for it; if there is a server with a poor hardware configuration, then the previous The weight configuration of one is weight=2, and the configuration of the latter one is weight=1).

test

 Deploy the Web project TestNginx.war to the Tomcat servers of the two machines (in order to distinguish between different Web servers, the TestNginx project deployed on the two machines is slightly different on the page display).

Start Tomcat on both machines and start nginx.

访问nginx:http://localhost/TestNginx

Refresh, then visit:

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

http://www.bpa2365.cn/
http://www.fks8445.cn/
http://www.aht8537.cn/
http://www.cun5054.cn/
http://www.gdk7028.cn/
http://www.ypk8666.cn/
http://www.wan2959.cn/
http://www.sit9945.cn/
http://www.zmj4226.cn/
http://www.ccn6233.cn/
http://www.jck8045.cn/
http://www.ckk6213.cn/
http://www.mak1390.cn/
http://www.vii0197.cn/
http://www.pwj5001.cn/
http://www.wvh4263.cn/
http://www.mvg0339.cn/
http://www.yif9712.cn/
http://www.jta0960.cn/
http://www.omx8816.cn/
http://www.nlc4773.cn/
http://www.dep9137.cn/
http://www.vlq7732.cn/
http://www.umg2515.cn/
http://www.kog1435.cn/
http://www.nxf9936.cn/
http://www.hqh7518.cn/
http://www.hij5984.cn/
http://www.vui9639.cn/
http://www.fzl7156.cn/
http://www.wue0833.cn/
http://www.dye6768.cn/
http://www.ryh7899.cn/
http://www.lij0467.cn/
http://www.epv8502.cn/
http://www.lru8400.cn/
http://www.mtr5072.cn/
http://www.kbs9896.cn/
http://www.qfk7654.cn/
http://www.myb6827.cn/
http://www.tcr0461.cn/
http://www.xua4102.cn/
http://www.tzn6024.cn/
http://www.kme4313.cn/
http://www.bnb6875.cn/
http://www.yio4898.cn/
http://www.yat8046.cn/
http://www.mtl1611.cn/
http://www.ltz6047.cn/
http://www.wsa2392.cn/
http://www.xfz1235.cn/
http://www.fsh3334.cn/
http://www.hmb6894.cn/
http://www.zis3531.cn/
http://www.cyj2776.cn/
http://www.bpj4889.cn/
http://www.dvu3043.cn/
http://www.vrc3090.cn/

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324392803&siteId=291194637