Tomcat6.0でセッションレプリケーション
フェイルオーバーを目的とした冗長構成実現のため、セッションレプリケーション設定を行ってみることにした。
備忘録として以下に。
前提
- Tomcat6.0
- SimpleTcpClusterを利用し、メモリでのセッションレプリケーションを行う。
- 設置環境は以前作ったcoLinux:CentOS5.2の2環境([Cent1,IP:192.168.0.11][Cent2,IP:192.168.0.12])
ー 構成は以下
web | [Cent1,IP:192.168.0.11] [Cent2,IP:192.168.0.12] Apache (mod_proxy_balancerでバランシング) |___________________________________ | | Tomcat Tomcat
サーバ側
Tomcat設定
server.xmlに対して、Tomcat5.5までのサンプルを元に以下の設定を行う。
変更前
<!-- ここあたり <Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster" /> -->
変更後
<Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster" channelSendOptions="6"> <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="192.168.0.11" port="5000" selectorTimeout="100" maxThreads="6" /> ←※cent2では192.168.0.12に設定 <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" /> <Interceptor className="org.apache.catalina.tribes.group.interceptors.ThroughputInterceptor" /> </Channel> <Valve className="org.apache.catalina.ha.tcp.ReplicationValve" filter=".*\.gif;.*\.js;.*\.jpg;.*\.png;.*\.htm;.*\.html;.*\.css;.*\.txt;" /> <ClusterListener className="org.apache.catalina.ha.session.ClusterSessionListener" /> </Cluster>
注意点としてReceiverのaddressは"auto"(デフォルト値)だとlocalhostになってしまうため、明示的にサーバのIPアドレスを指定しておく必要があった。
Apache設定
mod_proxy_balancer設定をhttp.confに追記
ProxyPass / balancer://test/ nofailover=On timeout=2 <Proxy balancer://test/> BalancerMember ajp://192.168.0.11:8009 keepalive=On loadfactor=100 retry=5 BalancerMember ajp://192.168.0.12:8009 keepalive=On loadfactor=100 retry=5 </Proxy>