This section describes how to configure Apache, Tomcat, and JOnAS to run the architecture shown in the following illustration:
This example uses mod_jk but an alternative configuration using Enhydra Director (http://director.objectweb.org) is also possible. (See Chapter 43 Load Balancing with Enhydra Director.)
mod_jk is a plug-in that handles the communication between Apache and Tomcat.
mod_jk uses the concept of a worker. A worker is a Tomcat instance that is running to perform Servlet requests coming from the web server. Each worker is identified to the web server by the host on which it is located, the port where it listens, and the communication protocol used to exchange messages. In this configuration there is one worker for each Tomcat instance and one worker that will handle the load balancing (this is a specific worker with no host and no port number). All workers are defined in the worker.properties file.
![]() | Note: |
---|---|
The JK Module can also be used for site partitioning. |
httpd.conf should load the following files:
AddModule mod_jk.c
Include $APACHE_HOME/conf/jk/tomcat_jk.conf
LoadModule jk_module libexec/mod_jk.so
To configure Tomcat, perform the following configuration steps for each Tomcat server.
Configure Tomcat for the connector AJP13. In the file installdir/conf/server.xml, add (if not already there):
<!-- Define an AJP 1.3 Connector on port 9009 --> <Connector port="9009" minProcessors="5" maxProcessors="75" acceptCount="10" debug="20" protocol="AJP/1.3"/> |
Explanations:
The TCP port number on which this Connector will create a server socket and await incoming connections.
The minimum number of processors to start at intialization time. If not specified, this attribute is set to 5.
The maximum number of processors allowed.
The maximum queue length for incoming connection requests when all possible requests processing threads are in use. Any requests received when the queue is full will be refused.
The debugging detail level of log messages generated by this component, with higher numbers creating more detailed output.
This attribute must be AJP/1.3 to use the AJP handler.
![]() | Note |
---|---|
Consult the AJP Connector documentation http://jakarta.apache.org/tomcat/tomcat-5.0-doc/condig/ajp.html. |
Define the jvmRoute.
In the installdir/conf/server.xml file, add a unique route to the Catalina engine. Replace the line:
<Engine name="Standalone" defaultHost="localhost" debug="0"> |
with:
<Engine jvmRoute="worker1" name="Standalone" defaultHost="localhost" debug="0"> |
Explanations:
Logical name of this Engine, used in log and error messages.
Uniquely identifies the Tomcat server to the Apache server. The name has been specified in the orkers.properties file.
Identifies the Host that will process requests directed to host names on this server.
The level of debugging detail logged by this Engine.
![]() | Note |
---|---|
The jvmRoute name should be the same as the name of the associated worker defined in worker.properties. This will ensure the Session affinity. Consult the Engine Container documentation http://jakarta.apache.org/tomcat/tomcat-5.0-doc/condig/engine.html. |
In the JOnAS-specific deployment descriptor, add the tag shared for the entity beans involved and set it to true. When this flag is set to true, multiple instances of the same entity bean in different JOnAS servers can access a common database concurrently.
The following is an example of a deployment descriptor with the flag shared:
<jonas-ejb-jar> <jonas-entity> <ejb-name>Id_1</ejb-name> <jndi-name>clusterId_1</jndi-name> <shared>true</shared> <jdbc-mapping> <jndi-name>jdbc_1</jndi-name> <jdbc-table-name>clusterIdentityEC</jdbc-table-name> <cmp-field-jdbc-mapping> <field-name>name</field-name> <jdbc-field-name>c_name</jdbc-field-name> </cmp-field-jdbc-mapping> <cmp-field-jdbc-mapping> <field-name>number</field-name> <jdbc-field-name>c_number</jdbc-field-name> </cmp-field-jdbc-mapping> <finder-method-jdbc-mapping> <jonas-method> <method-name>findByNumber</method-name> </jonas-method> <jdbc-where-clause>where c_number = ?</jdbc-where-clause> </finder-method-jdbc-mapping> <finder-method-jdbc-mapping> <jonas-method> <method-name>findAll</method-name> </jonas-method> <jdbc-where-clause></jdbc-where-clause> </finder-method-jdbc-mapping> </jdbc-mapping> </jonas-entity> </jonas-ejb-jar> |
The web application is now ready to run:
Start the jonas servers:
service jonas start |
Restart Apache:
/usr/local/apache2/bin/apachectl restart |
Use a browser to access the welcome page, usually index.html.
![]() | Note |
---|---|
The order of launching is important, otherwise it will not work correctly. |