LB template for load-balancer service

Instructions to create load-balancer template to work with GlassFish and provide load-balancer service

For Native mode, user need to only create lb.zip file. Please proceed to section Installation details for Native mode.

Prerequisite for creating load-balancer template for KVM

First create a GlassFish template using provided set of instructions. If you have already created GlassFish template, then lets move on.

  • If you have a Virtual Machine(VM) for GlassFish, then just clone it. After cloning is complete, start the cloned VM.
  • Else if you have glassfish.img and glassfish.xml, then copy it to say apache.img and apache.xml respectively. You can use any other name as well. Now start virt-manager, and click on Create a new virtual machine. Select option of Import existing disk image and point to apache.img. Once VM creation is complete, then start the VM.

Creating load-balancer template

The following instructions provide details on how to install Openssl, Apache httpd and mod_jk to create a load-balancer template

Required packages

We need to compile different components for load-balancer service. Therefore we need to install make, gcc and g++ packages.

sudo apt-get install make gcc g++

Installation details

The following directories are used as default for installation of Openssl and Apache. You can customize these directories as per your requirement.

  • APACHE HTTPD INSTALL DIR : /u01/glassfish/lb/install
  • OPENSSL INSTALL DIR : /u01/glassfish/lb/install

First create /u01/glassfish directory

sudo mkdir /u01/glassfish
sudo chown -R cloud:cloud /u01/glassfish

Note : In case you are using other username than cloud, then please transfer ownership of directory /u01/glassfish to that user.

Installing Openssl

  • Get openssl source from Openssl site. The current latest version is openssl-1.0.0e.
  • Compile and install it using following commands
    cd openssl-1.0.0e
    ./config --prefix=/u01/glassfish/lb/install --openssldir=/u01/glassfish/lb/install/conf shared
    make
    make test
    make install

    Note : Above example uses /u01/glassfish/lb/install as openssl installation directory. You can customize it to your preferred directory. Please provide your preferred directory using --prefix option.

Installing Apache httpd

  • Get Apache httpd source from Apache site. The current latest version is httpd 2.2.21.
  • Compile and install it using following commands :
    cd httpd-2.2.21
    ./configure --prefix=/u01/glassfish/lb/install --with-ssl=/u01/glassfish/lb/install --enable-ssl --enable-so --with-mpm=worker --with-included-apr --enable-rewrite
    make
    make install

Note : Above example uses /u01/glassfish/lb/install as apache httpd installation directory. You can customize it to your preferred directory. Please provide your preferred directory using --prefix option. Also if you have installed openssl in non-default directory, please provide that directory for --with-ssl option.

Installing mod_jk module

  • Get the source for tomcat connectors from Apache site. The current latest version is jk 1.2.32.
  • Compile and install it using following commands :
    cd tomcat-connectors-1.2.32-src/native
    ./configure --with-apxs=/u01/glassfish/lb/install/bin/apxs
    make
    make install

Note : If you have installed apache httpd in non-default directory, please provide location of apxs under apache install directory for --with-apxs option.

Parametrize Apache httpd and configure mod_jk

  • Parametrize http port in APACHE-INSTALL-DIR/conf/httpd.conf and also add worker configuration for mod_jk module. The difference between the original and modified httpd.conf is captured below :
    --- /u01/glassfish/lb/install/conf/httpd.conf.orig	2011-10-03 02:34:46.000000000 -0700
    +++ /u01/glassfish/lb/install/conf/httpd.conf	2011-10-03 02:39:05.000000000 -0700
    @@ -37,7 +37,7 @@
     # prevent Apache from glomming onto all bound IP addresses.
     #
     #Listen 12.34.56.78:80
    -Listen 80
    +Listen <HTTP_PORT>
    
     #
     # Dynamic Shared Object (DSO) Support
    @@ -413,3 +413,20 @@
     SSLRandomSeed startup builtin
     SSLRandomSeed connect builtin
     </IfModule>
    +
    +LoadModule jk_module modules/mod_jk.so
    +<IfModule jk_module>
    +JkWorkersFile conf/worker.properties
    +# Where to put jk logs
    +JkLogFile logs/mod_jk.log
    +# Set the 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"
    +</IfModule>
    +<VirtualHost _default_:<HTTP_PORT> >
    +Include conf/glassfish-jkmount.conf
    +</VirtualHost>
    +Include conf/glassfish-vhosts.conf
  • Add a placeholder worker.properties to APACHE-INSTALL-DIR/conf. This will be updated during association phase.
    bash#touch /u01/glassfish/lb/install/conf/worker.properties
  • Add a placeholder glassfish-vhosts.conf and glassfish-jkmount.conf to APACHE-INSTALL-DIR/conf. This will be updated during association phase.
bash#touch /u01/glassfish/lb/install/conf/glassfish-vhosts.conf
bash#touch /u01/glassfish/lb/install/conf/glassfish-jkmount.conf
  • Parametrize https port in APACHE-INSTALL-DIR/conf/extra/httpd-ssl.conf and also add worker configuration for mod_jk module. The difference between the original and modified httpd-ssl.conf is captured below :
    --- /u01/glassfish/lb/install/conf/extra/httpd-ssl.conf.orig	2011-10-03 02:35:02.000000000 -0700
    +++ /u01/glassfish/lb/install/conf/extra/httpd-ssl.conf	2011-10-03 02:36:17.000000000 -0700
    @@ -34,7 +34,7 @@
     # Note: Configurations that use IPv6 but not IPv4-mapped addresses need two
     #       Listen directives: "Listen [::]:443" and "Listen 0.0.0.0:443"
     #
    -Listen 443
    +Listen <HTTPS_PORT>
    
     ##
     ##  SSL Global Context
    @@ -71,7 +71,7 @@
     ## SSL Virtual Host Context
     ##
    
    -<VirtualHost _default_:443>
    +<VirtualHost _default_:<HTTPS_PORT>>
    
     #   General setup for the virtual host
     DocumentRoot "/u01/glassfish/lb/install/htdocs"
    @@ -228,4 +228,5 @@
     CustomLog "/u01/glassfish/lb/install/logs/ssl_request_log" \
               "%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \"%r\" %b"
    
    +Include conf/glassfish-jkmount.conf
     </VirtualHost>

Cleanup for KVM

Once apache, openssl and mod_jk modules are installed, you can remove their source and compiled files. They are not needed any further.

Now shutdown the virtual machine, and you can use this image for adding load-balancer template in DAS.

Adding load-balancer template in DAS for KVM mode

  • Use below command to add load-balancer template in DAS if you have installed apache httpd in default directories.
    $GLASSFISH_HOME/bin/asadmin create-template --virtualization kvm --files $TEMPLATE_DIR/apache.img,$TEMPLATE_DIR/apache.xml --indexes ServiceType=LB,VirtualizationType=libvirt apachemodjk
    $GLASSFISH_HOME/bin/asadmin create-template-user --virtualization kvm --userid 1000 --groupid 1000 --template apachemodjk cloud

    Note : Here GLASSFISH_HOME refers to your glassfish install directory, and TEMPLATE_DIR refers to directory where you have kept load-balancer image and xml file. In case you have created load-balancer image and xml files with names other name apache.img and apache.xml, then please use that.

  • Use below command to add load-balancer temmplate in DAS if you have installed apache httpd in non-default directories.
    $GLASSFISH_HOME/bin/asadmin create-template --virtualization kvm --files $TEMPLATE_DIR/apache.img,$TEMPLATE_DIR/apache.xml --properties install-dir=${APACHE_INSTALL_DIR} --indexes ServiceType=LB,VirtualizationType=libvirt apachemodjk
    $GLASSFISH_HOME/bin/asadmin create-template-user --virtualization kvm --userid 1000 --groupid 1000 --template apachemodjk cloud

    Note : APACHE_INSTALL_DIR refers to directory where you have installed Apache httpd. GLASSFISH_HOME refers to your glassfish install directory, and TEMPLATE_DIR refers to directory where you have kept load-balancer image and xml file. In case you have created load-balancer image and xml files with names other name apache.img and apache.xml, then please use that.

Adding load-balancer template in DAS for Native mode

  • Create lb.zip file
    bash# cd /u01/glassfish/
    bash# zip -r lb.zip lb
    bash# rm -rf lb/
  • Use below command to add load-balancer template in DAS if you have installed apache httpd in default directories.
    cp /u01/glassfish/lb.zip $GLASSFISH_HOME/config
    $GLASSFISH_HOME/bin/asadmin create-template --indexes ServiceType=LB,VirtualizationType=Native LBNative

    Note : Here GLASSFISH_HOME refers to your glassfish install directory

  • Use below command to add load-balancer temmplate in DAS if you have installed apache httpd in non-default directories.
    cp $APACHE_INSTALL_DIR/lb.zip $GLASSFISH_HOME/config
    $GLASSFISH_HOME/bin/asadmin create-template --properties install-dir=${APACHE_INSTALL_DIR} --indexes ServiceType=LB,VirtualizationType=Native LBNative

    Note : APACHE_INSTALL_DIR refers to directory where you have installed Apache httpd. GLASSFISH_HOME refers to your glassfish install directory.