nginx + memcached-session-manager 实现tomcat下的负载均衡

作者: 101.key
发布时间:2015-07-13 11:12:02

1. tomcat6.0 配置

memcached-session-manager 实现session共享

1.1 下载memcached-session-manager-1.6.5.jar、memcached-session-manager-tc6-1.6.5.jar(tomcat6.0)、msm-javolution-serializer-1.6.5.jar、spymemcached-2.8.12.jar、javolution-5.4.3.1.jar和couchbase-client-1.1.4.jar  共5个jar包放入tomcat的lib目录下;

1.2 context节点下增加如下配置

 <Manager className="de.javakaffee.web.msm.MemcachedBackupSessionManager"      memcachedNodes="n1:192.168.1.104:11211"   sticky="false"      requestUriIgnorePattern=".*\.(png|gif|jpg|css|js)$"      sessionBackupAsync="false"      sessionBackupTimeout="100"      transcoderFactoryClass="de.javakaffee.web.msm.serializer.javolution.JavolutionTranscoderFactory"      copyCollectionsForSerialization="false"      />

2.nginx-1.5.6 配置

#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;  }      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  10;        #gzip  on;      upstream   localhost  {             server    192.168.1.104:85;             server    192.168.1.106:85;          }        server {          listen       80;          server_name  localhost;            #charset koi8-r;      charset utf-8;            #access_log  logs/host.access.log  main;            location / {                  root    html;                  index   index.html index.htm;                  proxy_pass   http://localhost;                  proxy_set_header   X-Real-IP   $remote_addr;                  client_max_body_size   100m;             }             location ~ ^/(WEB-INF)/ {              deny all;             }            #error_page  404              /404.html;\      error_page    500 502 503 504   /50x.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;          #}      }          # another virtual host using mix of IP-, name-, and port-based configuration      #      #server {      #    listen       8000;      #    listen       somename:8080;      #    server_name  somename  alias  another.alias;        #    location / {      #        root   html;      #        index  index.html index.htm;      #    }      #}          # HTTPS server      #      #server {      #    listen       443 ssl;      #    server_name  localhost;        #    ssl_certificate      cert.pem;      #    ssl_certificate_key  cert.key;        #    ssl_session_cache    shared:SSL:1m;      #    ssl_session_timeout  5m;        #    ssl_ciphers  HIGH:!aNULL:!MD5;      #    ssl_prefer_server_ciphers  on;        #    location / {      #        root   html;      #        index  index.html index.htm;      #    }      #}    }
View Code

 

 

来源:http://www.cnblogs.com/101key/p/3384629.html

推荐: