Loadbalancing with mod_jk and GlassFish

In addition to jfarcands blog about mod_jk and GlassFish I also wanted to try out mod_jk loadbalancing with GlassFish. Here is the cookbook on how to get a simple load balancing scenario set up:


Software needed:

  • Apache 2.0.x
  • Apache Tomcat Connectors link
  • Apache Tomcat 5.5.16 (needed for just one jar File)
  • Apache Commons Logging 1.0.4 link
  • Apache Commons Modeler 1.1 link
  • And of course you need at least two running installations of GlassFish V1/V2.


    Steps to setup load balancing:

  • Install mod_jk into your Apache config (copy mod_jk.so to your Apache modules directory)
  • Configure your Apache httpd to include mod_jk.so by editing your httpd.conf to include the following:

    LoadModule jk_module modules/mod_jk.so
    JkWorkersFile path_to_your_config/conf/workers.properties
    JkLogFile path_to_your_log_dir/mod_jk.log
    JkLogLevel info
    JkLogStampFormat "[%a %b %d %H:%M:%S %Y] "
    JkOptions +ForwardKeySize +ForwardURICompat -ForwardDirectories
    JkRequestLogFormat "%w %V %T"
    #Mount your webapps eg WebApplication1 using JkMount
    JkMount /WebApplication1/\* loadbalancer

  • Create a worker.properties File for the mod_jk connector. In the example shown below a load balancing worker for two local GlassFish instances (listening on jk port 8009/8010) is provided.

    worker.list=loadbalancer
    worker.worker1.type=ajp13
    worker.worker1.host=localhost
    worker.worker1.port=8009
    worker.worker1.lbfactor=1
    worker.worker1.socket_keepalive=1
    worker.worker1.socket_timeout=300
    worker.worker2.type=ajp13
    worker.worker2.host=localhost
    worker.worker2.port=8010
    worker.worker2.lbfactor=1
    worker.worker2.socket_keepalive=1
    worker.worker2.socket_timeout=300
    worker.loadbalancer.type=lb
    worker.loadbalancer.balance_workers=worker1,worker2


  • Enable the jk connector in each GlassFish instance by adding a JVM Option with asadmin. If your instances run on the same box you have to choose different JK ports. The ports must also match your worker.workerX.port definitions in your worker.properties files.
    $GLASSFISH_HOME/bin/asadmin create-jvm-options 
    -Dcom.sun.enterprise.web.connector.enableJK=8009

  • Copy the following jar archives to your GlassFish Installations lib directory ($GLASSFISH_HOME/lib): tomcat-ajp.jar (from Tomcat 5.5.16 /server/lib dir), commons-logging.jar and commons-modeler.jar.
  • Next restart your apache httpd and your glassfish instances.
  • If JK connector was enabled successfully in glassfish you should see a log entry in your server log as for example:
    [#|2006-12-01T11:33:14.667+0100|INFO|sun-appserver-pe9.0|
    org.apache.jk.common.ChannelSocket|_ThreadID=11;_ThreadName=Thread-5;|JK: ajp13 listening on /0.0.0.0:8009|#]

    Now all web applications that are deployed to your GlassFish instances and that are mounted in your httpd.conf through JkMount commands should be loadbalanced equally.

    More advanced jk configuration properties may be found in the Tomcat connectors documentation

  • Kommentare:

    Senden Sie einen Kommentar:
    Kommentare sind ausgeschaltet.
    About

    Daniel Adelhardt

    Search

    Archives
    « April 2014
    MoDiMiDoFrSaSo
     
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
        
           
    Heute