Home > 16ms > in 5 min to Tomcat Cluster…

in 5 min to Tomcat Cluster…

October 9th, 2008 AVC Leave a comment Go to comments

Overview

This section describes how to setup a Tomcat 5.5 cluster with in-memory session replication and configure the cluster to use JK as the load balancing module.
Steps to Setup a Tomcat Cluster and Configure it for Load Balancing

1. Configure Tomcat application servers for load balancing
Edit TOMCAT_HOME/conf/server.xml. Locate the <Engine> element and add a jvmRoute attribute to it:

<Engine name="Catalina" defaultHost="localhost" jvmRoute="NODE_NAME">
... ...
</Engine>

The NODE_NAME must match the name that you will define in the JK configuration (for example “node1″ or “node2″).
2. Edit EP5_DEPLOY_DIR/WEB-INF/web.xml
Set the application as distributable in the web.xml descriptor. e.g.:

<?xml version="1.0"?>
<web-app>
<distributable/>
<!-- ... -->
</web-app>

3. Configure session replication
Add the following lines to TOMCAT_HOME/conf/server.xml and (replacing SERVER_IP_ADDRESS with the IP address of your server).


<Host ......>
...
<Cluster className="org.apache.catalina.cluster.tcp.SimpleTcpCluster"
managerClassName="org.apache.catalina.cluster.session.DeltaManager"
expireSessionsOnShutdown="false"
useDirtyFlag="true"
notifyListenersOnReplication="true">
<Membership
className="org.apache.catalina.cluster.mcast.McastService"
mcastAddr="228.0.0.4"
mcastPort="45564"
mcastFrequency="500"
mcastDropTime="3000" />
<Receiver
className="org.apache.catalina.cluster.tcp.ReplicationListener"
tcpListenAddress="SERVER_IP_ADDRESS"
tcpListenPort="4001"
tcpSelectorTimeout="100"
tcpThreadCount="6" />
<Sender
className="org.apache.catalina.cluster.tcp.ReplicationTransmitter"
replicationMode="pooled"
ackTimeout="15000"
waitForAck="true" />
<Valve className="org.apache.catalina.cluster.tcp.ReplicationValve"
filter=".*\.gif;.*\.js;.*\.jpg;.*\.png;.*\.htm;.*\.html;.*\.css;.*\.txt;" />
<Deployer className="org.apache.catalina.cluster.deploy.FarmWarDeployer"
tempDir="/tmp/war-temp/"
deployDir="/tmp/war-deploy/"
watchDir="/tmp/war-listen/"
watchEnabled="false" />
<ClusterListener className="org.apache.catalina.cluster.session.ClusterSessionListener" />
</Cluster>
...
</Host>

Steps to Setup a Tomcat Cluster and Configure it for Load Balancing with database persisence of sessions

1. Configure Tomcat application servers for load balancing
Edit TOMCAT_HOME/conf/server.xml. Locate the <Engine> element and add a jvmRoute attribute:

<Engine name="Catalina" defaultHost="localhost" jvmRoute="{NODE_NAME}">
... ...
</Engine>

The NODE_NAME must match the name that you will define in the JK configuration (for example “epnode1″ or “epnode2″).
2. Create a table to store sessions
Choose a database server and create a table to store sessions.
For example, with MySQL the table can be created with the following SQL.


create database tomcat;
create table tomcat$sessions
(
id varchar(100) not null primary key,
app varchar(255),
valid char(1) not null,
maxinactive int not null,
lastaccess bigint,
data mediumblob
);

3. Configure Tomcat to store sessions in the session table
Configure the Tomcat context to store sessions into the session table.
For example, the connection to a MySQL table can be configured as follows.

<Context>
....
<Manager className="org.apache.catalina.session.PersistentManager"
debug="0"
saveOnRestart="true"
maxActiveSessions="-1"
minIdleSwap="-1"
maxIdleSwap="-1"
maxIdleBackup="-1">
<Store className="org.apache.catalina.session.JDBCStore"
driverName="com.mysql.jdbc.Driver"
connectionURL="jdbc:mysql://MYSQL_SERVER_IP_ADDRESS:MYSQL_SERVER_PORT/tomcat?
user=USER_NAME&password=PASSWORD"
sessionTable="tomcat$sessions"
sessionIdCol="id"
sessionAppCol="app"
sessionDataCol="data"
sessionValidCol="valid"
sessionMaxInactiveCol="maxinactive"
sessionLastAccessedCol="lastaccess"
checkInterval="60"
debug="99" />
</Manager>
</Context>

gretz avc(arkadiusz v. czarnik)

Categories: 16ms Tags:
  1. No comments yet.
  1. No trackbacks yet.
You must be logged in to post a comment.