terracotta loadbalancing and clustering

16

Click here to load reader

Upload: pawan

Post on 15-Nov-2014

111 views

Category:

Documents


4 download

DESCRIPTION

Terracotta is open source infrastructure software that makes it inexpensive and easy to scale a Java application to as many computers as needed, without the usual custom application code and databases used to share data in a cluster. Terracotta manages mission critical data using Network-Attached Memory (NAM) technology. NAM enables Terracotta to cluster Java Virtual Machines (JVMs) directly underneath applications, and is a proven runtime approach to providing Java applications both high availability and scalability.This document guide you the steps to cluster web application. Step wise description to achieve clustering. This is a fastest & easiest way to achieve load balancing & clustering.

TRANSCRIPT

Page 1: Terracotta LoadBalancing and Clustering

Load Balancing & Clustering

Terracotta Server

Page 1

TERACOTTA

Load Balancing & Clustering

Author: Pawan Modi

Page 2: Terracotta LoadBalancing and Clustering

Load Balancing & Clustering

Terracotta Server

Page 2

TABLE OF CONTENTS

INTRODUCTION _________________________________________________________ 3

INSTALL TERRACOTTA SERVER _______________________________________________ 4

INSTALL GERONIMO SERVER ________________________________________________ 5

INSTALL TERRACOTTA CLIENT ________________________________________________ 6

UPDATE TERRACOTTA CONFIGURATION FILE ______________________________________ 7

Excerpt from tc-config.xml ______________________________________________ 7

START TERRACOTTA SERVER ________________________________________________ 8

START TERRACOTTA CLIENT AND GERONIMO SERVER ________________________________ 9

Starting Geronimo ____________________________________________________ 9

INSTALL WEB APPLICATION ON EACH GERONIMO CLUSTER MEMBER _____________________ 10

SETUP LOAD BALANCING AND FAILOVER _______________________________________ 11

Apache HTTP Server: _________________________________________________ 11

MOD_JK SETUP: _______________________________________________________ 13

TESTING DEMO LOAD BALANCING: ___________________________________________ 15

USEFUL LINKS: ________________________________________________________ 16

Page 3: Terracotta LoadBalancing and Clustering

Load Balancing & Clustering

Terracotta Server

Page 3

Introduction

Terracotta is open source infrastructure software that makes it inexpensive and easy to scale

a Java application to as many computers as needed, without the usual custom application

code and databases used to share data in a cluster.

Terracotta manages mission critical data using Network-Attached Memory (NAM)

technology. NAM enables Terracotta to cluster Java Virtual Machines (JVMs) directly

underneath applications, and is a proven runtime approach to providing Java applications

both high availability and scalability.

Terracotta's open source community of developers is sponsored by Terracotta, Inc.

This article describes the steps to cluster a simple web application's HttpSession data using

Open Terracotta. The required step includes.

• Install Terracotta Server

• Install Geronimo Server

• Install Terracotta Client

• Update Terracotta configuration file

• Start Terracotta Server

• Start Terracotta Client and Geronimo Server

• Install Web Application on each Geronimo cluster member

• Setup Load Balancing and Failover

• Testing Load Balancing and Failover

• Use the Terracotta admin console

Page 4: Terracotta LoadBalancing and Clustering

Load Balancing & Clustering

Terracotta Server

Page 4

Install Terracotta Server

Terracotta needs to be installed on one machine that will serve as the Terracotta Server.

The Terracotta server will be responsible for maintaining session state and assuring that it is

accurately reflected in each of the Geronimo cluster members.

Download the Terracotta Sessions bundle

and run the Installer. This example requires

"Open Terracotta 2.2.1 Stable 2" or higher.

Page 5: Terracotta LoadBalancing and Clustering

Load Balancing & Clustering

Terracotta Server

Page 5

Install Geronimo Server

The Geronimo Application Server needs to be installed on each machine that is to be

clustered. The example in this article will install Geronimo on two separate machines (cluster

members).

Download the Geronimo image that includes the Tomcat web container from the Geronimo

Website

Note: -

and unpack it on each of the cluster members. This example requires Geronimo

1.1.1 with the Tomcat web container. The Jetty web container is not yet supported by

Terracotta.

Download only J2EE certified release. Don’t download minimal / little-G releases.

Minimal / little-G release doesn’t support administration console. User need Admin

console for variety of purposes like new applications deployment etc.

Note that the same version release of Geronimo must be installed on each machine

to be clustered. Mixing versions of Geronimo is not currently supported by

Terracotta.

Page 6: Terracotta LoadBalancing and Clustering

Load Balancing & Clustering

Terracotta Server

Page 6

Install Terracotta Client

The Terracotta client needs to be installed on each machine that contains a Geronimo

cluster member. Currently, the same install bundle includes both the Terracotta server and

client. So, it is possible to run the Terracotta Server and Terracotta Client on the same

machine with a common installation.

Download the Terracotta Sessions bundle

and run the Installer on each cluster member.

This example requires "Open Terracotta 2.2.1 Stable 2" or higher.

Page 7: Terracotta LoadBalancing and Clustering

Load Balancing & Clustering

Terracotta Server

Page 7

Update Terracotta configuration file

The tc-config.xml file identifies which context-roots are to be clustered as well as the data

types that are to be placed in the HttpSession.

This example will use the Terracotta configuration file that is delivered with the Terracotta

distribution. The specific file is:

C:\Terracotta\terracotta-2.2.1\sessions\sandbox\tomcat5.5\tc-config.xml

Change the tc-config.xml file to look similar to the following example. Note that the tc-

config.xml example below only shows the xml items that are to be updated. Other portions

of that xml file should remain unchanged. Remember to change the IP address in the

example below to the address of the Terracotta Server.

Excerpt from tc-config.xml

Page 8: Terracotta LoadBalancing and Clustering

Load Balancing & Clustering

Terracotta Server

Page 8

Start Terracotta Server

Start the Terracotta server specifying the location of the tc-config.xml file that you just

updated.

cd C:\Terracotta\terracotta-2.2.1\sessions\bin

start-tc-server.bat -f c:\Terracotta\terracotta-2.2.1\sessions\sandbox\tomcat5.5\tc-

config.xml

Page 9: Terracotta LoadBalancing and Clustering

Load Balancing & Clustering

Terracotta Server

Page 9

Start Terracotta Client and Geronimo Server

Open Terracotta supports a variety of JVMs and each one requires a unique boot jar be

present in the bootclasspath when launching the Geronimo server. The example below is

using the Windows JVM that is present in the Terracotta Sessions Package. It is possible to

use other JVMs, though a different boot jar will likely need to be created. Also some of the

launch arguments in the script below were obtained by issuing the dso-env script in

c:\Terracotta\terracotta-2.2.1\sessions\bin\ directory. You should issue this command on

your system to find the arguments that are appropriate for your environment.

The IPAddress in the example below needs to be replaced with the IP Address (or hostname)

of your Terracotta server. This value will be used to determine which Terracotta server will

provide the Terracotta client with its tc-config.xml file. Alternately, -

Dtc.config="IPAddress:9510" can be omitted though you will need to update tc-config.xml

on each cluster member (e.g. c:\Terracotta\terracotta-

2.2.1\sessions\sandbox\tomcat5.5\tc-config.xml). Review the Terracotta documentation

Here is an example startup on a Windows Machine:

for

more details.

Starting Geronimo

c:\Terracotta\terracotta-2.2.1\jre\bin\java.exe

-Xbootclasspath/p:

-Dtc.install-root=

"C:\Terracotta\terracotta-2.2.1\common\lib\dso-boot\dso-boot-

hotspot_win32_150_09.jar"

-Dtc.config=

"C:\Terracotta\terracotta-2.2.1"

-jar c:\geronimo-1.1.1-TERRACOTTA\geronimo-1.1.1\bin\server.jar

"IPAddress:9510"

Page 10: Terracotta LoadBalancing and Clustering

Load Balancing & Clustering

Terracotta Server

Page 10

Install Web Application on each Geronimo cluster member

Use the Geronimo admin console to install the appropriate example application to each of

the Geronimo installations.

Here are links to the example applications and the deployment plan.

servlets-examples-cluster-node1.war - Web application for Cluster Member 1

servlets-examples-cluster-node2.war - Web application for Cluster Member 2

servlets-examples-geronimo-plan.xml - Geronimo common deployment plan (for

both cluster members)

Note that the two applications above are identical except for the field which indicates the

Server name (e.g. Server1, Server2). This distinction will be useful when testing.

The Geronimo admin console can be accessed at http://localhost:8080/console on

each machine.

The default id and password for the Geronimo admin console is id=system

password=manager.

Select "Applications-> Deploy New" from the GUI and follow the instructions on the

panel for installing the example application

Now test that the applications were deployed correctly by accessing the applications with

your favourite Web Browser:

http://YourHost1:8080/servlets-examples-terracotta/servlet/SessionExample

http://YourHost2:8080/servlets-examples-terracotta/servlet/SessionExample

If this is working correctly, it is now time to setup the Load Balancer.

Page 11: Terracotta LoadBalancing and Clustering

Load Balancing & Clustering

Terracotta Server

Page 11

Setup Load Balancing and Failover

Now you are ready to setup the Load Balancer. We recommend using Apache HTTP server

and mod_jk for this example.

Apache HTTP Server:

Install Apache HTTP server - instructions and downloads available at

http://httpd.apache.org/

Set environment variable Apache_Home i.e. home directory of Apache http server

installation.

Run the Apache .msi file you downloaded above. This will prompt you for:

Whether or not you want to run Apache for all users (installing Apache as a

Service), or if you want it installed to run in a console window when you choose

the Start Apache shortcut. It is recommended to install Apache HTTP server as

service. HTTP server start automatically with system boot. User can start / stop /

restart Apache HTTP server from \control panel\Administrative

tool\services\Apache.

Your Server name, Domain name and administrative email account.

The directory to install Apache into. (the default is C:\Program Files\Apache

Group\Apache although you can change this to any other directory you wish)

The installation type. The "Complete" option installs everything, including the

source code if you downloaded the -src.msi

package. Choose the "Custom"

install if you choose not to install the documentation, or the source code from

that package.

Test Apache HTTP server is running or not using following link

http://127.0.0.1

\control panel\Administrative tool\services\Apache & retest above link.

If Apache HTTP server page is not opening the restart HTTP server from

Useful dos commands to control HTTP server

To test the Apache configuration files

Page 12: Terracotta LoadBalancing and Clustering

Load Balancing & Clustering

Terracotta Server

Page 12

apache –t

Start Apache using particular configuration file:

apache -f "c:\my server\conf\my.conf"

apache -f test\test.conf

Note: This conf file is httpd.conf

Command to start & stop Apache as service

NET START APACHE

NET STOP APACHE

To restart Apache from console.

apache -k restart

To stop Apache.

apache -k shutdown

Page 13: Terracotta LoadBalancing and Clustering

Load Balancing & Clustering

Terracotta Server

Page 13

Mod_JK Setup:

Download mod_jk binary release from this link

http://tomcat.apache.org/download-connectors.cgi

After downloading it is time to configure mod_jk. Steps are as follow

Set environment variable CATALINA_HOME i.e. home directory of Geronimo /

tomcat server.

Rename file mod_jk-apache-2.x.xx.so to mod_jk.so, and place under directory

<Apache_Home>\modules

Set environment variable

Create a file with name “workers.properties”. Copy & paste the following contents in

file “worker.properties”.

workers.Geranimo_home=C:\Pawan\IPNC\Tools\Terracotta\geronimo1.1.1\geronimo-1.1.1

workers.java_home=C:\JavaSDK\jdk

ps=\

worker.list=loadbalancer,status

worker.node1.port=8009

worker.node1.host=_your.first.cluster.member.host.name_or_IP_address

worker.node1.type=ajp13

worker.node1.lbfactor=1

worker.node2.port=8009

worker.node2.host=_your.second.cluster.member.host.name_or_IP_address

worker.node2.type=ajp13

worker.node2.lbfactor=1

worker.loadbalancer.type=lb

worker.loadbalancer.balance_workers=node1,node2

worker.loadbalancer.sticky_session=1

worker.status.type=status

Page 14: Terracotta LoadBalancing and Clustering

Load Balancing & Clustering

Terracotta Server

Page 14

Save “workers.properties” file at Apache_Home\conf directory.

Edit file Apache_Home\conf\httpd.conf

LoadModule jk_module modules/mod_jk.so

AddModule mod_jk.c

<IfModule mod_jk.c>

JkWorkersFile "C:/Program Files/Apache Group/Apache/conf/workers.properties"

JkLogFile logs/mod_jk.log

JkLogLevel error

JkLogStampFormat "[%a %b %d %H:%M:%S %Y] "

JkOptions +ForwardKeySize +ForwardURICompat -ForwardDirectories

JkRequestLogFormat "%w %V %T"

Alias /servlets-examples-terracotta "CATALINA_HOME\repository\geronimo\servlets-

examples-terracotta\1.1\servlets-examples-terracotta-1.1.war"

<Directory "CATALINA_HOME\repository\geronimo\servlets-examples-

terracotta\1.1\servlets-examples-terracotta-1.1.war">

Options Indexes +FollowSymLinks

AllowOverride None

Allow from all

</Directory>

<Location /*/WEB-INF/*>

AllowOverride None

deny from all

</Location>

JkMount /servlets-examples-terracotta loadbalancer

JkMount /servlets-examples-terracotta/* loadbalancer

</IfModule>

Page 15: Terracotta LoadBalancing and Clustering

Load Balancing & Clustering

Terracotta Server

Page 15

Testing Demo Load Balancing:

1] Start Terracotta server using command above.

2] Start HTTP server using command above.

3] Start Geronimo-Tomcat server using command above.

4] Start application “SessionExample” using following link

http://YourHost/servlets-examples-terracotta/servlet/SessionExample

Note that the output page contains the ID of the server that is servicing the request. In your

browser window, fill in the appropriate input fields and hit the submit button. Add a few

more items to your shopping cart. Notice that the browser indicates which server (Server1

or Server2) is servicing your request. Without Sticky Session support, you may see the load

balancer alternately route the requests between the two cluster members. If you have setup

everything correctly, then the shopping cart data should be present in the session after the

browser request moves between the two servers. For Sticky Session, you can test failover by

stopping the Geronimo server that is currently servicing the session and seeing that the next

http request will failover into the remaining cluster member. The httpsession data from the

previous request should be recovered and displayed in the refreshed browser window.

Note:

When testing using a web browser, make sure that you erase cookies and cached

pages between test cases. Browser caching can cause confusion when testing.

Page 16: Terracotta LoadBalancing and Clustering

Load Balancing & Clustering

Terracotta Server

Page 16

Useful Links:

http://mule.mulesource.org/display/MULE/Clustering

http://mule.mulesource.org/display/MULE/External+Clustering+for+Mule

http://cwiki.apache.org/GMOxDEV/clustering-geronimo-with-open-terracotta.html

http://www.johnturner.com/howto/winxp-howto.html

http://www.devside.net/guides/windows/tomcat

http://www.cnr.berkeley.edu/~salazar/apache_tomcat.html

http://www.debianhelp.co.uk/apachetomcat.htm

http://www.devside.net/guides/windows/mod-jk

http://tomcat.apache.org/tomcat-3.3-doc/mod_jk-howto.html