Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I am trying to set up a JBoss Cluster with Apache Load Balancing. But when I type localhost in my browser it should get redirected (proxied?) to port 8080 (JBoss) but it is not getting redirected.

Here's my environment setup:

Ubuntu 11.04
JBoss AS 5.1-GA
Apache 2
mod_jk 1.2.30

My setup looks something like the following:

Apache Web Server: 192.168.1.12:80 - lb1
JBoss App Server 1: 192.168.1.12:8080 - app1
JBoss App Server 2: 192.168.1.23:8080 - app2

My loadbalancer and JBoss1 is on the same machine. (I even tried keeping it on two different machines).

I have copied the mod_jk.so file into /usr/lib/apache2/modules/mod_jk.so, and executed the following steps:

  1. Now execute the following # echo LoadModule jk_module /usr/lib/apache2/modules/mod_jk.so" > /etc/apache2/mods-available/jk.load
  2. And # touch /etc/apache2/mods-available/jk.conf
  3. And # touch /etc/apache2/workers.conf
  4. # a2enmod jk

I have created the file /etc/apache2/workers.conf in the lb1 machine

# Defining the workers list:
worker.list=loadbalancer,status
# first worker properties, we use the AJB13 connection type:
worker.worker1.type=ajp13
worker.worker1.connection_pool_size=20
worker.worker1.host=192.168.1.12
worker.worker1.port=8080
worker.worker1.lbfactor=1
# second worker properties, we use the AJB13 connection type:
worker.worker2.type=ajp13
worker.worker2.connection_pool_size=20
worker.worker2.host=192.168.1.23
worker.worker2.port=8080
worker.worker2.lbfactor=1
# No we set the load balancing config
worker.loadbalancer.type=lb
worker.loadbalancer.sticky_session=true
worker.loadbalancer.balance_workers=worker1,worker2
worker.status.type=status

And I have created the file /etc/apache2/mods-available/jk.conf:

<IfModule mod_jk.c>
# The Jk shared mem location
JkShmFile /var/log/apache2/mod_jk.shm

# Jk logs
JkLogFile /var/log/apache2/mod_jk.log
# Jk loglevel
JkLogLevel info
# Jk logformat
JkLogStampFormat "[%a %b %d %H:%M:%S %Y] "

# Our workers config
JkWorkersFile /etc/apache2/workers.conf

# The most important:
# We will send eveything (/*) to our loadbalancer (set in JkWorkersFile)
JkMount /* loadbalancer
</IfModule>

I changed the serve.xml file of my JBoss:

<Connector port="8009" address="${jboss.bind.address}"
emptySessionPath="true" enableLookups="false" redirectPort="8443" 
protocol="AJP/1.3" connectionTimeout="600000" maxThreads="200"/>

I checked the log files it says mod_jk is initialized.

But its not getting redirected to 8080 port of jboss.

Thanks in Advance.

This my mod_jk.log file

  [Tue Jul 19 13:17:23 2011] [5505:3079493376] [info] init_jk::mod_jk.c (3183):       
  mod_jk/1.2.28 initialized
  [Tue Jul 19 13:17:23 2011] [5506:3079493376] [info] init_jk::mod_jk.c (3183):    
  mod_jk/1.2.28 initialized

and error.log file of apache

  [Tue Jul 19 13:17:23 2011] [notice] Apache/2.2.17 (Ubuntu) mod_jk/1.2.28 configured --      
  resuming normal operations
  [Tue Jul 19 13:22:13 2011] [error] [client 192.168.1.12] File does not exist:   
  /var/www/favicon.ico
share|improve this question

2 Answers 2

up vote 0 down vote accepted

I see such potential errors:

  1. Base on workers.conf file you want to connect on port 8080 using AJP protocol. If you want use AJP you should use such definition (look at port definition):

    worker.worker1.type=ajp13
    worker.worker1.connection_pool_size=20
    worker.worker1.host=192.168.1.12
    worker.worker1.port=8009
    worker.worker1.lbfactor=1
    
  2. There is lack of definition in Engine tag in server.xml file. On each server you should define jvmRoute parameter - base on your workrs.conf file:

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

    You can find more info here: http://tomcat.apache.org/tomcat-5.5-doc/config/engine.html

  3. How dou you run your JBoss? By default JBoss listine only on localhost. you can check it using netstat:

    netstat -ltnp
    

    You can also run JBoss with -b parameter:

    run.sh -b 192.168.1.12
    
share|improve this answer
    
thanks for the help. i tried the above things but still its not getting redirected to 8080 port. –  VISHAL Jul 19 '11 at 7:56
    
i checked the apache log file is shows. [Tue Jul 19 13:17:23 2011] [notice] Apache/2.2.17 (Ubuntu) mod_jk/1.2.28 configured -- resuming normal operations. [Tue Jul 19 13:22:13 2011] [error] [client 192.168.1.12] File does not exist: /var/www/favicon.ico –  VISHAL Jul 19 '11 at 7:57
    
i have addded my log files.pls have look into it. –  VISHAL Jul 19 '11 at 8:03
    
Did you change your workers.properties configuration? You use AJP protocol to connect to the JBoss and by default you should use 8009 port, not 8080. –  Lukasz Stelmach Jul 19 '11 at 12:23
    
yes i did changed it. –  VISHAL Jul 19 '11 at 12:33

Here is the entire process step by step for loadbalancing jboss App server with apache using mod_jk.

step 1: Environment setup

Ubuntu 11.04
JBoss AS 5.1-GA
Apache 2
mod_jk 1.2.30

My setup looks something like the following:

 Apache Web Server: 192.168.1.12:80 - lb1
 JBoss App Server 1: 192.168.1.53:8080 - app1
 JBoss App Server 2: 192.168.1.56:8080 - app2

step 2: configuring apache

create following files in /etc/apache2/conf folder

 step -I: create file httpd.conf

 # Include mod_jk's specific configuration file  
 Include conf/mod-jk.conf  

and replace this file with one that is there in /etc/apache

step -II: create file mod-jk.conf

  # 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
 # here cluster1 is the name of the test project that i used 

  JkMountFile conf/uriworkermap.properties   

  JkMount /cluster1 loadbalancer
  JkMount /cluster1/* 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>

 <VirtualHost *:80>

 ServerName 192.168.1.53

 JkMountFile conf/uriworkermap.properties

 </VirtualHost>

step -III: create file uriworkermap.properties

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

step -IV: create file workers.properties

  # 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.worker1.port=8009
  worker.worker1.host=192.168.1.53
  worker.worker1.type=ajp13
  worker.worker1.lbfactor=1
  worker.worker1.cachesize=10

 # Define Node2
 # modify the host as your host IP or DNS name.
 worker.worker2.port=8009
 worker.worker2.host= 192.168.1.56
 worker.worker2.type=ajp13
 worker.worker2.lbfactor=1
 worker.worker2.cachesize=10

 # Load-balancing behaviour
 worker.loadbalancer.type=lb
 worker.loadbalancer.balance_workers=worker1,worker2
 worker.loadbalancer.sticky_session=1
 #worker.list=loadbalancer

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


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

Step3: configuring jboss

modify the server.xml of your jboss as follows:

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

same for the server2 using worker2 instead of worker1.

now start the jboss and apache. try localhost in your browser in lb1 machine it will get redirected to jboss page( on port 8080) running on on server1.

for best result try to use three different machines. i tried it on ubuntu-11.04 and centos its working fine.

thats it.

Thanks.............

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.