centos 6.6 搭建nginx1.80+redis-3.0.2.tar + tomcat8做负载均衡
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了centos 6.6 搭建nginx1.80+redis-3.0.2.tar + tomcat8做负载均衡,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2633字,纯文字阅读大概需要4分钟。
内容图文
本文记录nginx+redis+tomcat实现session共享的过程
nginx安装:http://blog.csdn.net/grhlove123/article/details/47834673
redis安装:http://blog.csdn.net/grhlove123/article/details/47783471
准备两个tomcat,修改相应的端口 8080,9090
修改nginx.conf加上:
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;
}
修改nginx.conf的location成
location / {
root html;
index index.html index.htm;
proxy_pass http://backend;
}
启动nginx。
下载tomcat-redis-session-manager相应的jar包,主要有三个:
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
下载完成后拷贝到$TOMCAT_HOME/lib中
修改两tomcat的context.xml:
<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="60" />
</Context>
在tomcat/webapps/test放一个index.jsp
<%@ page language="java" %>
<html>
<head><title>TomcatA</title></head>
<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>
</html>
sessionID:<%=session.getId()%>
<br>
SessionIP:<%=request.getServerName()%>
<br>
SessionPort:<%=request.getServerPort()%>
<%
//为了区分,第二个可以是222
out.println("This is Tomcat Server 1111");
%>
启动tomcat,发现有异常:com.orangefunction.tomcat.redissessions.RedisSessionHandlerValve 类找不到
分别打开三个jar包,确实没有这个类,解决可以参考:
http://blog.csdn.net/qinxcb/article/details/42041023
通过访问http://10.10.49.20/test/
刷新:
可以看到虽然Server从1111变为2222,但session的创建时间没有变化,这就完成了session共享。
原文:http://www.cnblogs.com/Lzly/p/4939938.html
内容总结
以上是互联网集市为您收集整理的centos 6.6 搭建nginx1.80+redis-3.0.2.tar + tomcat8做负载均衡全部内容,希望文章能够帮你解决centos 6.6 搭建nginx1.80+redis-3.0.2.tar + tomcat8做负载均衡所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。