1.nginx test: First downloaded from the official website Nginx website is: http://nginx.org/and then find stable version of the download, because this version is the most stable, do not go to download the latest, because of instability, such as:
After downloading the extract, you can
Here also to the decompression of the Nginx conf directory under the NGINX.CONF configuration such as:
The Proxy_pass Http://test-service in the meaning that only tomcat under Test-service can pass my reverse proxy.
We then launched two Tomcat and placed note two on the two Tomcat WebApps, noting that two tomcat ports were not conflicting. Enter http://localhost/test_war/index.jsp in the browser,
Display, not refreshed 2 times the browser forwards the request to another tomcat, as you can see, the algorithm for load balancing is configured by default to poll.
Algorithm for load Balancing:
1. Polling: This is the fairest principle, that is, every n requests are distributed to TOMCAT1, and the next n requests are distributed to TOMCAT2. For example, a tomcat1 of 1th, Tomcat2 2nd, 1th then the tomcat1,2 is divided to Tomcat2, No. 3rd No, then start again from TOMCAT1.
2. Random algorithm: Distribute the request to the appropriate tomcat by a certain range of random numbers. When the request volume is very large, it is actually very close to polling.
3. Source Address hash: the corresponding hashcode is calculated by the IP of the requested source to be distributed to the appropriate Tomcat, as long as the IP does not change the request for the distribution of Tomcat is fixed.
4. Weighted polling: On the basis of the poll to increase the weight, for example, now is TOMCAT1,TOMCAT2, at this time TOMCAT2 weighted weight 4, then the polling order is TOMCAT1,TOMCAT2,TOMCAT2,TOMCAT2,TOMCAT2,TOMCAT2.
5. Weighted random method (Weight random): Similar to weighted polling. For example, TOMCAT1,TOMCAT2, at this time tomcat2 increase the weight of 4, then tomcat1,tomcat2,tomcat2,tomcat2,tomcat2,tomcat2, then tomcat randomly distributed when the chance of distribution increased.
6. Minimum connection number method (Least Connections): According to the current connection situation of the back-end server, dynamically select a server with the fewest number of current backlog connections to process the current request.
Even if one of the tomcat is hung at this point, the request service will also be accessed normally. There is another tomcat running on the outside.
Nginx Note 3-load Balancing algorithm