服务配置: 数量3台:tomcat_69 tomcat_108 nginx_134 redis:安装在tomcat_69上面,端口为6379 1.拷贝 redis-tomcat依赖包到/usr/local/tomcat7/lib目录下 下载地址:http://down.51cto.com/data/2126036 2.配置tomcat_69下的context.xml [[email protected]_server conf]# vim /usr/local/tomcat7/conf/context.xml <Valve className="com.orangefunction.tomcat.redissessions.RedisSessionHandlerValve" /> <Manager className="com.orangefunction.tomcat.redissessions.RedisSessionManager" host="localhost" port="6379" database="0" maxInactiveInterval="60"/> 3.配置tomcat_108下的context.xml [[email protected]_server ~]# vim /usr/local/tomcat7/conf/context.xml <Valve className="com.orangefunction.tomcat.redissessions.RedisSessionHandlerValve" /> <Manager className="com.orangefunction.tomcat.redissessions.RedisSessionManager" host="10.200.134.69" port="6379" database="0" maxInactiveInterval="60"/> 4.编辑一个tomcat的测试页面 vim /usr/local/tomcat7/webapps/ROOT/index.jsp <%@ page language="java" %> <html> <head><title>TomcatB</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()%> <% out.println("This tomcat server is 108"); %> 5.配置nginx.conf [[email protected]_server ~]# vim /usr/local/nginx/conf/nginx.conf http{.... upstream tomcat{ server 10.200.134.69:8080; server 10.200.134.108:8081; } server { .... location / { proxy_pass http://tomcat; } ...} ...} 6.#重启nginx /usr/local/nginx/sbin/nginx -s reload 7.#重启2个tomcat /usr/local/tomcat7/bin/startup.sh
8.#查看redis [[email protected]_server lib]# redis-cli 127.0.0.1:6379> KEYS * 1) "31CC406DA697E01839C9B04C1CADCB05" 2) "4865467A9DC8DA88C3EEE06731D81606" 3) "E029F555EE14331949D4CA53D3374890" 127.0.0.1:6379>
时间: 2024-10-27 00:33:53