Cluster and session

session consistency

		(1) session sticky
source_ip:
nginx: ip_hash
haproxy: source
lvs: sh
cookie:
nginx:hash
haproxy: cookie
(2) session cluster:
delta(增量)session manager
tomcat delta manager
(3) session server:
redis(store)
memcached(cache)

Tomcat Cluster

		(1) httpd + tomcat cluster
httpd: mod_proxy, mod_proxy_http, mod_proxy_balancer
tomcat cluster:http connector
(2) httpd + tomcat cluster
httpd: mod_proxy, mod_proxy_ajp, mod_proxy_balancer
tomcat cluster:ajp connector
(3) nginx + tomcat cluster
保持会话的方式参考第一种方式。 Tomcat Cluster的第一种方法实现
<proxy balancer://tcsrvs>
BalancerMember http://172.:8080
BalancerMember http://172.:8080
ProxySet lbmethod=byrequests
</Proxy>
<VirtualHost *:80>
ServerName lb.magedu.com
ProxyVia On
ProxyRequests Off
ProxyPreserveHost On
<Proxy *>
Require all granted
</Proxy>
ProxyPass / balancer://tcsrvs/
ProxyPassReverse / balancer://tcsrvs/
<Location />
Require all granted
</Location>
</VirtualHost> Tomact Cluster的第二种实现方法
<proxy balancer://tcsrvs>
BalancerMember ajp://172.:8009
BalancerMember ajp://172.18.:8009
ProxySet lbmethod=byrequests
</Proxy>
<VirtualHost *:80>
ServerName lb.magedu.com
ProxyVia On
ProxyRequests Off
ProxyPreserveHost On
<Proxy *>
Require all granted
</Proxy>
ProxyPass / balancer://tcsrvs/
ProxyPassReverse / balancer://tcsrvs/
<Location />
Require all granted
</Location>
<Location /balancer-manager>
SetHandler balancer-manager
ProxyPass !
Require all granted
</Location>
</VirtualHost>

BalancerMember

	BalancerMember [balancerurl] url [key=value [key=value ...]]
status:
D: Worker已停且不接受任何请求。
S: Worker已经有管理地停止。
I: Worker采用忽略错误的模式,并被认为总是可用。
H: Worker 采用双机热备模式并讲仅在没有其他可用worker时使用。
E: Worker 处于错误状态.
N: Worker 采用drain mode 并仅接收到达自身的粘性会话, 以及忽略其他所有清空。
loadfactor:
负载因子,即权重;
perform pending request balancing.lbmethod:Balancer load-balance method
选择负载平衡的调度算法。
byrequests
进行权重请求的计算
bytraffic
进行加权流量字节数平衡
bybuyness
进行挂起的请求平衡
默认是byrequests
stickysession:Balancer sticky session name.
这个值常被设置为JSESSIONID 或者 PHPSESSIONID之类的值,且它依赖于后端应用服务支持的会话。
如果后端应用服务为cookies使用不同的名,以及url 编码id(如小程序容器)使用“|”来区分它们。
第一部分用于cookie,第二部分用于路径,可用在iApache HTTP Server 2.4.4 和最新版本。 会话粘性的实现方法:
Header add Set-Cookie "ROUTEID=.%{BALANCER_WORKER_ROUTE}e; path=/" env=BALANCER_ROUTE_CHANGED
<proxy balancer://tcsrvs>
BalancerMember http://172.:8080 route=TomcatA loadfactor=1
BalancerMember http://172.:8080 route=TomcatB loadfactor=2
ProxySet lbmethod=byrequests
ProxySet stickysession=ROUTEID
</Proxy>
<VirtualHost *:80>
ServerName lb.magedu.com
ProxyVia On
ProxyRequests Off
ProxyPreserveHost On
<Proxy *>
Require all granted
</Proxy>
ProxyPass / balancer://tcsrvs/
ProxyPassReverse / balancer://tcsrvs/
<Location />
Require all granted
</Location>
</VirtualHost>
启用管理接口:
<Location /balancer-manager>
SetHandler balancer-manager
ProxyPass !
Require all granted
</Location> 示例程序:
演示效果,在TomcatA上某context中(如/test),提供如下页面
<%@ page language="java" %>
<html>
<head><title>TomcatA</title></head>
<body>
<h1><font color="red">TomcatA.magedu.com</font></h1>
<table align="centre" border="1">
<tr>
<td>Session ID</td>
<% session.setAttribute("magedu.com","magedu.com"); %>
<td><%= session.getId() %></td>
</tr>
<tr>
<td>Created on</td>
<td><%= session.getCreationTime() %></td>
</tr>
</table>
</body>
</html> 演示效果,在TomcatB上某context中(如/test),提供如下页面
<%@ page language="java" %>
<html>
<head><title>TomcatB</title></head>
<body>
<h1><font color="blue">TomcatB.magedu.com</font></h1>
<table align="centre" border="1">
<tr>
<td>Session ID</td>
<% session.setAttribute("magedu.com","magedu.com"); %>
<td><%= session.getId() %></td>
</tr>
<tr>
<td>Created on</td>
<td><%= session.getCreationTime() %></td>
</tr>
</table>
</body>
</html>

Tomcat Session Replication Cluster

	(1) 配置启用集群,将下列配置放置于<engine>或<host>中;
<Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"
channelSendOptions="8">
<Manager className="org.apache.catalina.ha.session.DeltaManager"
expireSessionsOnShutdown="false"
notifyListenersOnReplication="true"/>
<Channel className="org.apache.catalina.tribes.group.GroupChannel">
<Membership className="org.apache.catalina.tribes.membership.McastService"
address="228.0.0.4"
port="45564"
frequency="500"
dropTime="3000"/>
<Receiver className="org.apache.catalina.tribes.transport.nio.NioReceiver"
address="auto"
port="4000"
autoBind="100"
selectorTimeout="5000"
maxThreads="6"/>
<Sender className="org.apache.catalina.tribes.transport.ReplicationTransmitter">
<Transport className="org.apache.catalina.tribes.transport.nio.PooledParallelSender"/>
</Sender>
<Interceptor className="org.apache.catalina.tribes.group.interceptors.TcpFailureDetector"/>
<Interceptor className="org.apache.catalina.tribes.group.interceptors.MessageDispatch15Interceptor"/>
</Channel>
<Valve className="org.apache.catalina.ha.tcp.ReplicationValve"
filter=""/>
<Valve className="org.apache.catalina.ha.session.JvmRouteBinderValve"/>
<Deployer className="org.apache.catalina.ha.deploy.FarmWarDeployer"
tempDir="/tmp/war-temp/"
deployDir="/tmp/war-deploy/"
watchDir="/tmp/war-listen/"
watchEnabled="false"/>
<ClusterListener className="org.apache.catalina.ha.session.JvmRouteSessionIDBinderListener"/>
<ClusterListener className="org.apache.catalina.ha.session.ClusterSessionListener"/>
</Cluster>
确保Engine的jvmRoute属性配置正确。 (2) 配置webapps
编辑WEB-INF/web.xml,添加<distributable/>元素;
注意:CentOS 7上的tomcat自带的文档中的配置示例有语法错误;
<ClusterListener className="org.apache.catalina.ha.session.JvmRouteSessionIDBinderListener"/>
<ClusterListener className="org.apache.catalina.ha.session.ClusterSessionListener"/>
绑定的地址为auto时,会自动解析本地主机名,并解析得出的IP地址作为使用的地址。

Tomcat Session Server (memcached)

	https://github.com/magro/memcached-session-manager
支持的session server类型:
memcached:
couchbase:
redis:
示例方案:
Tomcat7:
memcached
javolution

最新文章

  1. 自动判断应该Ajax还是return
  2. 敏捷BI比传统BI功能强大是否属实?
  3. 如何在Delphi里面查看程序的汇编代码?
  4. 关于新闻,在线编辑器建表时此字段一定要为text
  5. 【python游戏编程之旅】第三篇---pygame事件与设备轮询
  6. A Round Peg in a Ground Hole - POJ 1584 (判断凸多边形&amp;判断点在多边形内&amp;判断圆在多边形内)
  7. 解决django关于图片无法显示的问题
  8. NSPredicate的用法
  9. 测试驱动 ASP.NET MVC Type Aliase
  10. map.entry&lt;k,v&gt;小用法(转)
  11. Webpack的加载器
  12. Linux服务器集群系统(LVS)
  13. Django通用视图APIView和视图集ViewSet的介绍和使用
  14. 腾讯云服务器突然远程连不上(包含ssh,拒绝访问)
  15. 数据机构-折半查找法(二分查找法)-Python实现
  16. Google Guava--Guava新增集合
  17. git之合并分支(git merge)------(三)
  18. 1013 Battle Over Cities (25)(25 point(s))
  19. par函数col参数-控制颜色
  20. erlang通讯解析浮点数的一些问题

热门文章

  1. windows环境下SVN服务器限制注释字数
  2. Asp.Net Thread is being Aborted
  3. [NOIP1998] 提高组 洛谷P1011 车站
  4. hdu5608:function
  5. eclispe使用
  6. Rem 字体设置学习一
  7. [bzoj2595][WC2008]游览计划/[bzoj5180][Baltic2016]Cities_斯坦纳树
  8. CPU 天梯图
  9. curl 发送post请求
  10. hibernate查询之Criteria实现分页方法(GROOVY语法)