19.6.3. Install the mod_jk Module Into the Apache HTTP Server (ZIP)

Prerequisites

  • To perform this task, you must be using Apache HTTP Server installed on a supported environment or the Apache HTTP Server installed in JBoss Enterprise Web Server. Note that the Apache HTTP Server installed in JBoss Enterprise Web Server is part of the JBoss EAP 6 distribution.
  • If you need to install Apache HTTP Server, use the instructions in the Red Hat Enterprise Linux Deployment Guide.
  • If you need to install JBoss Enterprise Web Server, use the instructions from the JBoss Enterprise Web Server Installation Guide.
  • If you are using Apache HTTP Server, download the JBoss EAP 6 Native Components package for your platform from the Red Hat Customer 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.
  • If you are using Red Hat Enterprise Linux (RHEL) 5 and native Apache HTTP server (httpd 2.2.3), load the mod_perl module prior to loading mod_jk module.
  • You must be logged in with administrative (root) privileges.

Procedure 19.11. Install the mod_jk Module

  1. 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 -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 ensure they are reasonable for your setup. 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 the Apache HTTP server does not have mod_jk.so in its modules/ directory. You can skip this step if you are using the Apache HTTP 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/system/layers/base/native/lib/httpd/modules/ or the EAP_HOME/modules/system/layers/base/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.
  2. 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, see Section 19.6.5, “Configuration Reference for Apache Mod_jk Workers”.
  3. Restart the Web Server.

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

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

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

        In Red Hat Enterprise Linux, JBoss Enterprise Web Server installs its web server as a service. To restart the web server, 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 Apache HTTP server from a Zip archive, use the apachectl command to restart the web server. Replace EWS_HOME with the directory where you unzipped JBoss Enterprise Web Server Apache HTTP server.
        [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 Apache HTTP server.
        [root@host ~] EWS_HOME/httpd/sbin/apachectl restart
        
Result

The Apache HTTP server is now configured to use the mod_jk load balancer. To configure JBoss EAP 6 to be aware of mod_jk, see Section 19.3.6, “Configure JBoss EAP 6 to Accept Requests From External Web Servers”.