zoukankan      html  css  js  c++  java
  • 使用Redis存储Nginx+Tomcat负载均衡集群的Session (笔记)

    引用:http://blog.csdn.net/xlgen157387/article/details/52024139

    注意事项:

    nginx配置文件nginx.conf:

     upstream mynginxserver {
        #weigth参数表示权值,权值越高被分配到的几率越大
        #本机上的Squid开启3128端口
            server 127.0.0.1:8080 weight=1;
            server 127.0.0.1:8060 weight=1;
        }

        server {
            listen       80;

      #注意这地方是你本机的ip地址,不能随意写,我之前测试以为可以随意指定呢
            server_name  192.168.22.38;
            #access_log  logs/host.access.log  main;

            location / {
                #root   html;
                #index  index.html index.htm;
                proxy_pass http://mynginxserver;
            }

    tomcat配置文件context.xml:

    <!-- tomcat-redis-session -->
        <Valve className="com.orangefunction.tomcat.redissessions.RedisSessionHandlerValve" />  
            <Manager className="com.orangefunction.tomcat.redissessions.RedisSessionManager"

        #注意该ip地址为redis配置的host地址,否则会出现拒绝连接(我之前就是配置的192.168.22.38,出现问题百思不得其解,后来发现是redis host配置为“127.0.0.1”)
             host="127.0.0.1"   
             port="6379"   
             database="0"   
             maxInactiveInterval="60" />

    总结:nginx 同过server_name 配置访问地址,然后通过proxy_pass http://mynginxserver,实现负载均衡,在访问tomcat应用获取session时通过RedisSessionManager去redis数据库中查找;

    即:访问redis需要host="127.0.0.1" 和redis保持一致

    想的都是好
  • 相关阅读:
    2018ACM上海大都会赛 F Color it【基础的扫描线】
    2018大都会赛 A Fruit Ninja【随机数】
    两个数互质的概率
    【shell脚本学习-3】
    【mysql学习-1】
    【HCNE题型自我考究】
    【为系统营造的一个安全的环境】
    【nginx下对服务器脚本php的支持】
    【linux基于Postfix和Dovecot邮件系统的搭建】
    不同状态的动态路由协议对比
  • 原文地址:https://www.cnblogs.com/freezone/p/8297598.html
Copyright © 2011-2022 走看看