: This article mainly introduces Tomcat cluster and Session sharing + Nginx load. For more information about PHP tutorials, see. Although I have done it before, I often forget it. I will record it for future reference.
Related information:
Linux Tomcat running environment to build see another blog: http://blog.csdn.net/xiadi934/article/details/50911175
Tomcat7.0 official cluster documentation, detailed parameters please visit here: http://tomcat.apache.org/tomcat-7.0-doc/cluster-howto.html
If Nginx + Tomcat is set up in Linux, skip this step.
Ideas
- Use two machines: Windows, IP: 192.168.1.108, and virtual machines (Linux, IP: 192.168.25.132)
- Deployment of nginx + tomcat7 + web on Linux and deployment on Windows: tomcat7 + web
- Refer to the official Tomcat cluster example and use the built-in Tomcat cluster to share with the Session.
Implementation
- The server. xml file configuration in Tomcat on the Window remains unchanged. only the following configurations are modified.
...
- The configuration of the server. xml file in Tomcat on Linux remains unchanged.
"8">
"False" policylisteners> "true"/>
...
...
- Modify Nginx configuration and add it to server load balancer
Upstream backendServer {ip_hash; # Optional. select a web server based on the source IP address. If this parameter is omitted, select the web server server127.0.0.1: 8080 based on the default round robin mode; # Tomcatserver192.168.1.108: 8080; # Tomcat} server {# set listening port listen 80; charset UTF-8; # set server domain name (IP access and multi-domain access are not set) # server_name _ *; # server_name www.test.com; # enable shtml to support ssi on; ssi_silent_errors on; ssi_types text/shtml; # set the primary access log # access_log logs/access. log main; access_log/dev/null; error_page 404/404 .html; error_page 500502503504/50 x.html; location/{proxy_pass http: // backendServer; include proxy. conf ;}}
- Modify conf/web. xml under two Tomcat servers and add the following code at the end.
- Add to the test page, create the test folder under two Tomcat/webapps and create index. jsp. the code is as follows:
<% @ Page language = "java" import = "java. util. * "pageEncoding =" UTF-8 "%> <% String path = request. getContextPath (); String basePath = request. getScheme () + ": //" + request. getServerName () + ":" + request. getServerPort () + path + "/"; %>
">
Homepage
SessionID: <% = session. getId () %>
Session creation Time: <% = session. getCreationTime () %>
Server IP: <% = request. getRemoteHost () %>
Test
Start two Tomcat servers. if the test result is as follows, the server load balancer + cluster + Session sharing configuration is successful.
By default, Nginx accesses tomcat in Linux from the nearest IP address, as shown below:
Disable tomcat in Linux. after refreshing, access tomcat in Windows
Check the creation time of the Session. it indicates that the Session is successfully created.
'). AddClass ('pre-numbering '). hide (); $ (this ). addClass ('Has-numbering '). parent (). append ($ numbering); for (I = 1; I <= lines; I ++) {$ numbering. append ($ ('
'). Text (I) ;}; $ numbering. fadeIn (1700) ;}) ;}; script
The above introduces Tomcat cluster and Session sharing + Nginx load, including some content, hope to be helpful to friends who are interested in PHP tutorials.