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--
The following brings you nginx+tomcat dynamic and static separation + load balancing implementation steps and configuration process, hoping to give you some help in practical application. Load balancing involves more things, there are not many theories, and there are many books on the Internet. Today, we will use the accumulated experience in the industry to do an answer.
Introduction of static and dynamic separation and load balancing
Separation of movement and movement of Nginx+Tomcat:
The so-called static and dynamic separation is through nginx (or apache, etc.) to deal with static files such as pictures and html requested by the client, and tomcat (or weblogic) to deal with dynamic files such as jsp, do and so on, so that dynamic and static pages can be accessed through different containers. Nginx is much more efficient in dealing with static pages than tomcat, while tomcat is good at dynamic page processing, which can better improve concurrency and processing performance.
Load balancing of Nginx+Tomcat:
In the cloud server cluster, Nginx acts as a proxy server (i.e. reverse proxy). In order to avoid excessive pressure on a single server, it forwards requests from users to different servers. Tomcat is responsible for handling user requests forwarded by nginx.
2. Specific steps 1. Introduce the environment name, role address, centos7-1nginx192.168.142.153centos7-2Tomcat192.168.142.154centos7-3Tomcat192.168.142.132win7 client is not important (the same network segment is fine)
Objective:
When accessing the server, static pages are processed by the nginx server and dynamic pages are processed by tomcat
2. Tomcat configuration (the configuration of both Tomcat clients is the same)
Install the jdk environment package
[root@localhost tomcat] # rpm-ivh jdk-8u201-linux-x64.rpm [root@localhost tomcat] # cd / usr/java/jdk1.8.0_201-amd64/
Modify the global configuration file
[root@localhost jdk1.8.0_201-amd64] # vim / etc/profile// add export JAVA_HOME=/usr/java/jdk1.8.0_201-amd64 export CLASSPATH=$JAVA_HOME/lib/tools.jar:$JAVA_HOME/lib/dt.jar export PATH=$JAVA_HOME/bin:$PATH [root@localhost jdk1.8.0_201-amd64] # source / etc/profile [root@localhost jdk1.8.0_201-amd64] # cd / mnt/tomcat/
Install the Tomcat software ontology
[root@localhost tomcat] # tar zxvf apache-tomcat-9.0.16.tar.gz-C / usr/local/ [root@localhost tomcat] # cd / usr/local/ [root@localhost local] # mv apache-tomcat-9.0.16/ tomcat
Establish a start / stop soft link
[root@localhost local] # ln-s / usr/local/tomcat/bin/startup.sh / usr/local/bin/ [root@localhost local] # ln-s / usr/local/tomcat/bin/shutdown.sh / usr/local/bin/// start the service, turn off the firewall [root@localhost local] # startup.sh [root@localhost local] # systemctl stop firewalld.service [root@localhost local] # setenforce 0
Create the Tomcat home page
[root@tomcat1 local] # mkdir-p / web/webapp1 # build site [root@tomcat1 local] # vim / web/webapp1/index.jsp # New Tomcat homepage JSP test1 page
Specify in the configuration file
[root@tomcat1 local] # cd / usr/local/tomcat/conf/ [root@tomcat1 conf] # vim server.xml##149 Line insert / / Note: / / docBase: document benchmark directory of web application / / reloadable setting monitors whether "class" changes / / path= "" sets default "" class / / restart service [root@tomcat1 conf] # shutdown.sh [root@tomcat1 conf] # startup.sh 3, Nginx configuration
Install the environment package
[root@nginx ~] # yum-y install gcc gcc-c++ zlib-devel expat-devel pcre-devel pcre openssl-devel
Install the nginx software ontology
[root@nginx mnt] # cd / opt/nginx-1.12.0/ [root@nginx nginx-1.12.0] # useradd-M-s / sbin/nologin nginx [root@nginx nginx-1.12.0]. / configure\-- prefix=/usr/local/nginx\-- user=nginx-- group=nginx\-- with-file-aio\-- with-http_stub_status_module\-- with-http_gzip_static_module\-- with-http_flv_module\- -with-http_ssl_ module [root @ nginx nginx-1.12.0] # make & & make install
At this point, nginx will combine with Tomcat in three different directions, and I will explain them one by one here.
(1) nginx only provides load balancing and does not provide web services.
[root@nginx nginx-1.12.0] # vim / usr/local/nginx/conf/nginx.conf//gzip add upstream tomcat-server {/ / address pool name server 192.168.142.154vim 8080 weight=1; / / point to Tomcat address, use polling, the weight is the same server 192.168.142.132 vim 8080 weight=1;} / / location / segment, add proxy_pass http://tomcat-server; / / the agent points to the Tomcat address pool (previously specified)
(2) when only static and dynamic separation is performed by nginx
Add location ~ (.) after [root@nginx nginx-1.12.0] # vim / usr/local/nginx/conf/nginx.conf//server paragraph *). Jsp$ {proxy_pass http://192.168.142.132:8080; / / automatically proxies to the Tomcat server proxy_set_header Host $host;} when nginx encounters a web page ending in jsp
(3) nginx performs load balancing and reverse proxy at the same time
[root@nginx nginx-1.12.0] # vim / usr/local/nginx/conf/nginx.conf//gzip, add upstream tomcat-server {/ / address pool name server 192.168.142.154usr/local/nginx/conf/nginx.conf//gzip 8080 weight=1; / / to point to Tomcat address, use polling with the same weight server 192.168.142.132 usr/local/nginx/conf/nginx.conf//gzip 8080 weight=1;} / / add location ~ (. *). Jsp$ {proxy_pass http://tomcat-server; proxy_set_header Host $host;}
Start the service
[root@nginx nginx-1.12.0] # ln-s / usr/local/nginx/sbin/nginx / usr/local/sbin/ [root@nginx nginx-1.12.0] # nginx [root@nginx nginx-1.12.0] # systemctl stop firewalld.service
[root@nginx nginx-1.12.0] # setenforce 0
After reading the above about the implementation steps and configuration process of nginx+tomcat dynamic and static separation + load balancing, if there is anything else you need to know, you can find what you are interested in in the industry information or find our professional and technical engineer to answer, the technical engineer has more than ten years of experience in the industry.
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.