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

Tomcat+nginx clustering and static and dynamic separation

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

Share

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

Experimental environment

Nginx server (192.168.13.177)

Tomcat1 server (192.168.13.151)

Tomcat2 Server (192.168.13.178)

Client testing machine

One, load balancer 1, in Tomcat1 Install Tomcat service on Tomcat2 [root@tomcat1 ~] # systemctl stop firewalld.service # # close the firewall [root@tomcat1 ~] # mkdir / abc [root@tomcat1 ~] # mount.cifs / / 192.168.100.3/LNMP-C7 / abc/ [root@tomcat1 ~] # cd / abc/tomcat/ [root@tomcat1 tomcat] # tar zxvf jdk-8u91-linux-x64.tar.gz-C / usr/local/ # # decompress JDK [root@tomcat1 tomcat] # vim / etc/ Profile # # configure environment variable # # add export 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 [root@tomcat1 tomcat] # source / etc/profile # # refresh configuration file [root@tomcat1 tomcat] # tar zxvf apache-tomcat-8.5.16.tar.gz-C / at the end of Big G Usr/local/ # # decompress [root@tomcat1 tomcat] # cd / usr/local/ [root@tomcat1 local] # mv apache-tomcat-8.5.16/ tomcat [root@tomcat1 local] # ln-s / usr/local/tomcat/bin/startup.sh / usr/local/bin/ the startup and shutdown scripts are easy for the system to recognize [root@tomcat1 local] # ln-s / usr/local/tomcat/bin/shutdown.sh / usr/local/bin/ [root@tomcat1 local] ] # mkdir-p / web/webapp1 # # create site [root@tomcat1 local] # vim / web/webapp1/index.jsp # # write jsp page content # # jsp page content JSP test1 page # # output information [root@tomcat1 local] # vim / usr/local/tomcat/conf/server.xml # # modify Tomcat configuration document # # add site information [root@tomcat1 ~] # startup.sh # # Startup Service # # the content of web pages on Tomcat is the same as other configurations for accp 2 Install Nginx on the Nginx server [root @ nginx ~] # systemctl stop firewalld.service # # close the firewall [root@nginx ~] # setenforce 0 [root@nginx ~] # yum install pcre-devel zlib-devel gcc gcc-c++ make-y # # essential components of the installation environment [root@nginx ~] # mkdir / abc [root@nginx ~] # mount.cifs / / 192.168.100.3/LNMP-C7 / abc/ # # mount Password for root@// 192.168.100.3/LNMP-C7: [root@nginx ~] # cd / abc/ [root@nginx abc] # tar zxvf nginx-1.12.2.tar.gz-C / usr/local/ # # decompress [root@nginx abc] # useradd-M-s / sbin/nologin nginx # # create a system user [root@nginx abc] # cd / usr/local/nginx-1.12.2/ [root@nginx nginx-1.12.2] #. / configure \ # # configuration >-- prefix=/usr/local/nginx\ >-- user=nginx\ >-- group=nginx\ >-- with-http_stub_status_module\ >-- with-http_gzip_static_module\ >-- with-http_flv_module [root@nginx nginx-1.12.2] # make & & make install # # compile and install 3 Modify Nginx configuration file [root@nginx nginx-1.12.2] # vim / usr/local/nginx/conf/nginx.conf # keepalive_timeout 0 Keepalive_timeout 65; # gzip on; upstream tomcat-server {# add address pool server 192.168.13.151 server 8080 weight=1; server 192.168.13.178 weight=1 } server {listen 80. Omit location / {root html; index index.html index.htm; proxy_pass http://tomcat-server; # add a proxy and call the server address pool} [root@nginx nginx-1.12.2] # ln-s / usr/local/nginx/sbin/nginx / usr/local/sbin/ # # easy for the system to identify [root@nginx nginx-1.12.2] # nginx # # start the service

Second, change the configuration file [root@nginx nginx-1.12.2] # vim / etc/init.d/nginx # # on Nginx and write the service startup script #! / bin/bash#chkconfig:-99 20#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 0 [root@nginx nginx-1.12.2] # chmod + x / etc/init.d/nginx [root@nginx nginx-1.12.2] # chkconfig-add nginx [root@nginx nginx-1.12.2] # vim / usr/local/nginx/conf/nginx.confserver {. Omit. Location ~. * .jsp$ {# # matches jsp page jump proxy server pool proxy_pass http://tomcat-server; proxy_set_header Host $host;} location / {root html/test; # # modify site index index.html index.htm; proxy_pass http://tomcat-server; } [root@nginx nginx-1.12.2] # vim / usr/local/nginx/html/index.html # # write static web pages body {width: 35eme; margin: 0 auto; font-family: Tahoma, Verdana, Arial, sans-serif;} static pages

This is a static page.

[root@nginx nginx-1.12.2] # service nginx stop # # disable and enable the service [root@nginx nginx-1.12.2] # service nginx start2, in Tomcat1 Create a jsp dynamic page on Tomcat2 [root@tomcat1 ~] # mkdir / usr/local/tomcat/webapps/test [root@tomcat1 ~] # vim / usr/local/tomcat/webapps/test/index.jsp # # begin with a statement that dynamic page 1 is modified to dynamic page 22 on Tomcat2 / access static http://192.168.13.177/ access dynamic http://192.168.13.177/test/index.jspNginx to process static images Tomcat handles dynamic page 1, adding pictures [root@tomcat1 ~] # vim / usr/local/tomcat/webapps/test/index.jsp dynamic page to the page on Tomcat1,Tomcat2

/ / add page image [root@tomcat01 local] # vim / usr/local/tomcat/conf/server.xml # append the following entry under line 149, [root@tomcat1 test] # shutdown.sh # # close and restart [root@tomcat1 test] # startup.sh2, and modify the configuration file [root@nginx nginx-1.12.2] # vim / usr/local/nginx/conf/nginx.conflocation. * on Nginx. (gif | jpg | jpeg | png | bmp | swf | css) ${root html/test; expires 30d } [root@nginx nginx-1.12.2] # mkdir / usr/local/nginx/html/test [root@nginx nginx-1.12.2] # cp / abc/11.jpg / usr/local/nginx/html/test/# restart service 3, use client to test

[root@nginx html] # service nginx restart

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