1、./WEB-INF/lib中需要有两个jar
./META-INF
./META-INF/MANIFEST.MF
./META-INF/context.xml
./index.jsp
./WEB-INF
./WEB-INF/web.xml
./WEB-INF/lib
./WEB-INF/lib/terracotta-session-1.3.5.jar
./WEB-INF/lib/terracotta-toolkit-1.6-runtime-5.5.0.jar
./WEB-INF/classes
./WEB-INF/classes/com
2、web.xml配置
<filter>
<filter-name>terracotta-filter</filter-name>
<filter-class>org.terracotta.session.TerracottaJetty61xSessionFilter</filter-class>
<init-param>
<param-name>tcConfigUrl</param-name>
<param-value>192.168.1.191:9510</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>terracotta-filter</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>ERROR</dispatcher>
<dispatcher>INCLUDE</dispatcher>
<dispatcher>FORWARD</dispatcher>
<dispatcher>REQUEST</dispatcher>
</filter-mapping>
</web-app>
3、./META-INF/context.xml 文件内容
<!-- The following is an example of a Tomcat Valve declaration to add to your application to enable
terracotta express session clustering.
In the example below you will likely need to adjust the className attribute to match
your desired application server and the "tcConfigUrl" attribute should be changed to
match the location of your Terracotta server(s).
The order of <Valve> elements is relevant. The Terracotta Valve should always be listed first.
This file should be placed at META-INF/context.xml for WAR deployment on tomcat, or at
WEB-INF/context.xml for Jboss WAR deployment
Tomcat 5.0.x users must add a path attribute to the <Context path="/myApp"> element since it is not
optional in that version
-->
<Context>
<Valve className="org.terracotta.session.TerracottaTomcat60xSessionValve" tcConfigUrl="192.168.1.191:9510"/>
</Context>
<!-- tomcat 5.5.x -->
<!-- <Context> -->
<!-- <Valve className="org.terracotta.session.TerracottaTomcat55xSessionValve" tcConfigUrl="localhost:9510"/> -->
<!-- </Context> -->
<!-- tomcat 5.0.x -->
<!-- <Context path="/myApp"> -->
<!-- <Valve className="org.terracotta.session.TerracottaTomcat50xSessionValve" tcConfigUrl="localhost:9510"/> -->
<!-- </Context> -->
<!-- jboss 5.1.x -->
<!-- <Context> -->
<!-- <Valve className="org.terracotta.session.TerracottaJboss51xSessionValve" tcConfigUrl="localhost:9510"/> -->
<!-- </Context> -->
<!-- jboss 4.2.x -->
<!-- <Context> -->
<!-- <Valve className="org.terracotta.session.TerracottaJboss42xSessionValve" tcConfigUrl="localhost:9510"/> -->
<!-- </Context> -->
<!-- jboss 4.0.x -->
<!-- <Context> -->
<!-- <Valve className="org.terracotta.session.TerracottaJboss40xSessionValve" tcConfigUrl="localhost:9510"/> -->
<!-- </Context> -->
4、最重要的一点是:如果部署于两台机器 192.168.1.101 192.168.1.102 这两个机器作为后置机
前端必须有一个lvs , 用户通过lvs进入访问 ,这时session才能共享。
我用是nginx
本文详细介绍了如何在多个机器上配置Terracotta Session共享,实现集群部署,包括web.xml配置、context.xml文件内容以及前端访问策略。重点强调了使用LVS进行负载均衡的重要性,以确保session在不同机器间的共享。
4170

被折叠的 条评论
为什么被折叠?



