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保持一致

    想的都是好
  • 相关阅读:
    python--turtle库
    OpenCL编程基本流程及完整实例
    接口、虚函数、纯虚函数、抽象类
    [已解决问题] Could not find class XXX referenced from method XXX.<YYY>
    [基础] C++与JAVA的内存管理
    [OSX] 取消开机启动
    [基础] 重载的时候什么时候用引用&
    [JAVA关键字] synchronized
    [Audio processing] 常见语音特征 —— LPC
    [Audio processing] Harmonic change detection function (HCDF)
  • 原文地址:https://www.cnblogs.com/freezone/p/8297598.html
Copyright © 2011-2022 走看看