In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/03 Report--
The following brings you a detailed explanation of Nginx+Tomcat load balancing cluster, 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.
Experimental topology diagram
Deployment of CVM role IP address operating system Nginx server 192.168.142.131centos 7tomcat 01 server 192.168.142.134centos 7tomcat 02 server 192.168.142.130centos 7 Experimental step 1: configure Nginx server # installation environment [root@nginx ~] # yum install gcc gcc-c++ pcre-devel zlib-devel # add Nginx management user [root@nginx] # useradd-M-s / sbin/nologin nginx# far Program shared source package [root@nginx] # smbclient-L / / 192.168.142.1 [root@nginx ~] # mount.cifs / / 192.168.142.1/tomcat / mnt# decompress the source package [root@nginx ~] # cd / mnt [root@nginx ~] # tar zxvf nginx-1.12.0.tar.gz-C / opt [root@nginx mnt] # cd / opt/nginx-1.12.0/# for configure configuration [root@nginx nginx-1 .12.0] #. / configure-- prefix=/usr/local/nginx-- user=nginx-- group=nginx-- with-http_stub_status_module-- with-http_gzip_static_module-- with-http_flv_module# compilation and installation [root@nginx nginx-1.12.0] # make & & make install# create a soft connection to let the system recognize the nginx startup script [root@nginx nginx-1.12.0] # ln-s / usr/local/nginx / sbin/nginx / usr/local/sbin/ # enable the service [root@nginx nginx-1.12.0] # nginx [root@nginx nginx-1.12.0] # systemctl stop firewalld.service [root@nginx nginx-1.12.0] # setenforce "startup configuration file directory creation startup script [root@nginx nginx-1.12.0] # vim / etc/init.d/nginx #! / bin/bash# chkconfig:-99 2" description: Nginx Service Control ScriptPROG= "/ usr/local/nginx/sbin/nginx" PIDF= "/ usr/local/nginx/logs/nginx.pid" case "$1" in start) $PROG ; stop) kill-s QUIT $(cat $PIDF);; restart) $0 stop $0 start;; reload) kill-s HUP $(cat $PIDF) *) echo "Usage: $0 {start | stop | restart | reload}" exit 1esacexit add execution permission [root@nginx nginx-1.12.0] # chmod + x / etc/init.d/nginx# add nginx to service management [root@nginx nginx-1.12.0] # chkconfig-- add nginx# startup service [root@nginx nginx-1.12.0] # service nginx start# to view service port status [root@nginx nginx-1.12] .0] # netstat-ntap | grep 80tcp 00 0.0.0.0 grep 80tcp 80 0.0.0.0 LISTEN 42092/nginx: master # modify the configuration file [root@nginx nginx-1.12.0] # vim / usr/local/nginx/conf/nginx.conf # gzip on # append the following four lines of entries to define the tomcat service pool and assign the weight upstream tomcat-server {server 192.168.142.134server 8080 weight=1; server 192.168.142.130 server 8080 weight=1;} server {listen 80; server_name localhost # append the following four lines of entries to support location ~. * .jsp$ {proxy_pass http://tomcat-server; proxy_set_header Host $host;} # charset koi8-r; # access_log logs/host.access.log main; location / {root html; index index.html index.htm # append the following line of entries to call the tomcat service pool resource proxy_pass http://tomcat-server;} # append the following four lines of entries to support the caching of all kinds of images for 30 days location ~. *\. (gif | jpg | jpeg | png | bmp | swf | css) ${root html/test; expires 30d } # check syntax [root@nginx nginx-1.12.0] # nginx- tnginx: the configuration file / usr/local/nginx/conf/nginx.conf syntax is oknginx: configuration file / usr/local/nginx/conf/nginx.conf test is successful# restart the service And check the service port status [root@nginx nginx-1.12.0] # service nginx stop [root@nginx nginx-1.12.0] # service nginx start [root@nginx nginx-1.12.0] # netstat-ntap | grep nginxtcp 0 0 0.0 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. Root@nginx nginx-1.12.0 * LISTEN 69680/nginx: master# creation site directory [root@nginx nginx-1 .12.0] # mkdir / usr/local/nginx/html/test# copy pictures to site directory [root@nginx nginx-1.12.0] # cp / mnt/game.jpg / usr/local/nginx/html/test step 2: configure Tomcat01 server # remote shared source package [root@tomcat01] # smbclient-L / / 192.168.142.1 [root@tomcat01] # mount.cifs / / 192.168.142.1/tomcat / mnt# solution Press the source code package cd / mnt [root@tomcat01 mnt] # tar zxvf jdk-8u91-linux-x64.tar.gz-C / usr/local [root@tomcat01 mnt] # tar zxvf apache-tomcat-8.5.16.tar.gz-C / usr/local/# declare the environment variable [root@tomcat01 mnt] # vim / etc/profileexport JAVA_HOME=/usr/local//jdk1.8.0_91export JRE_HOME=$ {JAVA_HOME} / jreexport CLASSPATH=.:$ {JAVA_HOME} / lib:$ {JRE_HOME} / libexport PATH=$ {JAVA_HOME} / bin:$PATH# effective environment variable [root@tomcat01 mnt] # source / etc/profile [root@tomcat01 ~] # cd / usr/local [root@tomcat01 local] # mv apache-tomcat-8.5.16/ tomcat## create a soft link to the tomcat startup script to the system directory It is convenient for the system to identify [root@tomcat01 local] # ln-s / usr/local/tomcat/bin/startup.sh / usr/local/bin/# to create the soft link of the tomcat shutdown script to the system directory Easy for the system to identify [root@tomcat01 local] # ln-s / usr/local/tomcat/bin/shutdown.sh / usr/local/bin/# startup service [root@tomcat01 local] # startup.sh Using CATALINA_BASE: / usr/local/tomcatUsing CATALINA_HOME: / usr/local/tomcatUsing CATALINA_TMPDIR: / usr/local/tomcat/tempUsing JRE_HOME: / usr/local//jdk1.8.0_91/jreUsing CLASSPATH: / usr / local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jarTomcat started.# View service port status [root@tomcat01 local] # netstat-ntap | grep 8080tcp6 0 0:: 8080: * LISTEN 111655/java # create site directory [root@tomcat local] # mkdir / usr/local/tomcat/webapps/test# edit site home page Content [root@tomcat01 local] # vim / usr/local/tomcat/webapps/test/index.jsp dynamic web page Welcom to Jiangsu
[root@tomcat01 local] # vim / usr/local/tomcat/conf/server.xml # append the following entry under line 149, # restart the service [root@tomcat01 local] # shutdown.sh [root@tomcat01 local] # startup.sh# turn off firewall and security features [root@tomcat02 local] # systemctl stop firewalld.service [root@tomcat02 local] # setenforce 0 step 3: configure the Tomcat02 server The steps are the same as the Tomcat01 server # Editing the content of the home page of the site [root@tomcat01 local] # vim / usr/local/tomcat/webapps/test/index.jsp dynamic page Welcom to NanJing
Step 4: use the client to validate the web page
The following web page content is different, in order to verify the polling mechanism of the load balancing cluster, the web page content is the same in the real online network environment!
After reading the above practical explanation about Nginx+Tomcat load balancer cluster, if you have anything else you need to know, you can find out what you are interested in in the industry information or find our professional and technical engineers who have more than ten years of experience in the industry. Official website link www.yisu.com
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.