这段时间一直在搞项目部署,以前从来没做过,感觉很吃力,下面这个是自己配的Ubuntu下Nginx+Tomcat+Memecached实现session共享配置参考文档,欢迎大家拍砖,不知为啥session冒失还是不能实现共享,求告诉指教
这里的memcachedNodes是填写memcached节点,多个节点时可以以空隔分开,如:
n1:localhost:11211 n2:localhost:11212
sessionBackupTimeout的单位为分钟
E:/java_codes/TestSession/WebContent 替换成你的WEB目录
修改后重启两个TOMCAT即可,这个时候已经解决SESSION的共享问题.
二,配置nginx实现负载均衡
我的nginx.conf
Xml代码
user nginx nginx;
worker_processes 8;
worker_cpu_affinity 00000001 00000010 00000100 00001000 00010000 00100000 01000000 10000000;
error_log /log/nginx/error.log crit;
pid /var/run/nginx.pid;
worker_rlimit_nofile 65535;
events {
use epoll;
worker_connections 65535;
}
http {
include mime.types;
default_type application/octet-stream;
log_format access '$remote_addr - $remote_user [$time_local] "$request"' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"';
access_log /log/nginx/access.log access;
sendfile on;
tcp_nopush on;
keepalive_timeout 30;
tcp_nodelay on;
gzip off;
server_tokens off;
upstream 10.0.2.15 {
server 10.0.2.15:8080 ;
server 10.0.2.15:8081 ;
}
server {
server_name 10.0.2.15;
proxy_headers_hash_max_size 51200;
proxy_headers_hash_bucket_size 6400;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
location / {
proxy_pass http://10.0.2.15;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header REMOTE-HOST $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
access_log /log/nginx/10.0.2.15_access.log access;
}
}