Version 5

    HTTP Session Replication Example


    NOTE: this is a user contribution. Some sections might be obsolete or incorrect. If you wanna find a more up to date example which has been created by a JBoss developer, please go to ReplicatedCounter wiki.





    (Also see for another explanation of how to set things up).



    Setting Apache and Tomcat loadbalancer with mod_jk1.2

    1)Download Apache 1.3.x to a location like c:\Apache\\
    2)Download mod_jk1.2.x.dll to c:\apache\modules and rename it to mod_jk.dll\\
    3)Edit httpd.conf file of Apache under c:\apache\conf\\
    Add the following two lines at the end of the file\\
    #Include mod_jk
    Include conf/mod-jk.conf
    4) Create a new file called as mod-jk.conf under the conf directory of apache
    Copy everything in between ====
    #Load mod_jk module
    LoadModule jk_module modules/mod_jk.dll
    JkWorkersFile  conf/
    #Where to put JK Logs
    JkLogFile logs/mod_jk.log
    #Set jk log level [debug/error/info]
    JkLogLevel info
    #Select the log format
    JkLogStampFormat "[%a %b %d %H:%M:%S %Y] "
    #JkOptions indicate to send SSL Key Size
    JkOptions +ForwardKeySize +ForwardURICompat   -ForwardDirectories
    #JkRequestLogFormat set the request format
    JkRequestLogFormat "%w %V %T"
    JkMount   /*  loadbalancer



    Set up Apache Load Balancer with a new file "" under the conf directory of Apache


    # ------------------------
    # First tomcat server
    # ------------------------
    # ------------------------
    # 2nd tomcat server
    # ------------------------
    # Define load Balancing behavior



    Note: JBOSS_HOME is referred to as "JB" below
    #Copy the file "sample-bindings.xml" from docs/examples/binding-example  to JB.
    On my machine it is under c:\jboss-3.2.5
    #Go to JB/server
    #Copy directory "all" to instance1 and instance2
    Windows:   xcopy   all   instance1   /S
    Windows:   xcopy   all   instance2   /S
    Unix:   cp -R all instance1
    Unix:   cp -R all instance2
    4) Go to JB/server/instance1/jbossweb-tomcat50.sar
    Edit the file "server.xml"
    Add a name to this instance of Tomcat as below with "jvmRoute" attribute.
    <Engine name="jboss.web" defaultHost="localhost" jvmRoute="TOM1"></Engine>
    4.1) Go to JB/server/instance2/jbossweb-tomcat50.sar
    Edit the file "server.xml"
    Add a name to this instance of Tomcat as below with "jvmRoute" attribute.
    <Engine name="jboss.web" defaultHost="localhost" jvmRoute="TOM2"></Engine>
    5) Go to JB/server/instance2/conf
    Edit the file  "jboss-service.xml"
    You will need to uncomment the section for ServiceBindingManager  and also update the location
    of the xml file sample-bindings.xml  (Location will be from JB/bin directory)
          | Binding service manager for port/host mapping. This is a sample
          | config that demonstrates a JBoss instances with a server name 'jboss1'
          | loading its bindings from an XML file using the ServicesStoreFactory
          | implementation returned by the XMLServicesStoreFactory.
          | ServerName: The unique name assigned to a JBoss server instance for
          | lookup purposes. This allows a single ServicesStore to handle mulitiple
          | JBoss servers.
          | StoreURL: The URL string passed to
          | during initialization that specifies how to connect to the bindings store.
          | StoreFactory: The interface
          | implementation to create to obtain the ServicesStore instance.
       <mbean code=""
         <attribute name="ServerName">ports-01</attribute>
         <attribute name="StoreURL">../sample-bindings.xml</attribute>
         <attribute name="StoreFactoryClassName">
    • For JBoss4, additional changes for ServiceBindingManager are:[ConfigurePorts|DOC-9376].





    6) Under JB\server\instance2\deploy, create a folder named test.war and drop into it a file testsessionreplication.jsp containing the following code:
    <body bgcolor=blue>
    <%=request.getSession().getId() %>
    <h1>Tomcat 1</h1>
    Do the same with JB\server\instance2\deploy\ with the following code:
    <body bgcolor=green>
    <%=request.getSession().getId() %>
    <h1>Tomcat 2</h1>
    7) Go to JB/bin  in different terminal/command windows.
    Start instance1   run -c all
    Start instance2   run -c instance2
     8) Start Apache Server
    9) Go to browser and test:
    You should see a blue page with sessionid and Tomcat1
    10) Shutdown instance1  (Do ctrl-c)
    11) Go to browser and test
    You should see a green page with sessionid and Tomcat2
    Basically you can now start and stop either of the two tomcat instances in any order.  
    The session is replicated and as long as one of them is running, you will always
    see a response on browser.





    From a frustrated developer...


    "On JBoss 3.2.5 and Tomcat 5.0 (and possibly other versions) make sure you edit jbossweb-tomcat50.sar\META-INF\jboss-service.xml

    and change the flag to false. Otherwise, although your session replication will work from a creation point of view, updates will not be replicated! I could find very little other mention of this anywhere on the Internet :)"