Prerequisite Blogs:
Backup manager usually used clustered environment. Its like delta manger. But it will replicate to exactly one other instance(backup instance). Its act like one instance is Primary and another instance as backup.
How To Install Apache Tomcat
Multiple Tomcat Instances on Single Machine
Tomcat Clustering: Loadbalancing with mod_jk and Apache
Tomcat Clustering : Session Affinity
Backup Manager
Steps to make Session Replication in Tomcat Clustering
I am continue from exactly where I left in last session affinity post. So check that post and make sure jumRoute all are set properly. Steps are
I am continue from exactly where I left in last session affinity post. So check that post and make sure jumRoute all are set properly. Steps are
- Enable Multicast routing
- Add <Cluster> Entries in conf/server.xml file for all instances.
- Enable the Web Application as distributable
Step1: Enable Multicast routing
In Linux Environment most of the system kernel is capable to process the multicast address. We need to add route entry in kernel routing table.
sudo route add -net 224.0.0.0 netmask 240.0.0.0 dev eth0
Here eth0 is Ethernet interface. Change according to your interface.
In multicast address is belong to Class D address Range (224.0.0.0 to 239.255.255.255). So, we inform to kernel if any one access these address then it goes through eth0 interface.
Step2: Add <Cluster> Entries in conf/server.xml file for all instances.
This very important part for tomcat clustering. We need to Add <Cluster> tag in conf/server.xml file in all tomcat instances.
<Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"/>
We can add this <Cluster> tag in either inside the<Engine> tag or <Host> tag.
Here SimpleTcpCluster is tomcat cluster implementation. This tag is looks like simple but its has many inner tags. If we omitted then its takes the default values. If we want do any customization (like change multicast address, receiving address port) we need to use complete <Cluster> tag.
This is complete <Cluster> tag:
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"/>
<Sender className="org.apache.catalina.tribes.transport.ReplicationTransmitter">
<Transport className="org.apache.catalina.tribes.transport.nio.PooledParallelSender"/>
</Sender>
<Receiver className="org.apache.catalina.tribes.transport.nio.NioReceiver"
address="auto"
port="4000"
autoBind="100"
selectorTimeout="5000"
maxThreads="6"/>
<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"/>
<ClusterListener className="org.apache.catalina.ha.session.JvmRouteSessionIDBinderListener"/> <ClusterListener className="org.apache.catalina.ha.session.ClusterSessionListener"/>
</Cluster>
</Cluster>
Step3: Enable the Web Application as distributable
Note:
All session object in our web application must me serializable.
Comments
Post a Comment