cylszh 2016-12-24 04:13 采纳率: 33.3%
浏览 1529

memcached实现session共享问题

最近研究nginx + memcached + tomcat 实现负载均衡。
我按照网上大神们的blog来做,一个都没有成功的,我不知道大神们是怎么实现的,
求帮助。

用的两台centos7虚拟机,
vm1:192.168.206.128装了nginx、memcached、tomcat6
vm2:192.168.206.129装了memcached、tomcat6
最终测试session不能共享,访问第一次出现vm1,第二次出现vm2界面。session
每次都变化,后台tomcat启动后报这个错:

图片说明

主要配置如下:
1、vm1的nginx配置。

 #user  nobody;
worker_processes  1;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;


events {
    worker_connections  1024;
    use epoll;
}


http {
    include       mime.types;
    default_type  application/octet-stream;

    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';

    #access_log  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;

    upstream  localhost {  
              server   192.168.206.128:8089;
              server   192.168.206.129:8089;  
    }

    server {
        listen       80;
        server_name  localhost;

        charset utf-8;

        #access_log  logs/host.access.log  main;

        location /test {
            root   html;
            index  test.jsp;
            proxy_pass        http://localhost;  
            proxy_set_header  X-Real-IP  $remote_addr;  
            client_max_body_size  100m;  
        }

        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {
        #    proxy_pass   http://127.0.0.1;
        #}

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        #location ~ \.php$ {
        #    root           html;
        #    fastcgi_pass   127.0.0.1:9000;
        #    fastcgi_index  index.php;
        #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
        #    include        fastcgi_params;
        #}

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #    deny  all;
        #}
    }

2、vm1的tomcat下context.xml配置:




    <!-- Default set of monitored resources -->

    <WatchedResource>WEB-INF/web.xml</WatchedResource>



    <!-- Uncomment this to disable session persistence across Tomcat restarts -->

    <!--

    <Manager pathname="" />

    -->



    <Manager className="de.javakaffee.web.msm.MemcachedBackupSessionManager"

   memcachedNodes="n1:192.168.206.128:11211,n2:192.168.206.129:11211"   

   lockingMode="auto"

   sticky="false" 

   requestUriIgnorePattern= ".*\.(png|gif|jpg|css|js)$"    

   sessionBackupAsync= "false"   

   sessionBackupTimeout= "18000"  

   copyCollectionsForSerialization="true"   

   transcoderFactoryClass="de.javakaffee.web.msm.serializer.kryo.KryoTranscoderFactory"/>

</Context>

3、vm2中tomcat下context.xml配置:

 <Context>



    <!-- Default set of monitored resources -->

    <WatchedResource>WEB-INF/web.xml</WatchedResource>



    <!-- Uncomment this to disable session persistence across Tomcat restarts -->

    <!--

    <Manager pathname="" />

    -->

   <Manager className="de.javakaffee.web.msm.MemcachedBackupSessionManager"

   memcachedNodes="n1:192.168.206.128:11211,n2:192.168.206.129:11211"   

   lockingMode="auto"

   sticky="false" 

   requestUriIgnorePattern= ".*\.(png|gif|jpg|css|js)$"    

   sessionBackupAsync= "false"   

   sessionBackupTimeout= "18000"  

   copyCollectionsForSerialization="true"   

   transcoderFactoryClass="de.javakaffee.web.msm.serializer.javolution.JavolutionTranscoderFactory"/>

</Context>

4、tomcat/lib下jar包都放了:

图片说明

端口均已启动,截图如下:
tomcat端口:8089,memcached端口:11211,nginx端口:80
图片说明

访问后80端口对应界面效果:
图片说明

刷新后session就变成新的了如下:
图片说明

请研究过看看,这个要怎么弄才能实现session共享呢。

  • 写回答

1条回答 默认 最新

  • zqbnqsdsmd 2016-12-24 15:51
    关注
    评论

报告相同问题?

悬赏问题

  • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
  • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
  • ¥15 绘制多分类任务的roc曲线时只画出了一类的roc,其它的auc显示为nan
  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?