Terracottaを利用してTomcatのセッションとかもろもろ共有

基本的に http://www.terracotta.org/web/display/orgsite/Tomcat+Integration の通りにやればいいけど、少しだけ違うところがあったので記録しておく。

構成

試した構成はこんな感じ。

        ┌──────┐
        │ tc-worker2 │    mod_proxy_balancerで重み1同士の単純な振り分け。セッション共有の確認のために使ってる
        └──────┘
         ┌──┴──┐
┌──────┐┌──────┐
│ tc-worker1 ││ tc-worker3 │TomcatTerracotta(client)が動いてる
└──────┘└──────┘
         └──┬──┘
        ┌──────┐
        │ tc-master1 │    Terracotta(server)でセッション共有
        └──────┘

ポイントの整理

  • Terracottaは全てのAPサーバーで必要
  • APサーバー側のTerracottaにはTIMが必要
    • TIMはTerracottaとサーバーアプリとの協調動作のためのバインドみたいなもの
  • TCサーバー側はデフォルト設定でも動くみたい
    • ので、APサーバーのTCクライアントのほうが繋ぎに行く感じか
  • APサーバーのTCクライアント用にtc-config.xmlを用意
  • Tomcatのstartup.shでTCのdso-env.shを呼ぶようにする

TIMの取得

/opt/terracotta-3.0.0/bin/tim-get.sh  install tim-tomcat-6.0

で、

/opt/terracotta-3.0.0/modules/org/terracotta/modules

が追加される。

ドキュメントの通りだとうまく行かなかったところ

dso-env.shを呼ぶようにしたstartup.shを実行したところ、こんなエラーが。

[root@tc-worker1 ~]# /opt/apache-tomcat-6.0.18/bin/startup_tc.sh
Starting BootJarTool...
2009-05-28 16:50:52,013 INFO - Terracotta 3.0.0, as of 20090409-180411 (Revision 12431 by cruise@su10mo5 from 3.0)
2009-05-28 16:50:52,500 FATAL - BootJarTool: 
 *******************************************************************************
The configuration data in the file at '/opt/terracotta-3.0.0/tc-config.xml' does not obey the Terracotta schema:
  [0]: Line 10, column 8: Expected element 'server' instead of 'update-check' here in element servers

 *******************************************************************************

2009-05-28 16:50:52,501 FATAL - Exception thrown
com.tc.config.schema.setup.ConfigurationSetupException: 
 *******************************************************************************
The configuration data in the file at '/opt/terracotta-3.0.0/tc-config.xml' does not obey the Terracotta schema:
  [0]: Line 10, column 8: Expected element 'server' instead of 'update-check' here in element servers

 *******************************************************************************

        at com.tc.config.schema.setup.StandardXMLFileConfigurationCreator.loadConfigurationData(StandardXMLFileConfigurationCreator.java:323)
        at com.tc.config.schema.setup.StandardXMLFileConfigurationCreator.createConfigurationIntoRepositories(StandardXMLFileConfigurationCreator.java:207)
        at com.tc.config.schema.setup.BaseTVSConfigurationSetupManager.runConfigurationCreator(BaseTVSConfigurationSetupManager.java:104)
        at com.tc.config.schema.setup.StandardL1TVSConfigurationSetupManager.(StandardL1TVSConfigurationSetupManager.java:53)
        at com.tc.config.schema.setup.StandardTVSConfigurationSetupManagerFactory.createL1TVSConfigurationSetupManager(StandardTVSConfigurationSetupManagerFactory.java:161)
        at com.tc.object.tools.BootJarTool.main(BootJarTool.java:2633)

update_checkエレメントの代わりにserverエレメントがないといけない?
とりあえず、update_checkエレメントをなくしたらちゃんと起動した。

<tc:tc-config xmlns:tc="http://www.terracotta.org/config"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://www.terracotta.org/schema/terracotta-4.xsd">

  <servers>

  <!-- The <update-check> element helps ensure that you're using the latest version of Terracotta DSO.
    Out-of-date versions trigger a message to log and standard output. -->

<!--
       <update-check>
         <enabled>true</enabled>
       </update-check>
-->

       <server host="tc-master1">
         <dso-port>9510</dso-port>
       </server>
  </servers>
 
 <!-- <modules> is a section in <clients> that specifies the TIMs to be used by your Terracotta installation.
      In this example, the TIM for an application server called "my-app-sever", version 1.0.1, is included.
      The version of the TIM, 1.2.3, is also specified. This configuration assumes that the default repository,
      the modules directory in the Terracotta installation directory, is being used to store the TIM files. 
      For more on TIM repositories, see the Terracotta Configuration Guide and Reference. -->
       
  <clients>
     <modules>
        <module name="tim-tomcat-6.0" version="1.0.1" />
     </modules>
  </clients>

  <application>
    <dso>
       <instrumented-classes>
         <include>
<!-- Tomcatのexampleのcartでセッション共有を試してたので -->
           <class-expression>sessions.DummyCart</class-expression>
         </include>
       </instrumented-classes>

<!-- ここの意味はまだよくわからん -->
      <web-applications>
        <web-application>examples</web-application>
      </web-applications>
    </dso>
   </application>
</tc:tc-config>