16.6.3. Install the Mod_jk Module Into Apache HTTPD or JBoss Enterprise Web Server HTTPD

Prerequisites

  • To perform this task, you must be using Apache HTTPD installed on a supported environment or the HTTPD installed in JBoss Enterprise Web Server. Note that the HTTPD installed in JBoss Enterprise Web Server is part of the JBoss EAP 6 distribution.
  • If you need to install Apache HTTPD, use the instructions from the Red Hat Enterprise Linux Deployment Guide, available from https://access.redhat.com/site/documentation/.
  • If you need to install JBoss Enterprise Web Server, use the instructions from the JBoss Enterprise Web Server Installation Guide, available from https://access.redhat.com/site/documentation/.
  • If you are using Apache HTTPD, download the JBoss EAP 6 Native Components package for your platform from the Red Hat Customer Service Portal at https://access.redhat.com. This package contains both the mod_jk and mod_cluster binaries precompiled for Red Hat Enterprise Linux. If you are using JBoss Enterprise Web Server, it already includes the binary for mod_jk.
  • You must be logged in with administrative (root) privileges.

Procedure 16.9. Install the mod_jk Module

  1. Determine your HTTPD configuration location.

    Your HTTPD configuration location will be different depending on whether you are using Red Hat Enterprise Linux's Apache HTTPD or the HTTPD available in JBoss Enterprise Web Server. It is one of the following options, and is referred to in the rest of this task as HTTPD_HOME.
    • Apache HTTPD - /etc/httpd/
    • JBoss Enterprise Web Server HTTPD on RHEL - EWS_HOME/httpd
    • JBoss Enterprise Web Server HTTPD on Solaris - EWS_HOME/etc/httpd
    • JBoss Enterprise Web Server HTTPD on Windows - EWS_HOME/etc/httpd
  2. Configure the mod_jk module.

    1. Create a new file called HTTPD_HOME/conf.d/mod-jk.conf and add the following to it:

      Note

      The JkMount directive specifies which URLs Apache should forward to the mod_jk module. Based on the directive's configuration, mod_jk forwards the received URL to the correct Servlet containers.
      To serve static content directly, and only use the load balancer for Java applications, the URL path should be /application/*. To use mod_jk as a load balancer, use the value /*, to forward all URLs to mod_jk.
      # Load mod_jk module
      # Specify the filename of the mod_jk lib
      LoadModule jk_module modules/mod_jk.so
      
      # Where to find workers.properties
      JkWorkersFile conf/workers.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 indicates to send SSK KEY SIZE
      JkOptions +ForwardKeySize +ForwardURICompat -ForwardDirectories
      
      # JkRequestLogFormat
      JkRequestLogFormat "%w %V %T"
      
      # Mount your applications
      # The default setting only sends Java application data to mod_jk.
      # Use the commented-out line to send all URLs through mod_jk.
      # JkMount /* loadbalancer
      JkMount /application/* loadbalancer
      
      # Add shared memory.
      # This directive is present with 1.2.10 and
      # later versions of mod_jk, and is needed for
      # for load balancing to work properly
      JkShmFile logs/jk.shm 
      
      # Add jkstatus for managing runtime data
      <Location /jkstatus/>
      JkMount status
      Order deny,allow
      Deny from all
      Allow from 127.0.0.1
      </Location>
      
      
      Look over the values and make sure they are reasonable for your set-up. When you are satisfied, save the file.
    2. Specify a JKMountFile directive

      In addition to the JKMount directive in the mod-jk.conf, you can specify a file which contains multiple URL patterns to be forwarded to mod_jk.
      1. Add the following to the HTTPD_HOME/conf/mod-jk.conf file:
        # You can use external file for mount points.
        # It will be checked for updates each 60 seconds.
        # The format of the file is: /url=worker
        # /examples/*=loadbalancer
        JkMountFile conf/uriworkermap.properties
        
      2. Create a new file called HTTPD_HOME/conf/uriworkermap.properties, with a line for each URL pattern to be matched. The following example shows examples of the syntax of the file.
        # Simple worker configuration file
        /*=loadbalancer
        
    3. Copy the mod_jk.so file to the HTTPD's modules directory

      Note

      This is only necessary if your HTTPD does not have mod_jk.so in its modules/ directory. You can skip this step if you are using the Apache HTTPD server included as a download as part of JBoss EAP 6.
      Extract the Native Web Server Connectors ZIP package. Locate the mod_jk.so file in either the EAP_HOME/modules/native/lib/httpd/modules/ or the EAP_HOME/modules/native/lib64/httpd/modules/ directories, depending on whether your operating system is 32-bit or 64-bit.
      Copy the file to the HTTPD_HOME/modules/ directory.
  3. Configure the mod_jk worker nodes.

    1. Create a new file called HTTPD_HOME/conf/workers.properties. Use the following example as your starting point, and modify the file to suit your needs.
      # Define list of workers that will be used
      # for mapping requests
      worker.list=loadbalancer,status
      
      # Define Node1
      # modify the host as your host IP or DNS name.
      worker.node1.port=8009
      worker.node1.host=node1.mydomain.com
      worker.node1.type=ajp13
      worker.node1.ping_mode=A
      worker.node1.lbfactor=1 
      
      # Define Node2
      # modify the host as your host IP or DNS name.
      worker.node2.port=8009
      worker.node2.host=node2.mydomain.com
      worker.node2.type=ajp13
      worker.node2.ping_mode=A
      worker.node2.lbfactor=1
      
      # Load-balancing behavior
      worker.loadbalancer.type=lb
      worker.loadbalancer.balance_workers=node1,node2
      worker.loadbalancer.sticky_session=1
      
      # Status worker for managing load balancer
      worker.status.type=status
      
      For a detailed description of the syntax of the workers.properties file, and advanced configuration options, refer to Section 16.6.4, “Configuration Reference for Apache Mod_jk Workers”.
  4. Restart the HTTPD.

    The way to restart the HTTPD depends on whether you are using Red Hat Enterprise Linux's Apache HTTPD or the HTTPD included in JBoss Enterprise Web Server. Choose one of the two methods below.
    • Red Hat Enterprise Linux's Apache HTTPD

      Issue the following command:
      [root@host]# service httpd restart
    • JBoss Enterprise Web Server HTTPD

      JBoss Enterprise Web Server runs on both Red Hat Enterprise Linux and Microsoft Windows Server. The method for restarting the HTTPD is different for each.
      • Red Hat Enterprise Linux, installed from RPM

        In Red Hat Enterprise Linux, JBoss Enterprise Web Server installs its HTTPD as a service. To restart the HTTPD, issue the following two commands:
        [root@host ~]# service httpd stop
        [root@host ~]# service httpd start
        
      • Red Hat Enterprise Linux, installed from ZIP

        If you have installed the JBoss Enterprise Web Server HTTPD from a ZIP archive, use the apachectl command to restart the HTTPD. Replace EWS_HOME with the directory where you unzipped JBoss Enterprise Web Server HTTPD.
        [root@host ~]# EWS_HOME/httpd/sbin/apachectl restart
        
      • Microsoft Windows Server

        Issue the following commands in a command prompt with administrative privileges:
        C:\> net stop Apache2.2
        C:\> net start Apache2.2
        
      • Solaris

        Issue the following commands in a command prompt with administrative privileges. Replace EWS_HOME with the directory where you unzipped JBoss Enterprise Web Server HTTPD.
        [root@host ~] EWS_HOME/httpd/sbin/apachectl restart
        
Result

The Apache HTTPD is now configured to use the mod_jk load balancer. To configure JBoss EAP 6 to be aware of mod_jk, refer to Section 16.3.5, “Configure JBoss EAP 6 to Accept Requests From an External HTTPD”.