Session Clustering with Terracotta
- Before you start, make sure you have installed terracotta 2.4. We'll refer to the installation directory as
- If you haven't already got a boot jar for terracotta for your jvm version, then make one now. On linux this is
- Check out jetty from svn, or download an unzip a src bundle. We'll refer to the installation directory as
- Build it if it isn't already (
- Go to the
$JETTY_HOME/contrib/terracottadirectory and build it with
You'll need to have the terracotta tc.jar file installed in your local maven repository. If it isn't already, then maven will give you the exact instructions on what you need to do to put it there. It will look something like this:
- Copy the target/terracotta-sessions.jar you just built into
Configuring Jetty to use Terracotta consists of creating a single TerracottaSessionIdManager per jetty instance to generate unqiue session ids, and setting up a special TerracottaSessionManager per webapp to be distributed.
$JETTY-HOME/contrib/terracotta/src/main/resources/jetty.xml is an example file that you can use which sets up the TerracottaSessionIdManager. It is the standard jetty.xml, with these additional lines:
workerName is a unqiue name for the jetty instance. In the example it is "fred" but you can use any naming scheme you'd like.
Now, we need to configure which webapps we want to be distributed. The easiest way to do that is to use the ContextDeployer, and create a context file to deploy each webapp. There are some examples for the sample webapps distributed with terracotta in
In each case, the important lines which establish the webapp with terracotta are:
- Start a terracotta server with a jetty configuration file. On linux this is
$TC_HOME/bin/start-tc-server.sh -f $JETTY-HOME/jetty-6/contrib/terracotta/src/main/resources/tc-config-jetty.xml
- Set up the webapps that you want to use terracotta by following the instructions in the Configuration section above.
- Start jetty: