您的位置:首页 > 数据库 > Redis

tomcat redis session 共享

2015-07-04 19:51 555 查看
1.依赖包下载

注意:下载后解压依赖包,并把它们放到
tomcat 的 lib 目录下。

1.redis配置(192.168.159.131:16300)(v2.8.3)

2.tomcat配置

tomcat1(192.168.159.130:8081)

tomcat2(192.168.159.130:8082)

3.nginx安装在192.168.159.131。

首先,是配置tomcat,使其将session保存到redis上。有两种方法,也是在server.xml或context.xml中配置,不同的是memcached只需要添加一个manager标签,而redis需要增加的内容如下:(注意:valve标签一定要在manager前面,注意 Value 和 Manager 是存放在 Context 标签里面的。)

<Context path="" docBase="ajax" debug="0" reloadable="false">
<Valve className="com.radiadesign.catalina.session.RedisSessionHandlerValve" />
<Manager className="com.radiadesign.catalina.session.RedisSessionManager"
host="127.0.0.1"
port="6379"
database="0"
maxInactiveInterval="60"/>
</Context>


4.Nginx 配置
upstream redis.xxy.com {

server 192.168.159.130:8081;

server 192.168.159.130:8082;

}

log_format www_xy_com '$remote_addr - $remote_user [$time_local] $request '

'"$status" $body_bytes_sent "$http_referer"'

'"$http_user_agent" "$http_x_forwarded_for"';

server

{

listen 80;

server_name redis.xxy.com;

location / {

proxy_pass http://redis.xxy.com;
proxy_set_header Host $host;

proxy_set_header X-Real-IP $remote_addr;

proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

}

access_log /data/base_files/logs/redis.xxy.log www_xy_com;

}

最后,将你的应用放到两个tomcat中,并依次启动redis、tomcat、nginx。访问你的nginx,可以发现两个tomcat中的session可以保持共享了。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: