3

We have a setup where we have one httpd (apache) with mod_jk talking in a load balance setup to three tomcat servers. We have to recycle each tomcat instance envery three hours. So tomcat1 will restart at 1, and tomcat2 at 2 and ... until tomcat1 recycles again at 4.

We want to configure a script or a type of program to disable the worker node that is going through a recylce to minimize session errors at the user using our application.

Any suggestions.

Geo
  • 8,663
  • 13
  • 63
  • 93

3 Answers3

2

mod_jk re-reads workers.properties on an "apachectl graceful", so you if your workers.properties looks like this:

worker.loadbalancer.type=lb
worker.loadbalancer.balanced_workers=tomcat1, tomcat2, tomcat3

... 

You could just write a script which replaces the balanced_workers list with the ones you want, and then graceful's apache

Update here's a script to do just that, which I cobbled together from some bits I had lying around. I wouldn't suggest using it in production, but it might give you some ideas for your own version.

#!/bin/bash

# set some paths
WORKERS_PROPERTIES="./workers.properties"
APACHECTL="/usr/sbin/apache2ctl"

# what does the loadbalancer config line look like?
WORKER_LINE_START="worker.loadbalancer.balanced_workers="
# full list of workers
ALL_WORKERS="tomcat1 tomcat2 tomcat3"

# first command line arg is the worker to remove. 
remove=$1

# build up the new line listing the active workers
worker_line=$WORKER_LINE_START
sep=""
for worker in $ALL_WORKERS
do
  if [ ${remove} != ${worker} ]
  then
     worker_line="${worker_line}$sep $worker"
     sep=","
  fi
done

# sed hackery to replace the current line with the one we just built.
# needs gnu sed (or another one that supports in-place editing)
sed -i.bak "s/^$WORKER_LINE_START.*$/$worker_line/" $WORKERS_PROPERTIES

# restart apache
$APACHECTL graceful
Chris May
  • 670
  • 3
  • 6
2

Chris thanks or your answer. I am sure it will work, but I wanted to trigger the change at run time, even though the graceful restart is very similar. I was able to accomplish my describe task the following way.

In your httpd.conf file you should add the following lines to enable the jkmanager for mod_jk module.

<Location /jkmanager/>
JkMount jkstatus
order deny,allow
allow from <your ip address>
allow from 127.0.0.1
deny from all
</Location>

<IfModule mod_jk.c>
...
JkMount  /jkmanager/* jkstatus
...
</IfModule>

The changes on the "workers.properties" file are:

 worker.list=router,tomcat1,tomcat2,...,tomcatn,jkstatus
 worker.jkstatus.type=status

After these changes are done, you are able to see the jkmanager by typing your url followed by /jkmanager/ at the end. You should get something similar to the following picture.

jkmanager screenshot

In order to disable workers at run time just run the following URLs against the jkmanger. You can even read status in an xml format.

To disable tomcat1 just hit:

http://your.web.server/jkmanager/?cmd=update&w=router&opt=256&from=list&att=vwa&val0=1&val1=0&val2=0  

To enable tomcat1 back hit:

http://your.web.server/jkmanager/?cmd=update&w=router&opt=256&from=list&att=vwa&val0=0&val1=0&val2=0

I posted a complete article in my blog explaining the setup in case someone needs to know.

Cloud Computing Blog

Glorfindel
  • 21,988
  • 13
  • 81
  • 109
Geo
  • 8,663
  • 13
  • 63
  • 93
  • hi I am doing the same but I am not be able to get the above screen. Other is working well. What to do?? – Kumar Dec 17 '13 at 10:43
  • The Cloud Computing Blog link is broken too. No idea where it's suppose to be going, so couldn't find a replica. – slm Mar 25 '15 at 19:30
2

gkiragiannis, you answer was interesting, but doesn't seem to work for me. I wanted to only disable one of my subworkers at a time.

Lets assume we are working with the 'agent-lb' load balancer.

To view the worker status using this url:

server-name/jkmanager/?cmd=list&w=agent-lb

To disable the 'agent-n1' sub worker use this url:

server-name/jkmanager/?cmd=update&w=agent-lb&sw=agent-n1&vwa=1

To ensure that the worker is disabled wait for the redirect to the worker status page, and look in the 'Act' field for the sub worker, 'agent-n1'

To enable the 'agent-n1' sub worker use this url:

server-name/jkmanager/?cmd=update&w=agent-lb&sw=agent-n1&vwa=0