session共享之nginx+tomcat+redis
来源:互联网 发布:淘宝达人的推广方式 编辑:程序博客网 时间:2024/05/23 13:24
环境
centos6.4
nginx :192.168.44.137
tomcat1 :192.168.44.137
tomcat2 :192.168.44.139
redis :192.168.44.137
相关安装包:http://download.csdn.net/detail/tshangshi/9644017
nginx在前端做负载均衡,转发给后端tomcat进行处理,session存在reids服务器,实现session共享
redis
1.安装redis
# tar xvzf redis-stable.tar.gz
# cd redis-stable
# make
2.修改配置文件
# vim redis.conf
bind 192.168.44.137 #绑定的主机地址daemonize yes #以守护进程的方式运行
3.运行redis-server
# cd src && ./redis-server ../redis.conf
Nginx做负载均衡
# vim /etc/nginx/nginx.conf
upstream mytest.com { server 192.168.44.137:8080; server 192.168.44.139:8080; } server { listen 80; server_name www.nginx2.com; index index.jsp index.html index.htm; location / { proxy_redirect off; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header REMOTE-HOST $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_pass http://mytest.com; proxy_cookie_path /nginx2/ /; }
Tomcat
1.下载依赖jar包,放在 $TOMCAT_HOME/lib 目录下
tomcat-redis-session-manager-VERSION.jar
jedis-2.5.2.jar
commons-pool2-2.2.jar
2.context.xml(两个tomcat配置相同)
# vim $TOMCAT_HOME/conf/context.xml
添加
<Valve className="com.orangefunction.tomcat.redissessions.RedisSessionHandlerValve" /> <Manager className="com.orangefunction.tomcat.redissessions.RedisSessionManager" host="192.168.44.137" port="6379" database="0" maxInactiveInterval="60" />
3.server.xml
# vim $TOMCAT_HOME/conf/server.xml
tomcat1:
<Engine name="Catalina" defaultHost="192.168.44.137" jvmRoute="tomcat1"><Host name="192.168.44.137" appBase="webapps" unpackWARs="true" autoDeploy="true"> <Context path="" reloadable="true" docBase="/opt/rtomcat/webapps/test/" />
tomcat2:
<Engine name="Catalina" defaultHost="192.168.44.139" jvmRoute="tomcat2"><Host name="192.168.44.139" appBase="webapps" unpackWARs="true" autoDeploy="true"> <Context path="" reloadable="true" docBase="/opt/rtomcat/webapps/test/" />
4.测试页面 /opt/rtomcat/webapps/test/index.jsp
<%@ page contentType="text/html; charset=UTF-8" %><%@ page import="java.util.*" %><html><head><title>Tomcat Cluster Demo</title></head><body>Server Info:<%out.println(request.getLocalAddr() + " : " + request.getLocalPort()+"<br>");%><% out.println("<br> ID " + session.getId()+"<br>"); String dataName = request.getParameter("dataName"); if (dataName != null && dataName.length() > 0) { String dataValue = request.getParameter("dataValue"); session.setAttribute(dataName, dataValue); System.out.println("application:" + application.getAttribute(dataName)); application.setAttribute(dataName, dataValue); } out.print("<b>Session List</b>"); Enumeration<String> e = session.getAttributeNames(); while (e.hasMoreElements()) { String name = e.nextElement(); String value = session.getAttribute(name).toString(); out.println( name + " = " + value+"<br>"); System.out.println( name + " = " + value); }%> <form action="index.jsp" method="POST"> Name:<input type=text size=20 name="dataName"> <br> Value:<input type=text size=20 name="dataValue"> <br> <input type=submit> </form></body></html>
0 0
- session共享之nginx+tomcat+redis
- tomcat+redis+nginx session共享
- Nginx Redis tomcat session共享
- nginx-tomcat-redis共享session
- IT忍者神龟之Redis+Tomcat+Nginx集群实现Session共享
- Nginx+Tomcat+Redis实现负载均衡与Session共享之五 — Nginx+Tomcat+Redis实现Session共享
- nginx+tomcat+redis实现session共享
- nginx+tomcat+redis完成session共享
- nginx+tomcat+redis完成session共享
- Redis+Nginx+Tomcat实现Session共享
- nginx+tomcat+redis完成session共享
- tomcat redis nginx 实现session共享
- Nginx安装tomcat + redis session共享
- nginx+tomcat+redis负载均衡session共享
- nginx+tomcat+redis的集群+session共享
- Nginx+Tomcat+Redis实现session共享
- nginx+tomcat+redis完成session共享
- tomcat、redis、nginx实现session共享
- JSP学习笔记
- 关于STM32 使用ARM GCC编译链接C++生成固件的压缩、减少和优化大小的几个编译链接参数
- 自定义一个View作为弹出对话框
- 【Bash百宝箱】shell数组
- Android动画详解
- session共享之nginx+tomcat+redis
- JSTL学习笔记
- TortoiseGit安装与图形界面操作
- Ajax使用FormData对象上传文件
- Log4j学习笔记
- 数据结构实验之栈四:括号匹配
- LeetCode142—Linked List Cycle II
- DHCP协议
- 【Bash百宝箱】shell目录栈(dirs、pushd、popd)