Nginx+Tomcat load balancing

Introduction to knowledge part
: As we all know, Nginx, as a lightweight HTTP server, has the advantages of high concurrent processing and low resource consumption. However, Nginx, like Apache, has great advantages in processing static pages, while processing dynamic pages is not as good as Tomcat. We can solve this problem by separating static and dynamic pages with Nginx and Tomcat.
Tomcat: It is a free and open source Web lightweight application server. It is used in small and medium-sized systems and environments with less concurrent access. It is the first choice for developing and debugging JSP programs. Generally speaking, Tomcat has the same ability to process static page HTML as Apache and Nginx, but it is far inferior to Apache and Nginx in this respect, so Tomcat usually runs as a Servlet and JSP container on the backend alone.
Operation steps
In this case, we need to use one Nginx server and two Tomcat servers
Nginx+Tomcat load balancing
1. For the installation and configuration of Nginx server, please refer to this document:
http://blog.51cto.com/13434336/2102925
2. Tomcat part. Mount the CD and install the JDK. JDK is a Java language development kit provided by Sun for free, which contains the Java Virtual Machine (JVM), which can interpret Java bytecodes and ensure the cross-platform nature of Java.
Nginx+Tomcat load balancing
3. Create a Java.sh script under /etc/profile.d/
Nginx+Tomcat load balancing
4. Import the script into the environment variable to make it effective.
Nginx+Tomcat load balancing
5. Use java -version to view the Java version, which also means that the installation was started successfully.
Nginx+Tomcat load balancing
6. Install Tomcat.
Nginx+Tomcat load balancing
7. Create a Java web site and make a web page.
Nginx+Tomcat load balancing
The web page is made as shown below
Nginx+Tomcat load balancing
8. Modify the Tomcat main configuration file /usr/local/tomcat7/conf/server.xml. Find the location and add the following two lines
Nginx+Tomcat load balancing
9. Start the Tomcat service. (shudown.sh is used to stop Tomcat, and startup.sh is used to start Tomcat)
Nginx+Tomcat load balancing
10. Tomcat runs on port 8080 by default. After starting Tomcat, you can see that port 8080 is open.
Nginx+Tomcat load balancing
11. Use the Firefox browser on this machine to test whether Tomcat is running normally. (Tomcat's default port is 8080, so the port should be added during the test)
Nginx+Tomcat load balancing
12. Configure the address and enable the exception of port 8080.
Nginx+Tomcat load balancing
13. In another Tomcat, we will make small changes to the web page to facilitate the test results, and the ip address is configured as 192.168.1.2; The rest of the configuration is the same. Note: In the normal configuration, the configuration of the two Tomcats should be exactly the same. This time, the webpage settings are different to facilitate the test results.
Nginx+Tomcat load balancing
14. Local test.
Nginx+Tomcat load balancing
15. Modify the Nginx configuration file, vim /usr/local/nginx/conf/nginx.conf. First declare the addresses of the two Tomcat servers in the following figure. The weight is the weight. Setting the weight to the same means load balancing.
Nginx+Tomcat load balancing
Add the following line to the position in the figure below, indicating that the default battle of Nginx is proxyed to the set Tomcat load balancing server group through the proxy_pass method.
Nginx+Tomcat load balancing
16. Restart the Nginx service.
Nginx+Tomcat load balancing
17. Configure the address 192.168.1.3 for Nginx and verify. First visit the website on Nginx,
Nginx+Tomcat load balancing
then refresh the page.
Nginx+Tomcat load balancing

Guess you like

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