zoukankan      html  css  js  c++  java
  • 【nginx】nginx tomcat session 共享配置

    tomcat,redis下载忽略。

     一、从github上下载源码,https://github.com/jcoleman/tomcat-redis-session-manager,

    将源码复制到开发工具,打包成jar.注意tomcat版本,此处用tomcat 7.0.72,maven编译环境同样为1.7.

     

    二、准备两个tomcat, 版本为上述7.0.72。

     

    并修改指定端口,8081,8082,将上述jar,redis,commons-pool2

     

    放到tomcat lib目录中。

    按照github上指定的使用方法配置tomcat,

     

    这里使用单机redis,不使用集群。

    在每一个tomcat context.xml中配置:

    <!--redis session 配置-->
    
    <Valve className="com.orangefunction.tomcat.redissessions.RedisSessionHandlerValve" />
    
    <Manager className="com.orangefunction.tomcat.redissessions.RedisSessionManager"
    
    host="localhost"
    
    port="6379"
    
    database="0"
    
    maxInactiveInterval="60" />

    至此tomcat配置完成。

     三、nginx安装配置

    1.下载解压到opt下

     

    2.执行命令,配置命令以及配置文件的位置

     

    出现错误,

     

    安装pcre-devel,yum -y install pcre-devel

     

    再次执行配置,

     

    配置成功。

    执行make

    make install

    安装完成。

    3.

    修改opt/nginx/conf/nginx.conf,修改端口83,默认80.

     

    启动nginx

     

    访问ip:83,出现下面界面正常。

     

    停止nginx, /opt/nginx/sbin/nginx -s stop

     

    四、nginx 配置tomcat集群

    注意一定在http节点下配置,

     

    更多关于upstream的负载均衡策略介绍参考

    Nginx配置upstream实现负载均衡

    http://www.linuxidc.com/Linux/2015-03/115207.htm

    访问ip:83,可正常访问到不同的tomcat即负载均衡配置正常,为正常区分访问的是不同的tomcat,将

    webapps/ROOT/index.jsp修改一下比如Home->Home111等方便区分的。

    五、将项目部署到tomcat中,或者获取session信息比较,刚好有现成项目直接测试一下。

    登录后点击相应链接不会跳转到登录页面或抛出异常即redis共享配置成功。

  • 相关阅读:
    zabbix(三)网页操作
    zabbix(二)安装客户端
    zabbix(一)安装服务端
    python操作git
    elasticsearch之match
    elasticsearch之查询的两种方式
    Git 命令集合啦
    Django contenttype 组件
    Django 中 related_name/related_query_name 的区别
    Django中的CharField 和 FileField 主要讲FileField
  • 原文地址:https://www.cnblogs.com/lonelywolfmoutain/p/6285509.html
Copyright © 2011-2022 走看看