博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
nginx+tomcat+redis实现会话共享
阅读量:4334 次
发布时间:2019-06-07

本文共 2035 字,大约阅读时间需要 6 分钟。

1.环境准备(安装redis报错)

nginx,两个tomcat,redis (因为测试全部安装在同一台)

安装redis:

cd redis-4.0.9.tar.gz && cd redis-4.0.9 && make && cd src && make test

#make test的是报错1如下:

You need tcl 8.5 or newer in order to run the Redis test

make: *** [test] Error 1

解决:yum -y install tcl

#报错2如下:

[exception]: Executing test client: NOREPLICAS Not enough good slaves to write..

NOREPLICAS Not enough good slaves to write.

解决:

 

vim tests/integration/replication-2.tcl

 

- after 1000

 

+ after 10000

 

继续:make test && make install

启动redis :./redis-server

2.测试文件(在tomcat的webapps下面新建一个项目,两个tomcat项目名字一样,文件也一样,因为测试,访问的文件内容(最好加上session id)设置不一样看效果

  

3.tomcat配置

添加支持redis会话共享的插件(3个jar包)到tomcat/lib目录下

然后更改tomcat/conf下context.xml文件【context】节点下加如下代码【两个tomcat配置文件都要改下】: 

注:这是配置redis的链接信息,如果没有密码可以把passowrd项去掉 ,tomcat7 ,和tomcat8 对应支持resissession的jar也不一样(有三个),tomcat7 的插件在网上容易找到,现在网上插件(jar包)不支持tomcat8,能用的都是改过源码的,比较难找(本人暂时没有找到可以用的)

----------------------针对tomcat7的配置----------------------------

<Valve className="com.orangefunction.tomcat.redissessions.RedisSessionHandlerValve" />

<Manager className="com.orangefunction.tomcat.redissessions.RedisSessionManager"

      host="127.0.0.1"  

      port="6379"

      database="0"

      password="666"

      maxInactiveInterval="60" />

-------------------------针对tomcat8的配置-----------------------

<Valve className="com.demo.redis_session.RedisSessionHandlerValve" />

<Manager className="com.demo.redis_session.RedisSessionManager"

host="127.0.0.1" port="6379" database="0" password="666" maxInactiveInterval="60" />

 4.nginx配置  (附上主要代码)

cat /etc/nginx/conf.d/default.confupstream images_server {#ip_hash;server 192.168.110.28:8080;server 192.168.110.28:8081;}server {listen 80;server_name vm1.ql.com;location / {root /usr/share/nginx/html;index index.html index.htm;}location ~*/NginxTest/ {proxy_pass http://images_server;}error_page 500 502 503 504 /50x.html;location = /50x.html {root /usr/share/nginx/html;}}

 

5.结果验证

浏览器本地访问:(本地hosts加上域名解析)

http://vm1.ql.com/NginxTest/index.jsp

不断刷新浏览器,显示页面内容不一样,但session-id一直,则可说明已经实现了会话共享。

转载于:https://www.cnblogs.com/junzhu2/p/9055681.html

你可能感兴趣的文章
[置顶] 【cocos2d-x入门实战】微信飞机大战之三:飞机要起飞了
查看>>
BABOK - 需求分析(Requirements Analysis)概述
查看>>
第43条:掌握GCD及操作队列的使用时机
查看>>
Windows autoKeras的下载与安装连接
查看>>
CMU Bomblab 答案
查看>>
微信支付之异步通知签名错误
查看>>
2016 - 1 -17 GCD学习总结
查看>>
linux安装php-redis扩展(转)
查看>>
Vue集成微信开发趟坑:公众号以及JSSDK相关
查看>>
技术分析淘宝的超卖宝贝
查看>>
i++和++1
查看>>
react.js
查看>>
P1313 计算系数
查看>>
NSString的长度比较方法(一)
查看>>
Azure云服务托管恶意软件
查看>>
My安卓知识6--关于把项目从androidstudio工程转成eclipse工程并导成jar包
查看>>
旧的起点(开园说明)
查看>>
生产订单“生产线别”带入生产入库单
查看>>
crontab导致磁盘空间满问题的解决
查看>>
java基础 第十一章(多态、抽象类、接口、包装类、String)
查看>>