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

Prerequisites

  • To perform this task, you must be using Apache HTTPD installed in Red Hat Enterprise Linux, or the HTTPD installed in JBoss Enterprise Web Server.
  • If you need to install Apache HTTPD, use the instructions from the Red Hat Enterprise Linux Deployment Guide, available from https://access.redhat.com/knowledge/docs/.
  • 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/knowledge/docs/.
  • If you are using Apache HTTPD, download the JBoss Enterprise Application Platform Native Components package for Red Hat Enterprise Linux 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 13.10. Task

  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 Platform. It is one of the following two options, and is referred to in the rest of this task as HTTPD_HOME.
    • Apache HTTPD - /etc/httpd/
    • JBoss Enterprise Web Server HTTPD - EWS_HOME/httpd/
  2. Configure the mod_jk module.

    1. Open HTTPD_HOME/conf/httpd.conf in a text editor and add the following to the end of the file:
      # Include mod_jk's specific configuration file  
      Include conf/mod-jk.conf
      
    2. Create a new file called HTTPD_HOME/etc/httpd/conf/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.
    3. 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
        
    4. 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 Enterprise Application Platform 6.
      Extract the Native Components ZIP package. Locate the mod_jk.so file in either the native/lib/httpd/modules/ or native/lib64/httpd/modules/ directory, 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 13.4.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

        In Red Hat Enterprise Linux, 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
        
      • Microsoft Windows Server

        Issue the following commands in a command prompt with administrative privileges:
        C:\> net stop httpd
        C:\> net start httpd
        
Result

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