CentOS 6.6 builds Nginx1.80+redis-3.0.2.tar + tomcat8 for load balancing

Source: Internet
Author: User

This document records the process of Nginx+redis+tomcat implementing session sharing.

Nginx Installation: http://blog.csdn.net/grhlove123/article/details/47834673

Redis Installation: http://blog.csdn.net/grhlove123/article/details/47783471

Prepare two Tomcat and modify the appropriate port 8080,9090

Modify nginx.conf Plus:

Upstream Backend {
Server 10.10.49.23:8080 Max_fails=1 fail_timeout=10s;
Server 10.10.49.15:8081 Max_fails=1 fail_timeout=10s;
}

Modify the location of the nginx.conf into

Location/{
root HTML;
Index index.html index.htm;
Proxy_pass Http://backend;
}

Start Nginx.

Download Tomcat-redis-session-manager the corresponding jar package, there are three main:

wget https://github.com/downloads/jcoleman/tomcat-redis-session-manager/ Tomcat-redis-session-manager-1.2-tomcat-7-java-7.jar
wget Http://central.maven.org/maven2/redis/clients/jedis/2.5.2/jedis-2.5.2.jar
wget Http://central.maven.org/maven2/org/apache/commons/commons-pool2/2.0/commons-pool2-2.0.jar

Copy to $tomcat_home/lib when download is complete

Modify the Context.xml of two tomcat:

<Context>

<!--Default set of monitored resources--
<WatchedResource>WEB-INF/web.xml</WatchedResource>

<!--uncomment this to disable session persistence across Tomcat restarts-
<!--
<manager pathname= ""/>
-

<!--uncomment this to enable Comet connection tacking (provides events
On session expiration as well as WebApp lifecycle)--
<!--
<valve classname= "Org.apache.catalina.valves.CometConnectionManagerValve"/>
-

<valve classname= "Com.orangefunction.tomcat.redissessions.RedisSessionHandlerValve"/>
<manager classname= "Com.orangefunction.tomcat.redissessions.RedisSessionManager"
Host= "10.10.49.20"
Port= "6379"
database= "0"
Maxinactiveinterval= "/>"
</Context>

Put a index.jsp in tomcat/webapps/test.

<%@ page language= "java"%>
<body>

<table align= "centre" border= "1" >
<tr>
<td>session id</td>
<td><%= Session.getid ()%></td>
</tr>
<tr>
<td>created on</td>
<td><%= session.getcreationtime ()%></td>
</tr>
</table>
</body>
Sessionid:<%=session.getid ()%>
<br>
Sessionip:<%=request.getservername ()%>
<br>
Sessionport:<%=request.getserverport ()%>
<%
To differentiate, the second one can be 222.
Out.println ("This is Tomcat Server 1111");
%>

Started Tomcat, found an exception: Com.orangefunction.tomcat.redissessions.RedisSessionHandlerValve class could not find

Open three jar packages respectively, do not have this class, the solution can be consulted:

http://blog.csdn.net/qinxcb/article/details/42041023

by visiting http://10.10.49.20/test/


Refresh:

You can see that although server has changed from 1111 to 2222, the session creation time has not changed, which completes the session sharing.

CentOS 6.6 builds Nginx1.80+redis-3.0.2.tar + tomcat8 for load balancing

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.