Terracotta and Tomcat Clustering - Page 2

原网址:http://javadrama.blogspot.com/2012/10/terracotta-and-tomcat-clustering-page-2.html

Now, download apache-tomcat-6.0.35 and extract it twice to two directories of your choice, i will refer to them as ${CATALINA_HOME_NODE1} and ${CATALINA_HOME_NODE2}.

Copy Terracotta Libraries
we need two jar files to be copied to  both Tomcats  lib directory.
${TC_HOME}\common\terracotta-toolkit-1.6-runtime-5.0.0.jar
${TC_HOME}\sessions\terracotta-session-1.3.0.jar
 
Copy Terracotta Config File
we need to copy the same Terracotta configuration file to the  conf directory of  bothTomcats
${TC_HOME}\config\tc-config.xml

one small change to do, the client log location, both clients (Tomcat servers) can't be configured with the same client log location.

edit ${CATALINA_HOME_NODE2}\conf\tc-config.xml
change log location under the clients tag 
<logs>%(user.home)/terracotta/client-logs</logs>
to be 
<logs>%(user.home)/terracotta/client-logs2</logs>
Terracotta Valve
Tomcat connects to Terracotta by intercepting requests via a value, now let's hook that valve.
under the  conf directory of both Tomcats, edit the file context.xml to look like this: 
<Context>

 <!-- Default set of monitored resources -->
 <WatchedResource>WEB-INF/web.xml</WatchedResource>

 <!-- Uncomment this to disable session persistence across Tomcat restarts -->
    <Manager pathname="" />
 
 <!-- Hook the Terracotta Valve and configure it using the tc-config.xml file -->
 <Valve className="org.terracotta.session.TerracottaTomcat60xSessionValve" tcConfigUrl="../conf/tc-config.xml"/>

</Context>

note that we have disabled session persistence across Tomcat restarts because that is a task for Terracotta now.

Tomcat HA Configurations

 
 
jvmRoute
 
we need to define a unique jvmRoute for each Tomcat server.

edit ${CATALINA_HOME_NODE1}\conf\server.xml, change the  Engine tag to look like this: 
<Engine name="Catalina" defaultHost="localhost" jvmRoute="tomcat1">
 
edit ${CATALINA_HOME_NODE2}\conf\server.xml, change the  Engine tag to look like this: 
<Engine name="Catalina" defaultHost="localhost" jvmRoute="tomcat2">

Make sure you don't have port conflicts
as i am running both Tomcats on the same box, i had to change the ports for the second Tomcat.
in ${CATALINA_HOME_NODE2}\conf\server.xml, i have changed
shutdown port: 8005 to 8006
http port: 8080 to 8081
ajp port: 8009 to 8010

Run both Tomcats
open two more terminals and navigate to ${CATALINA_HOME_NODE1}\bin on one and ${CATALINA_HOME_NODE2}\bin on the other, on both terminals execute: 
startup.bat

if everything went as it should, you should see something like that on both Tomcat terminals 
Terracotta 3.7.0, as of 20120717-133013 (Revision unknown-20453 by cruise@rh5vmo113.terracotta.lan from 3.7.0)
Successfully loaded base configuration from file at 'H:\terracotta\apache-tomcat-6.0.35\bin\.\..\conf\tc-config.xml'.
Successfully loaded base configuration from file at 'H:\terracotta\apache-tomcat-6.0.35\temp\tc-config8509448930662041153.xml'.
Log file: 'C:\terracotta\client-logs\terracotta-client.log'.
Connection successfully established to server at 127.0.0.1:9510

Test it
Tomcat comes by default with a web application called  examples , we will use it till the end of this tutorial to test our setup

point your browser to http://localhost:8080/examples/ and http://localhost:8081/examples/ and make sure both servers are responding.

open your Terracotta Development Console and make sure that both clients (the tomcat server) are present as below.

 
also note that the sessions button is now active.

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值