Saturday, December 24, 2005

Using mod_jk 1.2.x with JBoss/Tomcat bundle and Apache2 with Suse 10

Originally used source is located at: http://www.jboss.org/wiki/Wiki.jsp?page=UsingMod_jk1.2WithJBoss

This article has some specifics related to SuSe 10:

Using Mod_jk1.2 With JBoss

Quick Overview



  1. Download Apache2

  2. Download modjk 1.2.x

  3. Change the main Apache config to include modjk config

  4. Create the modjk config

  5. Configure the modjk workers (which JBoss/Tomcat nodes Apache uses)

  6. Configure the Apache URIs served by modjk (the applications served by JBoss/Tomcat)

  7. Restart Apache

  8. Configure Tomcat (Give each JBoss/Tomcat a jvmRoute for session stickness)

  9. Restart JBoss

  10. Test it



Step #1: Download Apache2 Web Server
Get the latest Apache2 package from Apache.org and install it. We require no special configuration, just use the default settings. In the following steps, APACHE_HOME will represent the Apache install directory.

Best to do with SuSe is using yast2 or apt:
apt install apache2


Step #2: Download mod_jk 1.2.x
Download the latest package available from Jakarta's 'Tomcat connector section' page . Always download the latest release if possible.
Rename the lib mod_jk.so and drop it in /usr/lib/apache2 directory (see comments below).


Yast and apt have (at the moment of writing this) too old version of mod_jk. So I had to build from source (binary versions were available only for x64).
There are some specifics:
To build from source you need to apxs installed. To have that you need to install apache2-devel package: apt install apache2-devel

Then build from native dir:
./configure --with-apxs=/usr/sbin/apxs2 --enable-jni

"/usr/sbin/apxs2" is vere you will get apxs2 installed on SuSe 10 and it is not a standard location for mod_jk.

make

make install
(If you do make install the lib will be copied automatically to the right location)


Step #3: Setup Apache to use modjk
Add this line at the very bottom in APACHE_HOME/httpd.conf :

# Include mod_jk configuration file
Include /etc/apache2/mod_jk.conf


Step #4: Create the modjk config
Under APACHE_HOME/conf, create mod_jk.conf and populate it as follows:

This config file has all the paths changed for SuSe 10

# Load mod_jk module
# Specify the filename of the mod_jk lib
LoadModule jk_module usr/lib/apache2/mod_jk.so

# Where to find workers.properties
JkWorkersFile /etc/apache2/workers.properties

# Where to put jk logs
JkLogFile /var/log/apache2/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
JkMount /application/* loadbalancer

# 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 /etc/apache2/uriworkermap.properties

# 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 /var/log/apache2/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>


mod_jk is ready to forward requests to JBoss instances. We need now to setup the workers

Step #5: Configuring workers
Under APACHE_HOME, create workers.properties and populate it as follows:

# 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.lbfactor=1
#worker.node1.local_worker=1 (1)
worker.node1.cachesize=10

# 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.lbfactor=1
#worker.node2.local_worker=1 (1)
worker.node2.cachesize=10

# Load-balancing behaviour
worker.loadbalancer.type=lb
worker.loadbalancer.balance_workers=node1,node2
worker.loadbalancer.sticky_session=1
#worker.loadbalancer.local_worker_only=1
#worker.list=loadbalancer

# Status worker for managing load balancer
worker.status.type=status


You have to change the host names for yourself.



Step #6: Create the URI to worker map file
Create a uriworkermap.properties file in the APACHE_HOME directory. This file should contain the URL mappings you want Apache to forward to Tomcat. The format of the file is /url=worker_name. To get things started, paste this example into the file you created:

# Simple worker configuration file
#

# Mount the Servlet context to the ajp13 worker
/jmx-console=loadbalancer
/jmx-console/*=loadbalancer
/web-console=loadbalancer
/web-console/*=loadbalancer

This will configure mod_jk to forward requests to /jmx-console and /web-console to Tomcat.

Step #7: Restart Apache

Step #8: Configure Tomcat
To complete the configuration, we also need to name each node accordingly to the names specified in workers.properties.
Edit JBOSS_HOME/server/all/deploy/jbossweb-tomcat50.sar/server.xml (replace /all with your own server name, also tomcat version may change with later versions of JBoss)
Locate the <Engine….> element and add an attribute jvmRoute:

<Engine name="jboss.web" defaultHost="localhost" jvmRoute="node1">
.
</Engine>

The jvmRoute attribute must match the name specified in workers.properties.

Finally, we need to tell Tomcat to add the jvmRoute value to its session cookies so that mod_jk can route incoming requests.
Edit JBOSS_HOME/server/all/deploy/jbossweb-tomcat50.sar/META-INF/jboss-service.xml (replace /all with your own server name)
Locate the <attribute> element with a name of UseJK, and set its value to "true":


<attribute name="UseJK">true</attribute>



Step #9: Restart JBoss AS.

Step #10: Access the JBoss AS web-console through Apache by browsing to http://localhost/web-console or http://localhost/jmx-console (depends what you have configured/installed) and you should see the JBoss web console page.

Thursday, December 22, 2005

Deployment problems (myfaces)

If you just started with JSF and receive the following error message:

The absolute uri: http://java.sun.com/jsf/html cannot be resolved in either web.xml or the jar files deployed with this application


The problem can be that myfaces-impl.jar is not included in /WEB-INF/lib

Try to include this jar file in your web archive (.war) and see if you go any further.

And btw, watch out that you have compatible version of the same jar in your servlet container (Tomcat or JBoss).