Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the cluster management of load balancing based on nginx build tomcat9.0 (version)

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/03 Report--

The following brings you what is based on nginx to build tomcat9.0 (version) load balancing cluster management, hoping to give you some help in practical application, load balancing involves more things, there are not many theories, there are many books online, today we use the accumulated experience in the industry to do an answer.

Experimental environment preparation

Three CentOS7 virtual machines, one win7 virtual machine

CentOS7-1 nginx scheduling CVM IP address: 192.168.234.174

CentOS7-2 tomcat server 1 IP address: 192.168.234.177

CentOS7-3 tomcat Server 2 IP address: 192.168.234.181

Win7 client access IP address: 192.168.234.50

Experiment preparation package: jdk-8u171-linux-x64.rpm,

Apache-tomcat-9.0.8.tar.gz 、

Nginx-1.12.0.tar.gz

Deployment of Lab tomcat Server 1

First deploy tomcat server 1, mount the shared software package, and turn off the firewall

[root@localhost ~] # mkdir / abc / / create a mount point [root@localhost ~] # mount.cifs / / 192.168.234.1/ruanjiangongju / abc / / Mount the shared software package Password for root@//192.168.234.1/ruanjiangongju: [root@localhost ~] # systemctl stop firewalld.service / / turn off the firewall [root@localhost ~] # setenforce 0 / / disable the enhanced security feature

Install jdk environment, install tomcat9.0

[root@localhost tomcat] # rpm-ivh jdk-8u171-linux-x64.rpm / / one-click install jdk package [root@localhost tomcat] # vim / etc/profile.d/java.sh / / write a script for java.sh Import the environment variable export JAVA_HOME=/usr/java/jdk1.8.0_171-amd64export CLASSPATH=$JAVA_HOME/lib/tools.jar:$JAVA_HOME/lib/dt.jarexport PATH=$JAVA_HOME/bin:$ path [root @ localhost tomcat] # source / etc/profile.d/java.sh / / refresh Make the environment variable effective [root@localhost tomcat] # tar zxvf apache-tomcat-9.0.8.tar.gz-C / opt / / extract the package of tomcat9.0 to the / opt directory [root@localhost opt] # mv apache-tomcat-9.0.8/ / usr/local/tomcat9 / / move tomcat to / usr/local directory The command to enable the system to recognize tomcat [root@localhost opt] # / usr/local/tomcat9/bin/startup.sh / / enable the tomcat service [root@localhost opt] # netstat-ntap | the default port of grep 8080 / / tomcat is port 8080. Check whether the next port 8080 is open.

After tomcat is enabled here, use the local Firefox browser to access the local IP address to test whether you can access the tomcat home page normally.

After normal access, write a home page so that the later experiment can be divided into two tomcat servers

[root@localhost opt] # mkdir-pv / web/webapp1 [root@localhost opt] # vim / web/webapp1/index.jsp JSP test1 page / / output test1 [root@localhost opt] # vim / usr/local/tomcat9/conf/server.xml... shown here ... Omit / / add the following two sentences The docBase:web application's document base directory reloadable setting monitors whether the "class" changes path= ", sets the default" class "[root@localhost opt] # / usr/local/tomcat9/bin/shutdown.sh [root@localhost opt] # / usr/local/tomcat9/bin/startup.sh

After restarting the tomcat service, we visit the local IP using our local Firefox browser to check whether the home page has been successfully written

Deployment of tomcat Server 2

Mount the shared software package and turn off the firewall

[root@localhost ~] # mkdir / abc / / create a mount point [root@localhost ~] # mount.cifs / / 192.168.234.1/ruanjiangongju / abc / / Mount the shared software package Password for root@//192.168.234.1/ruanjiangongju: [root@localhost ~] # systemctl stop firewalld.service / / turn off the firewall [root@localhost ~] # setenforce 0 / / disable the enhanced security feature

Install jdk environment, install tomcat9.0

[root@localhost tomcat] # rpm-ivh jdk-8u171-linux-x64.rpm / / one-click install jdk package [root@localhost tomcat] # vim / etc/profile.d/java.sh / / write a script for java.sh Import the environment variable export JAVA_HOME=/usr/java/jdk1.8.0_171-amd64export CLASSPATH=$JAVA_HOME/lib/tools.jar:$JAVA_HOME/lib/dt.jarexport PATH=$JAVA_HOME/bin:$ path [root @ localhost tomcat] # source / etc/profile.d/java.sh / / refresh Make the environment variable effective [root@localhost tomcat] # tar zxvf apache-tomcat-9.0.8.tar.gz-C / opt / / extract the package of tomcat9.0 to the / opt directory [root@localhost opt] # mv apache-tomcat-9.0.8/ / usr/local/tomcat9 / / move tomcat to / usr/local directory The command to enable the system to recognize tomcat [root@localhost opt] # / usr/local/tomcat9/bin/startup.sh / / enable the tomcat service [root@localhost opt] # netstat-ntap | the default port of grep 8080 / / tomcat is port 8080. Check whether the next port 8080 is open.

After tomcat is enabled here, use the local Firefox browser to access the local IP address to test whether you can access the tomcat home page normally.

After normal access, write a home page so that the later experiment can be divided into two tomcat servers

[root@localhost opt] # mkdir-pv / web/webapp1 [root@localhost opt] # vim / web/webapp1/index.jsp JSP test1 page / / output test2 [root@localhost opt] # vim / usr/local/tomcat9/conf/server.xml... ... Omit / / add the following two sentences The docBase:web application's document base directory reloadable setting monitors whether the "class" changes path= ", sets the default" class "[root@localhost opt] # / usr/local/tomcat9/bin/shutdown.sh [root@localhost opt] # / usr/local/tomcat9/bin/startup.sh

After restarting the tomcat service, we visit the local IP using our local Firefox browser to check whether the home page has been successfully written

Deployment of nginx scheduling server

First install the relevant environment package

[root@localhost ~] # yum install gcc gcc-c++ pcre-devel zlib-devel openssl-devel-y

Mount the shared software folder and install nginx1.12.0

[root@localhost ~] # mkdir / abc [root@localhost ~] # mount.cifs / / 192.168.234.1/ruanjiangongju / abcPassword for root@//192.168.234.1/ruanjiangongju: [root@localhost tomcat] # tar xf nginx-1.12.0.tar.gz-C / opt [root@localhost nginx-1.12.0] # useradd-s / bin/false www [root@localhost tomcat] # cd / opt/nginx-1.12.0/ [root@localhost nginx-1 .12.0] #. / configure\ >-- prefix=/usr/local/nginx\ >-- user=www\ >-- group=www\ >-- with-file-aio\ >-- with-http_stub_status_module\ >-- with-http_gzip_static_module\ >-- with-http_flv_module\ >-- with-http_ssl_ module [root @ localhost nginx-1.12.0] # make & & make install [root@localhost nginx-1.12.0] # vim / usr/local/nginx/conf/nginx.conf... ... Omit # gzip on; upstream tomcat-server {/ / define the name of the service pool # add server 192.168.234.177 weight=1; server 192.168.234.181 weight=1; server 8080 weight=1; / / address points to two tomcat servers, weight 1}. Omit location / {root html; index index.html index.htm; proxy_pass http://tomcat-server; # add / / invoke service pool

All right, so the nginx scheduling server is configured, and you can use / usr/local/nginx/sbin/nginx-t to check for syntax errors.

[root@localhost nginx-1.12.0] # / usr/local/nginx/sbin/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

Then configure a soft link and open the nginx service to check whether the service is enabled or not

[root@localhost nginx-1.12.0] # ln-s / usr/local/nginx/sbin/nginx / usr/local/sbin/ [root@localhost nginx-1.12.0] # nginx [root@localhost nginx-1.12.0] # netstat-ntap | grep nginxtcp 0 0 0.0 0. 0. 0. 0. 0. 0. 0. 0.

All right, all the nginx deployments here have been completed, and the next step is to use the win7 client to access the IP address of the nginx scheduling server to see if load balancing can be achieved.

Click Refresh to see the content of the home page jump between the two tomcat homepages.

This shows that our experiment is successful, so the load balancer cluster management experiment of nginx building tomcat9.0 is completed.

After reading the above about what is the cluster management of load balancing based on nginx tomcat9.0 (version), if there is 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 for answers. Technical engineers 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.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report