高性能网站架构之负载均衡 Nginx+tomcat+redis实现tomcat集群
需要注意的问题:
不同机器上的jsessionid的碰撞问题,超时问题?redis的集群问题,出现问题
git:参考
- https://github.com/jcoleman/tomcat-redis-session-manager
- https://github.com/ameizi/DevArticles/issues/123
<Context>
<Valve className="com.orangefunction.tomcat.redissessions.RedisSessionHandlerValve" />
<Manager className="com.orangefunction.tomcat.redissessions.RedisSessionManager"
host="localhost"
port="6379"
database="0"
maxInactiveInterval="60" />
</Context>
Nginx
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 {
#use epoll; #epoll是多路复用IO(I/OMultiplexing)中的一种方式,但是仅用于linux2.6以上内核,可以大大提高nginx的性能
worker_connections 1024; #单个后台work processes 进程最大的并发连接数
}
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;
#要代理的服务器的地址和端口号 weight 为权重,权重越大 被访问的次数越多, 压力越大!
upstream myServer {
server 192.168.20.128:8080;
server 192.168.20.129:8080 weight=2;
}
#gzip on;
#监听80 端口
server {
listen 80;
#定义要使用的域名
server_name localhost;
#charset koi8-r;
#设定本虚拟主机的访问日志
#access_log logs/host.access.log main;
#配置前缀 即要转发到的ip+port
location / {
proxy_pass http://myServer;
# root html;
# index index.html index.htm;
}
#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;
}
}
}