title: How do I configure Glassfish 4 cluster for sticky sessions?
body: <p>Trying to set up (in a test environment) a two-server Glassfish 4 cluster in readiness from migrating from our existing single-instance Glassfish 3.1 webserver to one that supported load balancing and failover.</p>
  
  <p>Primarily an application writer, the noddy-GUI interface of Glassfish looked enticing to me. In practice I have been unable to get a Glassfish 4 cluster working correct and wondered if someone could give me the configuration that I needed. There are many blogs and guides describing the process, but they are all slightly different, for different versions of Glassfish, and none of them appear to work on GF4.</p>
  
  <p>The setup:</p>
  
  <p>Server 1: app01
  To house DAS, and NODE01->INSTANCE0101(SSH)</p>
  
  <p>Server 2: app02
  To house NODE02-INSTANCE0102(SSH)</p>
  
  <p>Cluster: CLUSTER01, involving NODE01->INSTANCE0101 and NODE02->INSTANCE0102</p>
  
  <p>Having set up the two servers, java, and installed Glassfish 4 on app01. Have installed Apache on app01.
  Our old server used Apache and mod_jk to forward appropriate requests to Glassfish. I had made the appropriate change in /etc/httpd/conf/httpd.conf to forward requests to jk-connector: (pulled from appropriate sections)</p>
  
  <pre><code>    LoadModule jk_module modules/mod_jk.so
      JkWorkersFile /etc/httpd/conf/workers.properties
      JkLogFile /var/log/httpd/mod_jk.log
      JkLogLevel error
      JkLogStampFormat "[%a %b %d %H:%M:%S %Y] "
      JkOptions +ForwardKeySize +ForwardURICompat -ForwardDirectories
  
      JkMount /* loadbalancer
  </code></pre>
  
  <p>This is what I thought was appropriate for workers.properties from all of the blog posts.</p>
  
  <pre><code>    worker.list=loadbalancer
  
      # default properties for workers
      worker.template.type=ajp13
      worker.template.lbfactor=50
      worker.template.connection_pool_timeout=600
      worker.template.socket_keepalive=1
      worker.template.socket_timeout=300
  
      # properties for worker1
      worker.worker1.reference=worker.template
      worker.worker1.host=app01.btodomain.bto.org
      worker.worker1.port=8009
  
      # properties for worker2
      worker.worker2.reference=worker.template
      worker.worker2.host=app02.btodomain.bto.org
      worker.worker2.port=8010
  
      # properties for loadbalancer
      worker.loadbalancer.type=lb
      worker.loadbalancer.balance_workers=worker1,worker2
  </code></pre>
  
  <p>Glassfish configuration I believed appropriate:</p>
  
  <pre><code>    create-jvm-options --target cluster01 "-DjvmRoute=\\${AJP_INSTANCE_NAME}"
      create-jvm-options --target cluster01 "-Dcom.sun.enterprise.web.connector.enableJK=\\${AJP_PORT}"
      create-system-properties --target instance0101 AJP_INSTANCE_NAME=instance0101
      create-system-properties --target instance0102 AJP_INSTANCE_NAME=instance0102
      create-system-properties --target instance0101 AJP_PORT=8009
      create-system-properties --target instance0102 AJP_PORT=8010
      create-network-listener --protocol http-listener-1 --listenerport “${AJP_PORT}” --jkenabled true --target cluster01 jk-connector
  </code></pre>
  
  <p>In addition to the configuration not working, when fiddling with the settings, I’ve twice ended up in a situation where test applications will not redeploy or un-deploy/deploy with Glassfish claiming that an application by the same name already existing (when it doesn’t)</p>
  
  <p>Any help would be appreciated.</p>
  
  <p>Mark</p>