Nginx|Apache反带用户请求到Tomcat
- LNMT:
client -->http --> nginx --> reverse_proxy --> http --> tomcat (http connector)location ~* \.(jsp|do)$ {proxy_pass http://web1.evescn.com:8080;}
- LAMT:
client --> http --> httpd --> reverse_proxy --> {http|ajp} --> tomcat {http connector|ajp connector}
反代模块: 主:proxy_module 子:proxy_module_http, proxy_module_ajp
proxy_module_http:ServerName web1.evescn.com ProxyVia On ProxyRequests Off # 开启反向代理时,需要关闭正向代理 ProxyPreserveHost On # 直接反带用户请求的虚拟主机名 Require all granted ProxyPass / http://172.16.100.67:8080/ ProxyPassReverse / http://172.16.100.67:8080/Require all granted
proxy_module_ajp:ServerName web1.evescn.com ProxyVia On ProxyRequests Off ProxyPreserveHost On Require all granted ProxyPass /status ! ProxyPass / ajp://172.16.100.67:8009/ ProxyPassReverse / ajp://172.16.100.67:8009/Require all granted
- LNAMT:
client -->http --> nginx --> httpd --> reverse_proxy --> {http|ajp} --> tomcat {http connector|ajp connector}
Tomcat会话保持
session sticky source ip cookiesession cluster: session server kv: memcached, redis
Tomcat集群
- (1) LB tomcat
nginx tomcats (upsteam模块)apache tomcats
- (2) LB tomcat cluster
- (3) LB tomcat
session server memcached
- apache: tomcats
(1) apache: mod_proxy mod_proxy_http mod_proxy_balancer tomcat: http connector(2) apache: mod_proxy mod_proxy_ajp mod_proxy_balancer tomcat: ajp connector(3) apache: mod_jk tomcat: ajp connector
- 第一种方法的实现:
BalancerMember http://172.16.100.68:8080 loadfactor=10 route=TomcatA BalancerMember http://172.16.100.69:8080 loadfactor=10 route=TomcatB ServerName web1.evescn.com ProxyVia On ProxyRequests Off ProxyPreserveHost On Require all granted ProxyPass / balancer://lbcluster1/ ProxyPassReverse / balancer://lbcluster1/Require all granted
如果需要会话绑定:
Header add Set-Cookie "ROUTEID=.%{BALANCER_WORKER_ROUTE}e; path=/" env=BALANCER_ROUTE_CHANGEDBalancerMember http://172.16.100.68:8080 loadfactor=10 route=TomcatA BalancerMember http://172.16.100.69:8080 loadfactor=10 route=TomcatB ProxySet stickysession=ROUTEID ServerName web1.evescn.com ProxyVia On ProxyRequests Off ProxyPreserveHost On Require all granted ProxyPass / balancer://lbcluster1/ ProxyPassReverse / balancer://lbcluster1/Require all granted
- 第二种方法的实现:
#Header add Set-Cookie "ROUTEID=.%{BALANCER_WORKER_ROUTE}e; path=/" env=BALANCER_ROUTE_CHANGEDBalancerMember ajp://172.16.100.68:8009 loadfactor=10 route=TomcatA BalancerMember ajp://172.16.100.69:8009 loadfactor=10 route=TomcatB ProxySet stickysession=ROUTEID ServerName web1.evescn.com ProxyVia On ProxyRequests Off ProxyPreserveHost On Require all granted ProxyPass / balancer://lbcluster1/ ProxyPassReverse / balancer://lbcluster1/Require all granted
- 补充:mod_proxy_balancer模块内置的manager:
SetHandler balancer-manager Proxypass ! Order Deny,Allow Allow from all
- 第三种方式:
mod_jk:额外编译安装
(1) 反向代理 模块配置文件:mod_jk.conf LoadModule jk_module modules/mod_jk.so JkWorkersFile /etc/httpd/conf.d/workers.properties JkLogFile logs/mod_jk.log JkLogLevel debug JkMount /* TomcatA JkMount /status/ stat1 workers配置文件:workers.properties worker.list=TomcatA,stat1 worker.TomcatA.port=8009 worker.TomcatA.host=172.16.100.68 worker.TomcatA.type=ajp13 worker.TomcatA.lbfactor=1 worker.stat1.type = status 注意:status的访问要做访问控制;
(2) 负载均衡 模块配置文件:mod_jk.conf LoadModule jk_module modules/mod_jk.so JkWorkersFile /etc/httpd/conf.d/workers.properties JkLogFile logs/mod_jk.log JkLogLevel debug JkMount /* lbcluster1 JkMount /status/ stat1 workers配置文件:workers.properties worker.list = lbcluster1,stat1 worker.TomcatA.type = ajp13 worker.TomcatA.host = 172.16.100.68 worker.TomcatA.port = 8009 worker.TomcatA.lbfactor = 1 worker.TomcatB.type = ajp13 worker.TomcatB.host = 172.16.100.69 worker.TomcatB.port = 8009 worker.TomcatB.lbfactor = 1 worker.lbcluster1.type = lb worker.lbcluster1.sticky_session = 0 worker.lbcluster1.balance_workers = TomcatA, TomcatB worker.stat1.type = status
- Session Cluster:
session manager:会话管理器 StandardManager PersistentManager: FileStore JDBC DeltaManager BackupManager
构建步骤:(1) 各节点配置使用deltamaanager:(2) 为需要使用session cluster的webapps开启session distribution的功能: WEB-INF/web.xml中添加