First, the tool
nginx-1.8.0
apache-tomcat-6.0.33
II. Objectives
A tomcat cluster for high-performance load balancing:
Third, step
1, first download nginx, to download stable version:
2. Then extract two tomcat, named Apache-tomcat-6.0.33-1 and Apache-tomcat-6.0.33-2, respectively:
3. Then modify the two Tomcat boot ports, 18080 and 28080, respectively, to change the first Tomcat as an example to open the Server.xml in the Tomcat conf directory:
A total of 3 ports need to be modified:
Of course the second Tomcat is the same, such as:
4. Then start two tomcat and visit to see if it is normal:
5, then modify the above two Tomcat default page (in order to distinguish between the following is the one tomcat, just change it):
After the change, visit, such as:
6, OK, now we can start to configure Nginx to achieve load balancing, in fact, very simple, only need to configure the Nginx configuration file can:
The configuration is as follows (only simple configuration here, the actual production environment can be more fully configured):
Worker_processes 1; #工作进程的个数, generally consistent with the number of CPU cores in the computer events { worker_connections , #单个进程最大连接数 (Maximum connections = number of connections * Number of processes)}http { include mime.types; #文件扩展名与文件类型映射表 default_type application/octet-stream; #默认文件类型 sendfile on; #开启高效文件传输模式, the sendfile directive specifies whether Nginx calls the Sendfile function to output the file, which is set to off for normal applications, and if it is used for downloading applications such as disk IO heavy load applications. To balance disk and network I/O processing speed and reduce the load on the system. Note: If the picture does not appear normal, change this to off. keepalive_timeout , #长连接超时时间, Unit is the second gzip on; #启用Gizp压缩 # server cluster upstream netitcast.com { #服务器集群名字server 127.0.0.1:18080 weight=1; #服务器配置 weight is the weight, the greater the weight, the greater the probability of distribution. Server 127.0.0.1:28080 weight=2;} #当前的Nginx的配置 Server { listen ; #监听80端口 can be changed to a different port server_name localhost;############## Current service domain location/{ Proxy_pass http://netitcast.com; Proxy_redirect default; } Error_page 502 503 504 /50x.html; Location =/50x.html { root html;}} }
The core configuration is as follows:
With this configuration complete, the following starts to demonstrate load balancing.
7, first, we start Nginx:
8, then we can enter: localhost/index.jsp View Health
On the first visit, it was discovered that the program was accessed on TOMCAT2:
Then refresh, or access the program on the TOMCAT2:
Again, the discovery becomes the program on the TOMCAT1:
Again, the discovery becomes the program on the TOMCAT2:
To this, we have implemented a load-balanced tomcat cluster using Nginx. We constantly refresh and find that the probability of accessing Tomcat2 is about twice times that of TOMCAT1, which is due to the weight of the two Tomcat configured in Nginx, such as:
Iv. Summary
Who would have thought it would be so easy to implement a high-performance load-balancing cluster. Nginx is so powerful and so simple to configure, what reasons do we have to reject it? It's a lot cheaper than the F5 big-IP, NetScaler, and other hardware load-balancing switches that are more than 100,000 to hundreds of thousands of yuan. In addition, we should not forget that nginx is not only a reverse proxy server, it can also host the Web site, as a Web server, HTTP service processing.
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Nginx+tomcat build high-performance load Balancing cluster