In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/03 Report--
First, the principle of Nginx load balancing: Nginx achieves load balancing through reverse proxy. (1) Nginx static processing advantage the efficiency of Nginx in handling static pages is much higher than that of Tomcat; if the number of requests of Tomcat is 1000, then the number of requests of Nginx is 6000; the throughput of Tomcat is 0.6m per second. The throughput of Nginx per second is 3.6m. Nginx's ability to process static resources is six times that of Tomcat, which has a great advantage. (2) Tomcat main directory bin: store startup and shutdown Tomcat scripts conf: store Tomcat different configuration files doc: store Tomcat documents lib/japser/common: store library files needed for Tomcat operation logs: store LOG files for Tomcat execution src: store Tomcat source code webapps:Tomcat main Web release directory work: store class files generated by jsp compilation (3) Nginx applications 1, Nginx is an excellent HTTP server software that supports responses of up to 50000 concurrent connections Has a strong static resource processing capacity; stable operation; memory, CPU and other system resources consumption is very low. 2. At present, many large websites have used Nginx server as the reverse proxy and load balancer of the back-end website program to improve the load concurrency ability of the whole site. (4) the principle of dynamic and static separation 1. When the server accepts the request from the client, there are both static and dynamic resources. 2. Set nginx to handle static images, backend Tomcat to process dynamic pages, modify Tomcat jsp files to specify image files, modify nginx configuration files to add regular processing images, create directories and add pictures (note that the project name needs to be the same as the Java project name) restart nginx; browser access test to check whether pictures are added View log files in nginx server and Tomcat server respectively. 2. Experiment case: experiment Topology Diagram (1) Network Diagram Overview:
(2) specific case experiments:
Role IP address Nginx 192.168.220.131Tomcat01 192.168.220.136Tomcat02 192.168.220.137 Experimental Environment description: prepare three virtual machines, one as a nginx proxy server for receiving user access requests, and two Tomcat servers (clusters); nginx forwards the client's request to multiple Tomcat servers in the background for processing, and Tomcat responds to the request and sends it to the client through the proxy server Experimental verification: the client only needs to access the address of the proxy server on the browser, and does not need to access the specific Tomcat in the background to access the web page information. Step 1: set up Nginx and nginx, which has been described in detail by the blog before. Step 2: deploy two Tomcat (1) configure JAVA environment 1, install jdkrpm-ivh jdk-8u201-linux-x64.rpm after installation at: / usr/java/2, configure environment variable vim / etc/profile Add the following code at the end of the file: export JAVA_HOME=/usr/java/jdk1.8.0_201-amd64export CLASSPATH=$JAVA_HOME/lib/tools.jar:$JAVA_HOME/lib/dt.jarexport PATH=$JAVA_HOME/bin:$PATH to make the environment variable take effect: source / etc/profile3, use the java-version command to check that the installation is successful
(2) install and start Tomcat1, extract the package to the specified path, / usr/local/tar zxvf apache-tomcat-9.0.16.tar.gz-C / usr/local/2, and generate an apache-tomcat-9.0.16 folder, renamed to Tomcatmv apache-tomcat-9.0.16/ tomcat3, in order to easily control the opening and closing of tomcat. We can create a soft link ln-s / usr/local/tomcat/bin/startup.sh / usr/bin/ln-s / usr/local/tomcat/bin/shutdown.sh / usr/bin/4 and open tomcat with the startup.sh script
Step 3: create a test page in Tomcat (1) create a directory mkdir-p / web/webapp1vim / web/webapp1/index.jsp add the following: JSP test1 page
)
(2) specify the site directory: / usr/local/tomcat/confvim server.xml add the following code:
(3) go back to the bin/ directory and restart the Tomcat./shutdown.sh. / startup.sh (4) browser to visit the web page to check whether it is successful.
(5) the deployment of the second Tomcat is exactly the same as that of the first, but in order to display the page differently, change the test1 to test2 in the / web/webapp1/index.jsp file with a slight modification
Note: in the enterprise network, the Tomcat site content in the cluster is exactly the same, no matter which Tomcat the customer visits, the website provided is the same. But here, in order to show the effect of the experiment, the content of the site is different, in order to distinguish which Tomcat provides the service response on the client side. Step 4: modify the Nginx configuration file, add the server pool (1) file location: / usr/local/nginx/conf/nginx.conf1, add the service pool: upstream tomcat-server {server 192.168.220.136 weight=1; server 8080 weight=1; 192.168.220.137 upstream tomcat-server 8080 weight=1;}
2. In the location section, add the following code to call the service pool (protocol, port, etc.) proxy_pass http://tomcat-server;
(2) restart nginx service killall-1 nginx step 5: the client tests this architecture, nginx only exists as a proxy server. When we visit the web page as users, we simply do not know which specific service server is behind. We just need to send the request to the nginx proxy server, which will call the Tomcat in the background to provide the user with a response. Access the nginx proxy server on the client browser:
We can see that the services provided by the cluster Tomcat can be accessed directly from the proxy server.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.