~ubuntu-branches/ubuntu/oneiric/libapache-mod-jk/oneiric

« back to all changes in this revision

Viewing changes to docs/howto/workers.html

  • Committer: Bazaar Package Importer
  • Author(s): Steve Kowalik
  • Date: 2006-08-05 16:30:53 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20060805163053-myf66gm6j1a21ps6
Tags: 1:1.2.18-1ubuntu1
Merge from Debian unstable.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<html><head><META http-equiv="Content-Type" content="text/html; charset=iso-8859-1"><title>Tomcat Connector - Workers HowTo</title><meta value="Henri Gomez" name="author"><meta value="hgomez@apache.org" name="email"><meta value="Gal Shachor" name="author"><meta value="shachor@il.ibm.com" name="email"><meta value="Mladen Tur" name="author"><meta value="mturk@apache.org" name="email"><link rel="stylesheet" type="text/css" href="../style.css"></head><body vlink="#525D76" alink="#525D76" link="#525D76" text="#000000" bgcolor="#ffffff"><table cellspacing="4" width="100%" border="0"><!--PAGE HEADER--><tr><td colspan="2"><!--TOMCAT LOGO--><a href="http://tomcat.apache.org/"><img border="0" alt="Apache Tomcat" align="left" src="../images/tomcat.gif"></a><!--APACHE LOGO--><a href="http://www.apache.org/"><img border="0" alt="Apache Logo" align="right" src="http://www.apache.org/images/asf-logo.gif"></a></td></tr><!--HEADER SEPARATOR--><tr><td colspan="2"><hr size="1" noshade="noshade"></td></tr><tr><!--LEFT SIDE NAVIGATION--><td nowrap="true" valign="top" width="20%"><p><strong>Links</strong></p><ul><li><a href="../index.html">Docs Home</a></li></ul><p><strong>Generic Howto</strong></p><ul><li><a href="quick.html">For the impatient</a></li><li><a href="workers.html">All about workers</a></li><li><a href="loadbalancers.html">Load Balancing</a></li></ul><p><strong>Webservers</strong></p><ul><li><a href="apache.html">Apache</a></li><li><a href="iis.html">IIS</a></li><li><a href="domino.html">Domino</a></li><li><a href="nes.html">SunOne (Netscape)</a></li></ul><p><strong>Get Involved</strong></p><ul><li><a href="doccontrib.html">Contribute documentation</a></li></ul></td><!--RIGHT SIDE MAIN BODY--><td align="left" valign="top" width="80%"><table cellspacing="4" width="100%" border="0"><tr><td valign="top" align="left"><h1>Tomcat Connector</h1><h2>Workers HowTo</h2></td><td nowrap="true" valign="top" align="right"><small><a href="printer/workers.html"><img alt="Printer Friendly Version" border="0" src="../images/printer.gif"><br>print-friendly<br>version
 
2
                    </a></small></td></tr></table><table width="100%" cellpadding="2" cellspacing="0" border="0"><tr><td bgcolor="#525D76"><font face="arial,helvetica.sanserif" color="#ffffff"><a name="Introduction"><strong>Introduction</strong></a></font></td></tr><tr><td><blockquote>
 
3
<p>
 
4
A Tomcat worker is a Tomcat instance that is waiting to execute servlets on behalf of some web server. 
 
5
For example, we can have a web server such as Apache forwarding servlet requests to a 
 
6
Tomcat process (the worker) running behind it.
 
7
</p>
 
8
<p>
 
9
The scenario described above is a very simple one; 
 
10
in fact one can configure multiple Tomcat workers to serve servlets on 
 
11
behalf of a certain web server. 
 
12
The reasons for such configuration can be:
 
13
</p>
 
14
<ul>
 
15
<li>
 
16
We want different contexts to be served by different Tomcat workers to provide a 
 
17
development environment where all the developers share the same web server but own a Tomcat worker of their own.
 
18
</li>
 
19
<li>
 
20
We want different virtual hosts served by different Tomcat processes to provide a 
 
21
clear separation between sites belonging to different companies.
 
22
</li>
 
23
<li>
 
24
We want to provide load balancing, meaning run multiple Tomcat workers each on a 
 
25
machine of its own and distribute the requests between them.
 
26
</li>
 
27
</ul>
 
28
 
 
29
<p>
 
30
There are probably more reasons for having multiple workers but I guess that this list is enough...
 
31
Tomcat workers are defined in a properties file dubbed workers.properties and this tutorial 
 
32
explains how to work with it.
 
33
</p>
 
34
 
 
35
<p>
 
36
This document was originally part of <b>Tomcat: A Minimalistic User's Guide</b> written by Gal Shachor, 
 
37
but has been split off for organizational reasons. 
 
38
</p>
 
39
</blockquote></td></tr></table><table width="100%" cellpadding="2" cellspacing="0" border="0"><tr><td bgcolor="#525D76"><font face="arial,helvetica.sanserif" color="#ffffff"><a name="Defining Workers"><strong>Defining Workers</strong></a></font></td></tr><tr><td><blockquote>
 
40
<p>
 
41
Defining workers to the Tomcat web server plugin can be done using a properties file 
 
42
(a sample file named workers.properties is available in the conf/ directory).
 
43
</p>
 
44
 
 
45
<p>
 
46
the file contains entries of the following form:
 
47
</p>
 
48
 
 
49
<p>
 
50
<b>worker.list</b>=&lt;a comma separated list of worker names&gt;
 
51
</p>
 
52
 
 
53
<div class="example"><pre>
 
54
  # the list of workers
 
55
  worker.list= worker1, worker2
 
56
</pre></div>
 
57
 
 
58
<p>
 
59
When starting up, the web server plugin will instantiate the workers whose name appears in the 
 
60
<b>worker.list</b> property, these are also the workers to whom you can map requests.
 
61
</p>
 
62
 
 
63
<table width="100%" cellpadding="2" cellspacing="0" border="0"><tr><td bgcolor="#828DA6"><font face="arial,helvetica.sanserif" color="#ffffff"><a name="Workers Type"><strong>Workers Type</strong></a></font></td></tr><tr><td><blockquote>
 
64
<p>
 
65
Each named worker should also have a few entries to provide additional information on his behalf.
 
66
This information includes the worker's type and other related worker information. 
 
67
Currently the following worker types that exists are (JK 1.2.5):
 
68
</p>
 
69
 
 
70
<table>
 
71
  <tr><th>Type</th><th>Description</th></tr>
 
72
  <tr><td>ajp12</td><td>This worker knows how to forward requests to out-of-process Tomcat workers using the ajpv12 protocol.</td></tr>
 
73
  <tr><td>ajp13</td><td>This worker knows how to forward requests to out-of-process Tomcat workers using the ajpv13 protocol.</td></tr>
 
74
  <tr><td>jni</td><td>This worker knows how to forward requests to in-process Tomcat workers using JNI.</td></tr>
 
75
  <tr><td>lb</td><td>This is a load-balancing worker; it knows how to provide round-robin based sticky load balancing with a certain level of fault-tolerance.</td></tr>
 
76
  <tr><td>status</td><td>This is a status worker for managing load balancers.</td></tr>
 
77
</table>
 
78
 
 
79
<p>
 
80
Defining workers of a certain type should be done with the following property format:
 
81
</p>
 
82
 
 
83
<p>
 
84
<b>worker</b>. <b>worker name</b>.<b>type</b>=&lt;worker type&gt;
 
85
Where worker name is the name assigned to the worker and the worker type is one of the four types defined 
 
86
in the table (a worker name may not contain any space (a good naming convention for queue named should 
 
87
follow the Java variable naming rules).
 
88
</p>
 
89
 
 
90
<div class="example"><pre>
 
91
  # Defines a worker named "local" that uses the ajpv12 protocol to forward requests to a Tomcat process.
 
92
  worker.local.type=ajp12
 
93
  # Defines a worker named "remote" that uses the ajpv13 protocol to forward requests to a Tomcat process.
 
94
  worker.remote.type=ajp13
 
95
  # Defines a worker named "fast" that uses JNI to forward requests to a Tomcat process.
 
96
  worker.fast.type=jni
 
97
  # Defines a worker named "loadbalancer" that loadbalances several Tomcat processes transparently.
 
98
  worker.loadbalancer.type=lb
 
99
</pre></div>
 
100
 
 
101
</blockquote></td></tr></table>
 
102
 
 
103
</blockquote></td></tr></table><table width="100%" cellpadding="2" cellspacing="0" border="0"><tr><td bgcolor="#525D76"><font face="arial,helvetica.sanserif" color="#ffffff"><a name="Setting Worker Properties"><strong>Setting Worker Properties</strong></a></font></td></tr><tr><td><blockquote>
 
104
<p>
 
105
After defining the workers you can also specify properties for them. 
 
106
Properties can be specified in the following manner:
 
107
</p>
 
108
 
 
109
<p>
 
110
worker.&lt;worker name&gt;.&lt;property&gt;=&lt;property value&gt;
 
111
</p>
 
112
 
 
113
Each worker has a set of properties that you can set as specified in the following subsections:
 
114
 
 
115
<table width="100%" cellpadding="2" cellspacing="0" border="0"><tr><td bgcolor="#828DA6"><font face="arial,helvetica.sanserif" color="#ffffff"><a name="ajp12 Worker properties"><strong>ajp12 Worker properties</strong></a></font></td></tr><tr><td><blockquote>
 
116
<p><p><font color="#ff0000">
 
117
The <b>ajp12</b> has been <b>deprecated</b> with Tomcat 3.3.x and you should use instead 
 
118
<b>ajp13</b> which is the only ajp protocol known by Tomcat 4.x and 5.
 
119
</font></p></p> 
 
120
<p>
 
121
The ajp12 typed workers forward requests to out-of-process Tomcat workers 
 
122
using the ajpv12 protocol over TCP/IP sockets.
 
123
</p>
 
124
 
 
125
<p>
 
126
the ajp12 worker properties are :
 
127
</p>
 
128
 
 
129
<p>
 
130
<b>host</b> property set the host where the Tomcat worker is listening for ajp12 requests.
 
131
</p>
 
132
 
 
133
<p>
 
134
<b>port</b> property set The port where the Tomcat worker is listening for ajp12 requests
 
135
</p>
 
136
 
 
137
<p>
 
138
<b>lbfactor</b>property is used when working with a load balancer worker, this is the load-balancing factor for the worker.
 
139
We'll see more on this in the lb worker section.
 
140
</p>
 
141
 
 
142
<div class="example"><pre>
 
143
  # worker "worker1" will talk to Tomcat listening on machine www.x.com at port 8007 using 2 lb factor
 
144
  worker.worker1.host=www.x.com
 
145
  worker.worker1.port=8007
 
146
  worker.worker1.lbfactor=2
 
147
</pre></div>
 
148
 
 
149
<p>
 
150
Notes: In the ajpv12 protocol, connections are created, used and then closed at each request.
 
151
The default port for ajp12 is 8007
 
152
</p>
 
153
 
 
154
</blockquote></td></tr></table>
 
155
 
 
156
<table width="100%" cellpadding="2" cellspacing="0" border="0"><tr><td bgcolor="#828DA6"><font face="arial,helvetica.sanserif" color="#ffffff"><a name="ajp13 Worker properties"><strong>ajp13 Worker properties</strong></a></font></td></tr><tr><td><blockquote>
 
157
<p>
 
158
The ajp13 typed workers forward requests to out-of-process Tomcat workers using the ajpv13 protocol over TCP/IP sockets.
 
159
The main difference between ajpv12 and ajpv13 are that:
 
160
<ul>
 
161
<li>
 
162
ajpv13 is a more binary protocol and it try to compress some of the request data by coding 
 
163
frequently used strings as small integers.
 
164
</li>
 
165
<li>
 
166
ajpv13 reuse open sockets and leaves them open for future requests (remember when you've got a Firewall between your 
 
167
WebServer and Tomcat).
 
168
</li>
 
169
<li>
 
170
ajpv13 has special treatment for SSL information so that the container can implement 
 
171
SSL related methods such as isSecure().
 
172
</li>
 
173
</ul>
 
174
 
 
175
</p>
 
176
 
 
177
<p>
 
178
You should note that Ajp13 is now the only out-process protocol supported by Tomcat 4.0.x, 4.1.x and 5.
 
179
</p>
 
180
 
 
181
 
 
182
<div class="example"><pre>
 
183
  # worker "worker2" will talk to Tomcat listening on machine www2.x.com at port 8009 using 3 lb factor
 
184
  worker.worker2.host=www2.x.com
 
185
  worker.worker2.port=8009
 
186
  worker.worker2.lbfactor=3
 
187
  # worker "worker2" use up to 10 sockets, which will stay no more than 10mn in the connection pool
 
188
  worker.worker2.connection_pool_size=10
 
189
  worker.worker2.connection_pool_timeout=600
 
190
  # worker "worker2" ask operating system to send KEEP-ALIVE signal on the connection
 
191
  worker.worker2.socket_keepalive=1
 
192
  # mount can be used as an alternative to the JkMount directive
 
193
  worker.worker2.mount=/contexta /contexta/* /contextb /contextb/*
 
194
</pre></div>
 
195
 
 
196
<p>
 
197
Notes: In the ajpv13 protocol, the default port is 8009
 
198
</p>
 
199
 
 
200
</blockquote></td></tr></table>
 
201
 
 
202
<table width="100%" cellpadding="2" cellspacing="0" border="0"><tr><td bgcolor="#828DA6"><font face="arial,helvetica.sanserif" color="#ffffff"><a name="lb Worker properties"><strong>lb Worker properties</strong></a></font></td></tr><tr><td><blockquote>
 
203
<p>
 
204
The load-balancing worker does not really communicate with Tomcat workers.
 
205
Instead it is responsible for the management of several "real" workers. 
 
206
This management includes:
 
207
</p>
 
208
 
 
209
<ul>
 
210
<li>
 
211
Instantiating the workers in the web server.
 
212
</li>
 
213
<li>
 
214
Using the worker's load-balancing factor, perform weighed-round-robin load balancing where 
 
215
high lbfactor means stronger machine (that is going to handle more requests)
 
216
</li>
 
217
<li>
 
218
Keeping requests belonging to the same session executing on the same Tomcat worker.
 
219
</li>
 
220
<li>
 
221
Identifying failed Tomcat workers, suspending requests to them and instead fall-backing on 
 
222
other workers managed by the lb worker.
 
223
</li>
 
224
</ul>
 
225
 
 
226
<p>
 
227
The overall result is that workers managed by the same lb worker are load-balanced (based on their lbfactor and current user session) and also fall-backed so a single Tomcat process death will not "kill" the entire site.
 
228
The following table specifies properties that the lb worker can accept:
 
229
<ul>
 
230
<li><b>balance_workers</b> is a comma separated list of workers that the load balancer need to manage. 
 
231
These workers should not appear in the worker.list property.</li>
 
232
<li><b>sticky_session</b> specifies whether requests with SESSION ID's should be routed back to the same
 
233
Tomcat worker. If sticky_session is an flag and if it is set to True and sessions are sticky, otherwise
 
234
sticky_session is set to false. Set sticky_session to False when Tomcat is using a Session Manager which
 
235
can persist session data across multiple instances of Tomcat. By default sticky_session is set to True.</li>
 
236
</ul>
 
237
</p>
 
238
 
 
239
<div class="example"><pre>
 
240
   The worker balance1 while use "real" workers worker1 and worker2
 
241
  worker.balance1.balance_workers=worker1, worker2
 
242
</pre></div>
 
243
 
 
244
</blockquote></td></tr></table>
 
245
 
 
246
<table width="100%" cellpadding="2" cellspacing="0" border="0"><tr><td bgcolor="#828DA6"><font face="arial,helvetica.sanserif" color="#ffffff"><a name="Advanced lb Worker properties"><strong>Advanced lb Worker properties</strong></a></font></td></tr><tr><td><blockquote>
 
247
<p>
 
248
With JK 1.2.x, new load-balancing and fault-tolerant support has been added via
 
249
2 new properties, <b>redirect</b> and <b>disabled</b>.
 
250
</p>
 
251
 
 
252
<p>
 
253
Let's take an example environment:
 
254
</p>
 
255
 
 
256
<p>
 
257
A cluster with two nodes (worker1+worker2), running a webserver + tomcat tandem on each node and 
 
258
a loadbalancer in front of the nodes.
 
259
</p>
 
260
 
 
261
<div class="example"><pre>
 
262
  # The advanced router LB worker
 
263
  worker.list=router
 
264
 
 
265
  # Define a worker using ajp13
 
266
  worker.worker1.port=8009
 
267
  worker.worker1.host=node1.domain.org
 
268
  worker.worker1.type=ajp13
 
269
  worker.worker1.lbfactor=1
 
270
  # Define prefered failover node for worker1
 
271
  worker.worker1.redirect=worker2
 
272
 
 
273
  # Define another worker using ajp13
 
274
  worker.worker2.port=8009
 
275
  worker.worker2.host=node2.domain.org
 
276
  worker.worker2.type=ajp13
 
277
  worker.worker2.lbfactor=1
 
278
  # Disable worker2 for all requests except failover
 
279
  worker.worker2.disabled=True
 
280
  
 
281
  # Define the LB worker
 
282
  worker.router.type=lb
 
283
  worker.router.balance_workers=worker1,worker2
 
284
</pre></div>
 
285
 
 
286
<p>
 
287
The <b>redirect</b> flag on worker1 tells the <b>lb_worker</b> to redirect the requests
 
288
to worker2 only if worker1 is in error state. In other cases worker2 will not receive
 
289
any requests, thus acting like a hot standby.
 
290
</p>
 
291
 
 
292
 
 
293
</blockquote></td></tr></table>
 
294
 
 
295
<table width="100%" cellpadding="2" cellspacing="0" border="0"><tr><td bgcolor="#828DA6"><font face="arial,helvetica.sanserif" color="#ffffff"><a name="Status Worker properties"><strong>Status Worker properties</strong></a></font></td></tr><tr><td><blockquote>
 
296
<p>
 
297
The status worker does not communicate with Tomcat.
 
298
Instead it is responsible for the load balancer management. 
 
299
</p>
 
300
<div class="example"><pre>
 
301
  # Add the status worker to the worker list
 
302
  worker.list=jkstatus
 
303
  # Define a 'jkstatus' worker using status
 
304
  worker.jkstatus.type=status
 
305
</pre></div>
 
306
<p>Next thing is to mount the requests to the jkstatus worker. For Apache
 
307
web servers use the:</p>
 
308
<div class="example"><pre>
 
309
  # Add the jkstatus mount point
 
310
  JkMount /jkmanager/* jkstatus 
 
311
</pre></div>
 
312
<p>To obtain a higher level of security use the:</p>
 
313
<div class="example"><pre>
 
314
  # Enable the JK manager access from localhost only
 
315
 &lt;Location /jkmanager/&gt;
 
316
    JkMount jkstatus
 
317
    Order deny,allow
 
318
    Deny from all
 
319
    Allow from 127.0.0.1
 
320
 &lt;/Location&gt;
 
321
</pre></div>
 
322
 
 
323
</blockquote></td></tr></table>
 
324
 
 
325
<table width="100%" cellpadding="2" cellspacing="0" border="0"><tr><td bgcolor="#828DA6"><font face="arial,helvetica.sanserif" color="#ffffff"><a name="Property file macros"><strong>Property file macros</strong></a></font></td></tr><tr><td><blockquote>
 
326
<p>
 
327
You can define "macros" in the property files. 
 
328
These macros let you define properties and later on use them while 
 
329
constructing other properties and it's very usefull when you want to
 
330
change your Java Home, Tomcat Home or OS path separator
 
331
</p>
 
332
 
 
333
<div class="example"><pre>
 
334
  # property example, don't hardcode path separator
 
335
  ps=\
 
336
  workers.tomcat_home=d:\tomcat
 
337
  workers.java_home=d:\sdk\jdk1.2.2
 
338
  # Using macros we'll have : worker.inprocess.class_path=d:\tomcat\classes
 
339
  worker.inprocess.class_path=$(workers.tomcat_home)$(ps)classes
 
340
  # Using macros we'll have : worker.inprocess.class_path=d:\sdk\jdk1.2.2\lib\tools.jar
 
341
  worker.inprocess.class_path=$(workers.java_home)$(ps)lib$(ps)tools.jar
 
342
</pre></div>
 
343
 
 
344
</blockquote></td></tr></table>
 
345
 
 
346
</blockquote></td></tr></table><table width="100%" cellpadding="2" cellspacing="0" border="0"><tr><td bgcolor="#525D76"><font face="arial,helvetica.sanserif" color="#ffffff"><a name="A sample worker.properties"><strong>A sample worker.properties</strong></a></font></td></tr><tr><td><blockquote>
 
347
<p>
 
348
Since coping with worker.properties on your own is not an easy thing to do, 
 
349
a sample worker.properties file is bundled along JK. 
 
350
</p>
 
351
 
 
352
<p>
 
353
You could also find here a sample workers.properties defining :
 
354
</p>
 
355
 
 
356
<ul>
 
357
<li>
 
358
An ajp12 worker that used the host localhost and the port 8007
 
359
</li>
 
360
<li>
 
361
An ajp13 worker that used the host localhost and the port 8008
 
362
</li>
 
363
<li>
 
364
A jni worker
 
365
</li>
 
366
<li>
 
367
A lb worker that load balance the ajp12 and ajp13 workers
 
368
</li>
 
369
</ul>
 
370
 
 
371
<div class="example"><pre>
 
372
  # Define some properties
 
373
  workers.apache_log=/var/log/httpd/
 
374
  workers.tomcat_home=/var/tomcat3
 
375
  workers.java_home=/opt/IBMJava2-131/
 
376
  ps=/
 
377
  # Define 4 workers, 3 real workers using ajp12, ajp13, jni, the last one being a loadbalancing worker 
 
378
  worker.list=worker1, worker2, worker3, worker4
 
379
  # Set properties for worker1 (ajp12)
 
380
  worker.worker1.type=ajp12
 
381
  worker.worker1.host=locahost
 
382
  worker.worker1.port=8007
 
383
  worker.worker1.lbfactor=1
 
384
  # Set properties for worker2 (ajp13)
 
385
  worker.worker2.type=ajp13
 
386
  worker.worker2.host=locahost
 
387
  worker.worker2.port=8009
 
388
  worker.worker2.lbfactor=1
 
389
  worker.worker2.connection_pool_size=10
 
390
  worker.worker2.connection_pool_timeout=600
 
391
  worker.worker2.socket_keepalive=1
 
392
  worker.worker2.socket_timeout=60
 
393
  # Set properties for worker3 (jni)
 
394
  worker.worker3.type=jni
 
395
  # Set worker3 bridge type, here Tomcat 3.3
 
396
  worker.worker3.bridge=tomcat33
 
397
  # Set worker3 classpath
 
398
  worker.worker3.class_path=$(workers.tomcat_home)$(ps)classes
 
399
  worker.worker3.class_path=$(workers.tomcat_home)$(ps)lib$(ps)tomcat.jar
 
400
  # Set worker3 tomcat command line
 
401
  worker.worker3.cmd_line=-home
 
402
  worker.worker3.cmd_line=$(workers.tomcat_home)
 
403
  # Set worker3 Tomcat/JVM settings
 
404
  worker.worker3.jvm_lib=$(workers.java_home)$(ps)jre$(ps)bin$(ps)classic$(ps)libjvm.so
 
405
  worker.worker3.stdout=$(workers.apache_log)$(ps)inprocess.stdout
 
406
  worker.worker3.stderr=$(workers.apache_log)$(ps)inprocess.stderr
 
407
  worker.worker3.sysprops=tomcat.home=$(workers.tomcat_home)
 
408
  # Set properties for worker4 (lb) which use worker1 and worker2
 
409
  worker.worker4.balance_workers=worker1,worker2
 
410
</pre></div>
 
411
 
 
412
</blockquote></td></tr></table></td></tr><!--FOOTER SEPARATOR--><tr><td colspan="2"><hr size="1" noshade="noshade"></td></tr><!--PAGE FOOTER--><tr><td colspan="2"><div align="center"><font size="-1" color="#525D76"><em>
 
413
        Copyright &copy; 1999-2005, Apache Software Foundation
 
414
        </em></font></div></td></tr></table></body></html>
 
 
b'\\ No newline at end of file'