博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Tomcat反带和集群
阅读量:5231 次
发布时间:2019-06-14

本文共 5294 字,大约阅读时间需要 17 分钟。

 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_CHANGED
BalancerMember 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_CHANGED
BalancerMember 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中添加

  

 

转载于:https://www.cnblogs.com/python-gm/p/8892428.html

你可能感兴趣的文章
$.ajax
查看>>
ListenableFuture
查看>>
DBA 管理常用内容
查看>>
Node.js之网游服务器实践
查看>>
移动开发必须要了解的易盾加固生态
查看>>
java提高篇(四)_理解java的三大特性之多态 转自 http://cmsblogs.com
查看>>
6-06数据的导入与导出
查看>>
【leetcode】566. Reshape the Matrix
查看>>
【leetcode】【141】Linked List Cycle
查看>>
RESTful API 如何设计
查看>>
Android 完美实现图片圆角和圆形(对实现进行分析)
查看>>
jQuery
查看>>
intellij idea 汉化
查看>>
DWM.EXE进程(Desktop Window Manager)不能删除
查看>>
用opencv做的静态图片人脸识别
查看>>
事后分析报告(M1阶段)
查看>>
第三章 熟悉常用的HDFS操作
查看>>
日语五十音图快速记忆法——看了这个,真的很好记
查看>>
Java8的GC垃圾回收
查看>>
ASP.NET - 匹配标签中的内容
查看>>