Both Tomcats store/retrieve sessions on the active Terracotta server.
Apache web server forwards requests to both Tomcats.
If the active Terracotta fails the passive Terracotta will be the active.
Let's Digg in
First things first! we need:
terracotta-3.7.0-installer.jar
apache-tomcat-6.0.35
mod_jk.so
httpd-2.2.22
JDK 1.6
My five servers built on a single windows 7 box as a POC, you should have no troubles with running the same example on Linux, only minor chages are needed.
Install and Configure Terracotta
open a terminal and change the directory to the place where you downloaded terracotta-3.7.0-installer.jar
java -jar terracotta-3.7.0-installer.jar
you will see a setup wizard, it is straight forward, install Terracotta to the directory of your choice, from now on i will refer to that directory as ${TC_HOME}
now, go to ${TC_HOME} and create a new directory called 'config', this directory will contain our Terracotta configuration file that will set up the Terracotta cluster.
create a new file inside the config directory called tc-config.xml with the following content:
for each Terracotta server that will run in the cluster you need to define a server node.
the server tag has three attributes:
bind: the default bind address which Terracotta listen to.
host: the IP address that will be used to connect to the Terracotta server.
name: the name of this node
data: is where this server stores its data (make it unique for each server if you are running the cluster on one box)
logs: is where the server store its logs (make it unique for each server if you are running the cluster on one box)
statistics: is where the server store its statistics (make it unique for each server if you are running the cluster on one box)
port configurations: JMX, DSO and group ports (make it unique for each server if you are running the cluster on one box)
data-backup: is where the server store its data backups (make it unique for each server if you are running the cluster on one box)
index: is where the server store its index files (make it unique for each server if you are running the cluster on one box)
dso: is the Distributed Shared Objects specific options. we have now defined two servers, we need to define how they would work.
mirror-group: a tag to define Terracotta groups
members: a tag to add a server to a group using its name
ha: is a tag to define the High Availability options of the group
mode: networked-active-passive it means that the communications between the servers will relay on networking.
election-time: the Terracotta server would wait for that time to decide if it should start as an Active or passive.
let's start out cluster an make sure everything is OK.
open three consoles and navigate to ${TC_HOME}\bin on the three of them
you should see
Becoming State[ ACTIVE-COORDINATOR ]
Terracotta Server instance has started up as ACTIVE node on 0.0.0.0:9510 successfully, and is now ready for work.
as per the screen shot, node1 is active and node2 is passive, play around by taking node1 down and see if node2 becomes the active and then Vice Versa.