windows下tomcat集群配置(两种方法)

两种方法只是在配置上不同原理一样,因为apache2.X后其自身集成了mod_jk功能,相对于1.3版本,不需要再进行繁琐的worker.properties配置,配置过程大幅简化。

一、软件需求
  操作系统:Windows XP
  JDK:jdk1.6.0_16,下载地址:http://www.oracle.com/technetwork/java/javase/downloads/index.html 。
  Apache :httpd-2.2.17 (一个),下载地址:http://httpd.apache.org/ 。
  Tomcat:tomcat-7.0.2 (两个),下载地址:http://tomcat.apache.org/download-70.cgi 。
  mod_jk:mod_jk-apache-2.0.55.so (1个),下载地址:http://tomcat.apache.org/download-70.cgi 。

二、环境搭建

  安照上篇《windows下apache tomcat整合》中的方法安装jdk/apache/tomcat

三、环境配置(两种配置)

  1.  原始配置

    (1)apache配置

       1>mod_jk.conf(apache/conf)

mod_jk.conf  
 1 # 加载mod_jk模块,此处的mod_jk.so为你复制到modules/下的mod_jk名   
 2 LoadModule jk_module modules/mod_jk-apache-2.2.2.so
 3 # 指定 workers.properties文件路径(指定tomcat监听配置文件地址
 4 JkWorkersFile conf/workers.properties
 5 # 设置日志存放路径   
 6 JkLogFile logs/mod_jk.log
 7 # 设置日志级别 [debug/error/info]   
 8 JkLogLevel info   
 9 # 设置日志格式   
10 JkLogStampFormat "[%a %b %d %H:%M:%S %Y]"  
11 # JkOptions indicate to send SSL KEY SIZE,   
12 JkOptions +ForwardKeySize +ForwardURICompat -ForwardDirectories   
13 # JkRequestLogFormat set the request format   
14 JkRequestLogFormat "%w %V %T"  
15 
16 #设置虚拟主机
17 #
18 #如果非虚拟主机,将和最后的注释或者删除掉即可
19 #ServerAdmin localhost
20 #DocumentRoot E:/wwwroot
21 #>
22 #您的站点项目所在路径,应与tomcat中的目录设置相同,据说以上两个必须同时设置才可以生效,没有试过不同的时候会有什么情况
23 #ServerName localhost
24 #DirectoryIndex index.html index.htm index.jsp
25 #ErrorLog logs/shsc-error_log.txt
26 #CustomLog logs/shsc-access_log.txt common
27 #JkMount /servlet/* ajp13 
28 #让Apache支持对servlet传送,用以Tomcat解析
29 #JkMount /*.jsp ajp13 
30 #让Apache支持对jsp传送,用以Tomcat解析
31 #JkMount /*.do ajp13 
32 #让Apache支持对.do传送,用以Tomcat解析
33 #
34 
35 #Send servlet for context /examples to worker named #ajp13,指定那些请求交给tomcat处理,"controller"为在workers.propertise里指定的负载分配控制器(让Apache支持对jsp传送,用以Tomcat解析)
36 JkMount /*.jsp controller
37 JkMount /*.do controller 
38 JkMount /*.dd controller
39 JkMount /*.ee controller
40 JkMount /servlet/* controller
41 JkMount /gwyhr* controller

                  2>httpd.conf(apache/conf)

httpd.conf
  1 #
  2 # This is the main Apache HTTP server configuration file.  It contains the
  3 # configuration directives that give the server its instructions.
  4 # See > for detailed information.
  5 # In particular, see 
  6 # /mod/directives.html>
  7 # for a discussion of each configuration directive.
  8 #
  9 # Do NOT simply read the instructions in here without understanding
 10 # what they do.  They're here only as hints or reminders.  If you are unsure
 11 # consult the online docs. You have been warned.  
 12 #
 13 # Configuration and logfile names: If the filenames you specify for many
 14 # of the server's control files begin with "/" (or "drive:/" for Win32), the
 15 # server will use that explicit path.  If the filenames do *not* begin
 16 # with "/", the value of ServerRoot is prepended -- so "logs/foo.log"
 17 # with ServerRoot set to "D:/Program Files/Apache Software Foundation/Apache2.2" will be interpreted by the
 18 # server as "D:/Program Files/Apache Software Foundation/Apache2.2/logs/foo.log".
 19 #
 20 # NOTE: Where filenames are specified, you must use forward slashes
 21 # instead of backslashes (e.g., "c:/apache" instead of "c:\apache").
 22 # If a drive letter is omitted, the drive on which httpd.exe is located
 23 # will be used by default.  It is recommended that you always supply
 24 # an explicit drive letter in absolute paths to avoid confusion.
 25 
 26 #
 27 # ServerRoot: The top of the directory tree under which the server's
 28 # configuration, error, and log files are kept.
 29 #
 30 # Do not add a slash at the end of the directory path.  If you point
 31 # ServerRoot at a non-local disk, be sure to point the LockFile directive
 32 # at a local disk.  If you wish to share the same ServerRoot for multiple
 33 # httpd daemons, you will need to change at least LockFile and PidFile.
 34 #
 35 ServerRoot "D:/Program Files/Apache Software Foundation/Apache2.2"
 36 
 37 #
 38 # Listen: Allows you to bind Apache to specific IP addresses and/or
 39 # ports, instead of the default. See also the 
 40 # directive.
 41 #
 42 # Change this to Listen on specific IP addresses as shown below to 
 43 # prevent Apache from glomming onto all bound IP addresses.
 44 #
 45 #Listen 12.34.56.78:80
 46 Listen 80
 47 
 48 #
 49 # Dynamic Shared Object (DSO) Support
 50 #
 51 # To be able to use the functionality of a module which was built as a DSO you
 52 # have to place corresponding `LoadModule' lines at this location so the
 53 # directives contained in it are actually available _before_ they are used.
 54 # Statically compiled modules (those listed by `httpd -l') do not need
 55 # to be loaded here.
 56 #
 57 # Example:
 58 # LoadModule foo_module modules/mod_foo.so
 59 #
 60 LoadModule actions_module modules/mod_actions.so
 61 LoadModule alias_module modules/mod_alias.so
 62 LoadModule asis_module modules/mod_asis.so
 63 LoadModule auth_basic_module modules/mod_auth_basic.so
 64 #LoadModule auth_digest_module modules/mod_auth_digest.so
 65 #LoadModule authn_alias_module modules/mod_authn_alias.so
 66 #LoadModule authn_anon_module modules/mod_authn_anon.so
 67 #LoadModule authn_dbd_module modules/mod_authn_dbd.so
 68 #LoadModule authn_dbm_module modules/mod_authn_dbm.so
 69 LoadModule authn_default_module modules/mod_authn_default.so
 70 LoadModule authn_file_module modules/mod_authn_file.so
 71 #LoadModule authnz_ldap_module modules/mod_authnz_ldap.so
 72 #LoadModule authz_dbm_module modules/mod_authz_dbm.so
 73 LoadModule authz_default_module modules/mod_authz_default.so
 74 LoadModule authz_groupfile_module modules/mod_authz_groupfile.so
 75 LoadModule authz_host_module modules/mod_authz_host.so
 76 #LoadModule authz_owner_module modules/mod_authz_owner.so
 77 LoadModule authz_user_module modules/mod_authz_user.so
 78 LoadModule autoindex_module modules/mod_autoindex.so
 79 #LoadModule cache_module modules/mod_cache.so
 80 #LoadModule cern_meta_module modules/mod_cern_meta.so
 81 LoadModule cgi_module modules/mod_cgi.so
 82 #LoadModule charset_lite_module modules/mod_charset_lite.so
 83 #LoadModule dav_module modules/mod_dav.so
 84 #LoadModule dav_fs_module modules/mod_dav_fs.so
 85 #LoadModule dav_lock_module modules/mod_dav_lock.so
 86 #LoadModule dbd_module modules/mod_dbd.so
 87 
 88 ######apache启用gzip压缩######
 89 #加载mod_deflate.so模块
 90 LoadModule deflate_module modules/mod_deflate.so
 91 #对text/html text/php text/png text/jpg text/plain text/css text/xml text/javascript启用GZIP压缩
 92 AddOutputFilterByType DEFLATE text/html text/php text/png text/jpg text/plain text/css text/xml text/javascript
 93 #压缩级别 9 性能最佳
 94 DeflateCompressionLevel 9
 95 #启用deflate模块对本站点的所有输出进行GZIP压缩
 96 SetOutputFilter DEFLATE
 97 #############################
 98 
 99 LoadModule dir_module modules/mod_dir.so
100 #LoadModule disk_cache_module modules/mod_disk_cache.so
101 #LoadModule dumpio_module modules/mod_dumpio.so
102 LoadModule env_module modules/mod_env.so
103 #LoadModule expires_module modules/mod_expires.so
104 #LoadModule ext_filter_module modules/mod_ext_filter.so
105 #LoadModule file_cache_module modules/mod_file_cache.so
106 #LoadModule filter_module modules/mod_filter.so
107 #LoadModule headers_module modules/mod_headers.so
108 #LoadModule ident_module modules/mod_ident.so
109 #LoadModule imagemap_module modules/mod_imagemap.so
110 LoadModule include_module modules/mod_include.so
111 #LoadModule info_module modules/mod_info.so
112 LoadModule isapi_module modules/mod_isapi.so
113 #LoadModule ldap_module modules/mod_ldap.so
114 #LoadModule logio_module modules/mod_logio.so
115 LoadModule log_config_module modules/mod_log_config.so
116 #LoadModule log_forensic_module modules/mod_log_forensic.so
117 #LoadModule mem_cache_module modules/mod_mem_cache.so
118 LoadModule mime_module modules/mod_mime.so
119 #LoadModule mime_magic_module modules/mod_mime_magic.so
120 LoadModule negotiation_module modules/mod_negotiation.so
121 #LoadModule proxy_module modules/mod_proxy.so
122 #LoadModule proxy_ajp_module modules/mod_proxy_ajp.so
123 #LoadModule proxy_balancer_module modules/mod_proxy_balancer.so
124 #LoadModule proxy_connect_module modules/mod_proxy_connect.so
125 #LoadModule proxy_ftp_module modules/mod_proxy_ftp.so
126 #LoadModule proxy_http_module modules/mod_proxy_http.so
127 #LoadModule proxy_scgi_module modules/mod_proxy_scgi.so
128 #LoadModule reqtimeout_module modules/mod_reqtimeout.so
129 #LoadModule rewrite_module modules/mod_rewrite.so
130 LoadModule setenvif_module modules/mod_setenvif.so
131 #LoadModule speling_module modules/mod_speling.so
132 #LoadModule ssl_module modules/mod_ssl.so
133 #LoadModule status_module modules/mod_status.so
134 #LoadModule substitute_module modules/mod_substitute.so
135 #LoadModule unique_id_module modules/mod_unique_id.so
136 #LoadModule userdir_module modules/mod_userdir.so
137 #LoadModule usertrack_module modules/mod_usertrack.so
138 #LoadModule version_module modules/mod_version.so
139 #LoadModule vhost_alias_module modules/mod_vhost_alias.so
140 
141 
142 
143 #
144 # If you wish httpd to run as a different user or group, you must run
145 # httpd as root initially and it will switch.  
146 #
147 # User/Group: The name (or #number) of the user/group to run httpd as.
148 # It is usually good practice to create a dedicated user and group for
149 # running httpd, as with most system services.
150 #
151 User daemon
152 Group daemon
153 
154 
155 
156 
157 # 'Main' server configuration
158 #
159 # The directives in this section set up the values used by the 'main'
160 # server, which responds to any requests that aren't handled by a
161 #  definition.  These values also provide defaults for
162 # any  containers you may define later in the file.
163 #
164 # All of these directives may appear inside  containers,
165 # in which case these default settings will be overridden for the
166 # virtual host being defined.
167 #
168 
169 #
170 # ServerAdmin: Your address, where problems with the server should be
171 # e-mailed.  This address appears on some server-generated pages, such
172 # as error documents.  e.g. [email protected]
173 #
174 ServerAdmin [email protected]
175 
176 #
177 # ServerName gives the name and port that the server uses to identify itself.
178 # This can often be determined automatically, but we recommend you specify
179 # it explicitly to prevent problems during startup.
180 #
181 # If your host doesn't have a registered DNS name, enter its IP address here.
182 #
183 #ServerName localhost:80
184 
185 #
186 # DocumentRoot: The directory out of which you will serve your
187 # documents. By default, all requests are taken from this directory, but
188 # symbolic links and aliases may be used to point to other locations.
189 #
190 DocumentRoot "D:/Program Files/Apache Software Foundation/Apache2.2/htdocs"
191 
192 #
193 # Each directory to which Apache has access can be configured with respect
194 # to which services and features are allowed and/or disabled in that
195 # directory (and its subdirectories). 
196 #
197 # First, we configure the "default" to be a very restrictive set of 
198 # features.  
199 #
200 
201     Options FollowSymLinks
202     AllowOverride None
203     Order deny,allow
204     Deny from all
205 
206 
207 #
208 # Note that from this point forward you must specifically allow
209 # particular features to be enabled - so if something's not working as
210 # you might expect, make sure that you have specifically enabled it
211 # below.
212 #
213 
214 #
215 # This should be changed to whatever you set DocumentRoot to.
216 #
217 >
218     #
219     # Possible values for the Options directive are "None", "All",
220     # or any combination of:
221     #   Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
222     #
223     # Note that "MultiViews" must be named *explicitly* --- "Options All"
224     # doesn't give it to you.
225     #
226     # The Options directive is both complicated and important.  Please see
227     # http://httpd.apache.org/docs/2.2/mod/core.html#options
228     # for more information.
229     #
230     Options Indexes FollowSymLinks
231 
232     #
233     # AllowOverride controls what directives may be placed in .htaccess files.
234     # It can be "All", "None", or any combination of the keywords:
235     #   Options FileInfo AuthConfig Limit
236     #
237     AllowOverride None
238 
239     #
240     # Controls who can get stuff from this server.
241     #
242     Order allow,deny
243     Allow from all
244 
245 
246 
247 #
248 # DirectoryIndex: sets the file that Apache will serve if a directory
249 # is requested.
250 # 此处加上index.jsp是为了配置完tomcat后若apache中的index.html不存在则能看到tomcat的首页(可以不加,则看到的是it works)
251 #
252 
253     DirectoryIndex index.html index.jsp
254 
255 
256 #
257 # The following lines prevent .htaccess and .htpasswd files from being 
258 # viewed by Web clients. 
259 #
260 >
261     Order allow,deny
262     Deny from all
263     Satisfy All
264 
265 
266 #
267 # ErrorLog: The location of the error log file.
268 # If you do not specify an ErrorLog directive within a 
269 # container, error messages relating to that virtual host will be
270 # logged here.  If you *do* define an error logfile for a 
271 # container, that host's errors will be logged there and not here.
272 #
273 ErrorLog "logs/error.log"
274 
275 #
276 # LogLevel: Control the number of messages logged to the error_log.
277 # Possible values include: debug, info, notice, warn, error, crit,
278 # alert, emerg.
279 #
280 LogLevel warn
281 
282 
283     #
284     # The following directives define some format nicknames for use with
285     # a CustomLog directive (see below).
286     #
287     LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
288     LogFormat "%h %l %u %t \"%r\" %>s %b" common
289 
290     
291       # You need to enable mod_logio.c to use %I and %O
292       LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" combinedio
293     
294 
295     #
296     # The location and format of the access logfile (Common Logfile Format).
297     # If you do not define any access logfiles within a 
298     # container, they will be logged here.  Contrariwise, if you *do*
299     # define per- access logfiles, transactions will be
300     # logged therein and *not* in this file.
301     #
302     CustomLog "logs/access.log" common
303 
304     #
305     # If you prefer a logfile with access, agent, and referer information
306     # (Combined Logfile Format) you can use the following directive.
307     #
308     #CustomLog "logs/access.log" combined
309 

310 
311 
312     #
313     # Redirect: Allows you to tell clients about documents that used to 
314     # exist in your server's namespace, but do not anymore. The client 
315     # will make a new request for the document at its new location.
316     # Example:
317     # Redirect permanent /foo http://localhost/bar
318 
319     #
320     # Alias: Maps web paths into filesystem paths and is used to
321     # access content that does not live under the DocumentRoot.
322     # Example:
323     # Alias /webpath /full/filesystem/path
324     #
325     # If you include a trailing / on /webpath then the server will
326     # require it to be present in the URL.  You will also likely
327     # need to provide a  section to allow access to
328     # the filesystem path.
329 
330     #
331     # ScriptAlias: This controls which directories contain server scripts. 
332     # ScriptAliases are essentially the same as Aliases, except that
333     # documents in the target directory are treated as applications and
334     # run by the server when requested rather than as documents sent to the
335     # client.  The same rules about trailing "/" apply to ScriptAlias
336     # directives as to Alias.
337     #
338     ScriptAlias /cgi-bin/ "D:/Program Files/Apache Software Foundation/Apache2.2/cgi-bin/"
339 
340 
341 
342 
343     #
344     # ScriptSock: On threaded servers, designate the path to the UNIX
345     # socket used to communicate with the CGI daemon of mod_cgid.
346     #
347     #Scriptsock logs/cgisock
348 
349 
350 #
351 # "D:/Program Files/Apache Software Foundation/Apache2.2/cgi-bin" should be changed to whatever your ScriptAliased
352 # CGI directory exists, if you have that configured.
353 #
354 >
355     AllowOverride None
356     Options None
357     Order allow,deny
358     Allow from all
359 
360 
361 #
362 # DefaultType: the default MIME type the server will use for a document
363 # if it cannot otherwise determine one, such as from filename extensions.
364 # If your server contains mostly text or HTML documents, "text/plain" is
365 # a good value.  If most of your content is binary, such as applications
366 # or images, you may want to use "application/octet-stream" instead to
367 # keep browsers from trying to display binary files as though they are
368 # text.
369 #
370 DefaultType text/plain
371 
372 
373     #
374     # TypesConfig points to the file containing the list of mappings from
375     # filename extension to MIME-type.
376     #
377     TypesConfig conf/mime.types
378 
379     #
380     # AddType allows you to add to or override the MIME configuration
381     # file specified in TypesConfig for specific file types.
382     #
383     #AddType application/x-gzip .tgz
384     #
385     # AddEncoding allows you to have certain browsers uncompress
386     # information on the fly. Note: Not all browsers support this.
387     #
388     #AddEncoding x-compress .Z
389     #AddEncoding x-gzip .gz .tgz
390     #
391     # If the AddEncoding directives above are commented-out, then you
392     # probably should define those extensions to indicate media types:
393     #
394     AddType application/x-compress .Z
395     AddType application/x-gzip .gz .tgz
396 
397     #
398     # AddHandler allows you to map certain file extensions to "handlers":
399     # actions unrelated to filetype. These can be either built into the server
400     # or added with the Action directive (see below)
401     #
402     # To use CGI scripts outside of ScriptAliased directories:
403     # (You will also need to add "ExecCGI" to the "Options" directive.)
404     #
405     #AddHandler cgi-script .cgi
406 
407     # For type maps (negotiated resources):
408     #AddHandler type-map var
409 
410     #
411     # Filters allow you to process content before it is sent to the client.
412     #
413     # To parse .shtml files for server-side includes (SSI):
414     # (You will also need to add "Includes" to the "Options" directive.)
415     #
416     #AddType text/html .shtml
417     #AddOutputFilter INCLUDES .shtml
418 
419 
420 #
421 # The mod_mime_magic module allows the server to use various hints from the
422 # contents of the file itself to determine its type.  The MIMEMagicFile
423 # directive tells the module where the hint definitions are located.
424 #
425 #MIMEMagicFile conf/magic
426 
427 #
428 # Customizable error responses come in three flavors:
429 # 1) plain text 2) local redirects 3) external redirects
430 #
431 # Some examples:
432 #ErrorDocument 500 "The server made a boo boo."
433 #ErrorDocument 404 /missing.html
434 #ErrorDocument 404 "/cgi-bin/missing_handler.pl"
435 #ErrorDocument 402 http://localhost/subscription_info.html
436 #
437 
438 #
439 # MaxRanges: Maximum number of Ranges in a request before
440 # returning the entire resource, or one of the special
441 # values 'default', 'none' or 'unlimited'.
442 # Default setting is to accept 200 Ranges.
443 #MaxRanges unlimited
444 
445 #
446 # EnableMMAP and EnableSendfile: On systems that support it, 
447 # memory-mapping or the sendfile syscall is used to deliver
448 # files.  This usually improves server performance, but must
449 # be turned off when serving from networked-mounted 
450 # filesystems or if support for these functions is otherwise
451 # broken on your system.
452 #
453 #EnableMMAP off
454 #EnableSendfile off
455 
456 # Supplemental configuration
457 #
458 # The configuration files in the conf/extra/ directory can be 
459 # included to add extra features or to modify the default configuration of 
460 # the server, or you may simply copy their contents here and change as 
461 # necessary.
462 
463 # Server-pool management (MPM specific)
464 #Include conf/extra/httpd-mpm.conf
465 
466 # Multi-language error messages
467 #Include conf/extra/httpd-multilang-errordoc.conf
468 
469 # Fancy directory listings
470 #Include conf/extra/httpd-autoindex.conf
471 
472 # Language settings
473 #Include conf/extra/httpd-languages.conf
474 
475 # User home directories
476 #Include conf/extra/httpd-userdir.conf
477 
478 # Real-time info on requests and configuration
479 #Include conf/extra/httpd-info.conf
480 
481 # Virtual hosts
482 #Include conf/extra/httpd-vhosts.conf
483 
484 # Local access to the Apache HTTP Server Manual
485 #Include conf/extra/httpd-manual.conf
486 
487 # Distributed authoring and versioning (WebDAV)
488 #Include conf/extra/httpd-dav.conf
489 
490 # Various default settings
491 #Include conf/extra/httpd-default.conf
492 
493 # Secure (SSL/TLS) connections
494 #Include conf/extra/httpd-ssl.conf
495 #
496 # Note: The following must must be present to support
497 #       starting without SSL on platforms with no /dev/random equivalent
498 #       but a statically compiled-in mod_ssl.
499 #
500 
501 SSLRandomSeed startup builtin
502 SSLRandomSeed connect builtin
503 
504 include conf/mod_jk.conf

                  3>workers.properties(apache/conf)

workers.properties
 1 #workers.tomcat_home=D:\software\apache-tomcat-6.0.20\apache-tomcat-6.0.20
 2 #workers.java_home=C:\Program Files\Java\jdk1.6.0_18\jre
 3 #ps=\
 4 #worker.list=ajp13
 5 #worker.ajp13.port=8009
 6 #worker.ajp13.host=localhost
 7 #worker.ajp13.type=ajp13
 8 #worker.ajp13.lbfactor=1
 9 #tomcat的路径,让mod_jk模块知道
10 workers.tomcat1_home=D:\Program Files\Apache Software Foundation\tomcat1
11 workers.tomcat2_home=D:\Program Files\Apache Software Foundation\tomcat2
12 workers.tomcat3_home=D:\Program Files\Apache Software Foundation\tomcat3
13 #jdk的路径,让mod_jk模块知道jre的位置
14 workers.java_home=C:\Program Files\Java\jdk1.6.0_18\jre
15 #路径分隔符
16 ps=\
17 #server 列表(tomcat1,tomcat2,tomcat3为别名)
18 worker.list = controller #模块版本
19 #========tomcat1========
20 worker.tomcat1.port=8009 #ajp13 端口号,在tomcat下server.xml配置,默认8009(工作端口,若没占用则不用修改)
21 worker.tomcat1.host=localhost #tomcat的主机地址,如不为本机,请填写ip地址
22 worker.tomcat1.type=ajp13 #类型
23 worker.tomcat1.lbfactor = 1 #server的加权比重,值越高,分得的请求越多(代理数,不用修改)
24 #========tomcat2========
25 worker.tomcat2.port=9009 #ajp13 端口号,在tomcat下server.xml配置,默认8009
26 worker.tomcat2.host=localhost #tomcat的主机地址,如不为本机,请填写ip地址
27 worker.tomcat2.type=ajp13
28 worker.tomcat2.lbfactor = 1 #server的加权比重,值越高,分得的请求越多
29 #========tomcat3========
30 worker.tomcat3.port=9010 #ajp13 端口号,在tomcat下server.xml配置,默认8009
31 worker.tomcat3.host=localhost #tomcat的主机地址,如不为本机,请填写ip地址
32 worker.tomcat3.type=ajp13
33 worker.tomcat3.lbfactor = 1 #server的加权比重,值越高,分得的请求越多
34 #========controller,负载均衡控制器========
35 worker.controller.type=lb
36 worker.controller.balanced_workers=tomcat1,tomcat2,tomcat3 #指定分担请求的tomcat
37 worker.controller.sticky_session=False #粘性会话设置

          (2)tomcat配置

      1>server.xml(tomcat/conf)

server.xml
  1 xml version='1.0' encoding='utf-8'?>
  2 
 18 
 22 <Server port="8005" shutdown="SHUTDOWN">
 23 
 24   
 25   <Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" />
 26   
 27   <Listener className="org.apache.catalina.core.JasperListener" />
 28   
 29   <Listener className="org.apache.catalina.mbeans.ServerLifecycleListener" />
 30   <Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" />
 31 
 32   
 35   <GlobalNamingResources>
 36     
 39     <Resource name="UserDatabase" auth="Container"
 40               type="org.apache.catalina.UserDatabase"
 41               description="User database that can be updated and saved"
 42               factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
 43               pathname="conf/tomcat-users.xml" />
 44   GlobalNamingResources>
 45 
 46   
 51   <Service name="Catalina">
 52   
 53     
 54     
 55     <Executor name="tomcatThreadPool" namePrefix="catalina-exec-" 
 56         maxThreads="1000" minSpareThreads="350"/>
 57     
 58     
 59     
 66     
 67     
 82     
 83     
 84     <Connector executor="tomcatThreadPool" port="8080" protocol="org.apache.coyote.http11.Http11NioProtocol" 
 85                connectionTimeout="30000" 
 86                redirectPort="8443" 
 87                enableLookups="false" 
 88                acceptCount="1000" 
 89                compression="on" 
 90                compressionMinSize="2048" 
 91                noCompressionUserAgents="gozilla, traviata" 
 92                compressableMimeType="text/html,text/xml,text/css,text/javascript,text/plain,image/gif,image/jpg"
 93                URIEncoding="utf-8" />
 94     
 95                
101     
105     
110 
111     
112     <Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />
113 
114 
115     
120 
121      
124     <Engine name="Catalina"  jvmRoute="tomcat1" defaultHost="localhost">
125 
126       
129      
130              
131 
132       <Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"
133                  channelSendOptions="6">
134 
135           <Manager className="org.apache.catalina.ha.session.BackupManager"
136                    expireSessionsOnShutdown="false"
137                    notifyListenersOnReplication="true"
138                    mapSendOptions="6"/>
139                   
144           <Channel className="org.apache.catalina.tribes.group.GroupChannel">
145             <Membership className="org.apache.catalina.tribes.membership.McastService"
146                         address="228.0.0.4"
147                         port="45564"
148                         frequency="500"
149                         dropTime="3000"/>
150             <Receiver className="org.apache.catalina.tribes.transport.nio.NioReceiver"
151                       address="auto"
152                       port="5000"
153                       selectorTimeout="100"
154                       maxThreads="6"/>
155 
156             <Sender className="org.apache.catalina.tribes.transport.ReplicationTransmitter">
157               <Transport className="org.apache.catalina.tribes.transport.nio.PooledParallelSender"/>
158             Sender>
159             <Interceptor className="org.apache.catalina.tribes.group.interceptors.TcpFailureDetector"/>
160             <Interceptor className="org.apache.catalina.tribes.group.interceptors.MessageDispatch15Interceptor"/>
161             <Interceptor className="org.apache.catalina.tribes.group.interceptors.ThroughputInterceptor"/>
162           Channel>
163 
164           <Valve className="org.apache.catalina.ha.tcp.ReplicationValve"
165                  filter=".*\.gif;.*\.js;.*\.jpg;.*\.png;.*\.htm;.*\.html;.*\.css;.*\.txt;"/>
166 
167           
174 
175           <ClusterListener className="org.apache.catalina.ha.session.ClusterSessionListener"/>
176       Cluster>
177       
178       
181       
184 
185       
189       <Realm className="org.apache.catalina.realm.UserDatabaseRealm"
190              resourceName="UserDatabase"/>
191 
192       
195       <Host name="localhost"  appBase="webapps"
196             unpackWARs="true" autoDeploy="true"
197             xmlValidation="false" xmlNamespaceAware="false">
198 
199         
201         
204 
205         
207         
211 
212       Host>
213     Engine>
214   Service>
215 Server>

                 2>web.xml(tomcat/conf)

web.xml(tomcat下的)
xml version="1.0" encoding="ISO-8859-1"?>

<web-app xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
version="2.5">





























































<servlet>
<servlet-name>defaultservlet-name>
<servlet-class>org.apache.catalina.servlets.DefaultServletservlet-class>
<init-param>
<param-name>debugparam-name>
<param-value>0param-value>
init-param>
<init-param>
<param-name>listingsparam-name>
<param-value>falseparam-value>
init-param>
<load-on-startup>1load-on-startup>
servlet>











































 












































































<servlet>
<servlet-name>jspservlet-name>
<servlet-class>org.apache.jasper.servlet.JspServletservlet-class>
<init-param>
<param-name>forkparam-name>
<param-value>falseparam-value>
init-param>
<init-param>
<param-name>xpoweredByparam-name>
<param-value>falseparam-value>
init-param>
<load-on-startup>3load-on-startup>
servlet>

































































<servlet-mapping>
<servlet-name>defaultservlet-name>
<url-pattern>/url-pattern>
servlet-mapping>



<servlet-mapping>
<servlet-name>jspservlet-name>
<url-pattern>*.jspurl-pattern>
servlet-mapping>
<servlet-mapping>
<servlet-name>jspservlet-name>
<url-pattern>*.jspxurl-pattern>
servlet-mapping>












































<session-config>
<session-timeout>30session-timeout>
session-config>







<mime-mapping>
<extension>absextension>
<mime-type>audio/x-mpegmime-type>
mime-mapping>
<mime-mapping>
<extension>aiextension>
<mime-type>application/postscriptmime-type>
mime-mapping>
<mime-mapping>
<extension>aifextension>
<mime-type>audio/x-aiffmime-type>
mime-mapping>
<mime-mapping>
<extension>aifcextension>
<mime-type>audio/x-aiffmime-type>
mime-mapping>
<mime-mapping>
<extension>aiffextension>
<mime-type>audio/x-aiffmime-type>
mime-mapping>
<mime-mapping>
<extension>aimextension>
<mime-type>application/x-aimmime-type>
mime-mapping>
<mime-mapping>
<extension>artextension>
<mime-type>image/x-jgmime-type>
mime-mapping>
<mime-mapping>
<extension>asfextension>
<mime-type>video/x-ms-asfmime-type>
mime-mapping>
<mime-mapping>
<extension>asxextension>
<mime-type>video/x-ms-asfmime-type>
mime-mapping>
<mime-mapping>
<extension>auextension>
<mime-type>audio/basicmime-type>
mime-mapping>
<mime-mapping>
<extension>aviextension>
<mime-type>video/x-msvideomime-type>
mime-mapping>
<mime-mapping>
<extension>avxextension>
<mime-type>video/x-rad-screenplaymime-type>
mime-mapping>
<mime-mapping>
<extension>bcpioextension>
<mime-type>application/x-bcpiomime-type>
mime-mapping>
<mime-mapping>
<extension>binextension>
<mime-type>application/octet-streammime-type>
mime-mapping>
<mime-mapping>
<extension>bmpextension>
<mime-type>image/bmpmime-type>
mime-mapping>
<mime-mapping>
<extension>bodyextension>
<mime-type>text/htmlmime-type>
mime-mapping>
<mime-mapping>
<extension>cdfextension>
<mime-type>application/x-cdfmime-type>
mime-mapping>
<mime-mapping>
<extension>cerextension>

<mime-type>application/x-x509-ca-certmime-type>
mime-mapping>
<mime-mapping>
<extension>classextension>
<mime-type>application/javamime-type>
mime-mapping>
<mime-mapping>
<extension>cpioextension>
<mime-type>application/x-cpiomime-type>
mime-mapping>
<mime-mapping>
<extension>cshextension>
<mime-type>application/x-cshmime-type>
mime-mapping>
<mime-mapping>
<extension>cssextension>
<mime-type>text/cssmime-type>
mime-mapping>
<mime-mapping>
<extension>dibextension>
<mime-type>image/bmpmime-type>
mime-mapping>
<mime-mapping>
<extension>docextension>
<mime-type>application/mswordmime-type>
mime-mapping>
<mime-mapping>
<extension>dtdextension>
<mime-type>application/xml-dtdmime-type>
mime-mapping>
<mime-mapping>
<extension>dvextension>
<mime-type>video/x-dvmime-type>
mime-mapping>
<mime-mapping>
<extension>dviextension>
<mime-type>application/x-dvimime-type>
mime-mapping>
<mime-mapping>
<extension>epsextension>
<mime-type>application/postscriptmime-type>
mime-mapping>
<mime-mapping>
<extension>etxextension>
<mime-type>text/x-setextmime-type>
mime-mapping>
<mime-mapping>
<extension>exeextension>
<mime-type>application/octet-streammime-type>
mime-mapping>
<mime-mapping>
<extension>gifextension>
<mime-type>image/gifmime-type>
mime-mapping>
<mime-mapping>
<extension>gtarextension>
<mime-type>application/x-gtarmime-type>
mime-mapping>
<mime-mapping>
<extension>gzextension>
<mime-type>application/x-gzipmime-type>
mime-mapping>
<mime-mapping>
<extension>hdfextension>
<mime-type>application/x-hdfmime-type>
mime-mapping>
<mime-mapping>
<extension>hqxextension>
<mime-type>application/mac-binhex40mime-type>
mime-mapping>
<mime-mapping>
<extension>htcextension>
<mime-type>text/x-componentmime-type>
mime-mapping>
<mime-mapping>
<extension>htmextension>
<mime-type>text/htmlmime-type>
mime-mapping>
<mime-mapping>
<extension>htmlextension>
<mime-type>text/htmlmime-type>
mime-mapping>
<mime-mapping>
<extension>hqxextension>
<mime-type>application/mac-binhex40mime-type>
mime-mapping>
<mime-mapping>
<extension>iefextension>
<mime-type>image/iefmime-type>
mime-mapping>
<mime-mapping>
<extension>jadextension>
<mime-type>text/vnd.sun.j2me.app-descriptormime-type>
mime-mapping>
<mime-mapping>
<extension>jarextension>
<mime-type>application/java-archivemime-type>
mime-mapping>
<mime-mapping>
<extension>javaextension>
<mime-type>text/plainmime-type>
mime-mapping>
<mime-mapping>
<extension>jnlpextension>
<mime-type>application/x-java-jnlp-filemime-type>
mime-mapping>
<mime-mapping>
<extension>jpeextension>
<mime-type>image/jpegmime-type>
mime-mapping>
<mime-mapping>
<extension>jpegextension>
<mime-type>image/jpegmime-type>
mime-mapping>
<mime-mapping>
<extension>jpgextension>
<mime-type>image/jpegmime-type>
mime-mapping>
<mime-mapping>
<extension>jsextension>
<mime-type>text/javascriptmime-type>
mime-mapping>
<mime-mapping>
<extension>jsfextension>
<mime-type>text/plainmime-type>
mime-mapping>
<mime-mapping>
<extension>jspfextension>
<mime-type>text/plainmime-type>
mime-mapping>
<mime-mapping>
<extension>karextension>
<mime-type>audio/x-midimime-type>
mime-mapping>
<mime-mapping>
<extension>latexextension>
<mime-type>application/x-latexmime-type>
mime-mapping>
<mime-mapping>
<extension>m3uextension>
<mime-type>audio/x-mpegurlmime-type>
mime-mapping>
<mime-mapping>
<extension>macextension>
<mime-type>image/x-macpaintmime-type>
mime-mapping>
<mime-mapping>
<extension>manextension>
<mime-type>application/x-troff-manmime-type>
mime-mapping>
<mime-mapping>
<extension>mathmlextension>
<mime-type>application/mathml+xmlmime-type> 
mime-mapping>
<mime-mapping>
<extension>meextension>
<mime-type>application/x-troff-memime-type>
mime-mapping>
<mime-mapping>
<extension>midextension>
<mime-type>audio/x-midimime-type>
mime-mapping>
<mime-mapping>
<extension>midiextension>

<mime-type>audio/x-midimime-type>
mime-mapping>
<mime-mapping>
<extension>mifextension>
<mime-type>application/x-mifmime-type>
mime-mapping>
<mime-mapping>
<extension>movextension>
<mime-type>video/quicktimemime-type>
mime-mapping>
<mime-mapping>
<extension>movieextension>
<mime-type>video/x-sgi-moviemime-type>
mime-mapping>
<mime-mapping>
<extension>mp1extension>
<mime-type>audio/x-mpegmime-type>
mime-mapping>
<mime-mapping>
<extension>mp2extension>
<mime-type>audio/x-mpegmime-type>
mime-mapping>
<mime-mapping>
<extension>mp3extension>
<mime-type>audio/x-mpegmime-type>
mime-mapping>
<mime-mapping>
<extension>mp4extension>
<mime-type>video/mp4mime-type>
mime-mapping>
<mime-mapping>
<extension>mpaextension>
<mime-type>audio/x-mpegmime-type>
mime-mapping>
<mime-mapping>
<extension>mpeextension>
<mime-type>video/mpegmime-type>
mime-mapping>
<mime-mapping>
<extension>mpegextension>
<mime-type>video/mpegmime-type>
mime-mapping>
<mime-mapping>
<extension>mpegaextension>
<mime-type>audio/x-mpegmime-type>
mime-mapping>
<mime-mapping>
<extension>mpgextension>
<mime-type>video/mpegmime-type>
mime-mapping>
<mime-mapping>
<extension>mpv2extension>
<mime-type>video/mpeg2mime-type>
mime-mapping>
<mime-mapping>
<extension>msextension>
<mime-type>application/x-wais-sourcemime-type>
mime-mapping>
<mime-mapping>
<extension>ncextension>
<mime-type>application/x-netcdfmime-type>
mime-mapping>
<mime-mapping>
<extension>odaextension>
<mime-type>application/odamime-type>
mime-mapping>
<mime-mapping>

<extension>odbextension>
<mime-type>application/vnd.oasis.opendocument.databasemime-type>
mime-mapping>
<mime-mapping>

<extension>odcextension>
<mime-type>application/vnd.oasis.opendocument.chartmime-type>
mime-mapping>
<mime-mapping>

<extension>odfextension>
<mime-type>application/vnd.oasis.opendocument.formulamime-type>
mime-mapping>
<mime-mapping>

<extension>odgextension>
<mime-type>application/vnd.oasis.opendocument.graphicsmime-type>
mime-mapping>
<mime-mapping>

<extension>odiextension>
<mime-type>application/vnd.oasis.opendocument.imagemime-type>
mime-mapping>
<mime-mapping>

<extension>odmextension>
<mime-type>application/vnd.oasis.opendocument.text-mastermime-type>
mime-mapping>
<mime-mapping>

<extension>odpextension>
<mime-type>application/vnd.oasis.opendocument.presentationmime-type>
mime-mapping>
<mime-mapping>

<extension>odsextension>
<mime-type>application/vnd.oasis.opendocument.spreadsheetmime-type>
mime-mapping>
<mime-mapping>

<extension>odtextension>
<mime-type>application/vnd.oasis.opendocument.textmime-type>
mime-mapping>
<mime-mapping>
<extension>oggextension>
<mime-type>application/oggmime-type>
mime-mapping>
<mime-mapping>

<extension>otg extension>
<mime-type>application/vnd.oasis.opendocument.graphics-templatemime-type>
mime-mapping>
<mime-mapping>

<extension>othextension>
<mime-type>application/vnd.oasis.opendocument.text-webmime-type>
mime-mapping>
<mime-mapping>

<extension>otpextension>
<mime-type>application/vnd.oasis.opendocument.presentation-templatemime-type>
mime-mapping>
<mime-mapping>

<extension>otsextension>
<mime-type>application/vnd.oasis.opendocument.spreadsheet-template mime-type>
mime-mapping>
<mime-mapping>

<extension>ottextension>
<mime-type>application/vnd.oasis.opendocument.text-templatemime-type>
mime-mapping>
<mime-mapping>
<extension>pbmextension>
<mime-type>image/x-portable-bitmapmime-type>
mime-mapping>
<mime-mapping>
<extension>pctextension>
<mime-type>image/pictmime-type>
mime-mapping>
<mime-mapping>
<extension>pdfextension>
<mime-type>application/pdfmime-type>
mime-mapping>
<mime-mapping>
<extension>pgmextension>
<mime-type>image/x-portable-graymapmime-type>
mime-mapping>
<mime-mapping>
<extension>picextension>
<mime-type>image/pictmime-type>
mime-mapping>
<mime-mapping>
<extension>pictextension>
<mime-type>image/pictmime-type>
mime-mapping>
<mime-mapping>
<extension>plsextension>
<mime-type>audio/x-scplsmime-type>
mime-mapping>
<mime-mapping>
<extension>pngextension>
<mime-type>image/pngmime-type>
mime-mapping>
<mime-mapping>
<extension>pnmextension>
<mime-type>image/x-portable-anymapmime-type>
mime-mapping>
<mime-mapping>
<extension>pntextension>
<mime-type>image/x-macpaintmime-type>
mime-mapping>
<mime-mapping>
<extension>ppmextension>
<mime-type>image/x-portable-pixmapmime-type>
mime-mapping>
<mime-mapping>
<extension>pptextension>
<mime-type>application/powerpointmime-type>
mime-mapping>
<mime-mapping>
<extension>psextension>
<mime-type>application/postscriptmime-type>
mime-mapping>
<mime-mapping>
<extension>psdextension>
<mime-type>image/x-photoshopmime-type>
mime-mapping>
<mime-mapping>
<extension>qtextension>
<mime-type>video/quicktimemime-type>
mime-mapping>
<mime-mapping>
<extension>qtiextension>
<mime-type>image/x-quicktimemime-type>
mime-mapping>
<mime-mapping>
<extension>qtifextension>
<mime-type>image/x-quicktimemime-type>
mime-mapping>
<mime-mapping>
<extension>rasextension>
<mime-type>image/x-cmu-rastermime-type>
mime-mapping>
<mime-mapping>
<extension>rdfextension>
<mime-type>application/rdf+xmlmime-type>
mime-mapping>
<mime-mapping>
<extension>rgbextension>
<mime-type>image/x-rgbmime-type>
mime-mapping>
<mime-mapping>
<extension>rmextension>
<mime-type>application/vnd.rn-realmediamime-type>
mime-mapping>
<mime-mapping>
<extension>roffextension>
<mime-type>application/x-troffmime-type>
mime-mapping>
<mime-mapping>
<extension>rtfextension>
<mime-type>application/rtfmime-type>
mime-mapping>
<mime-mapping>
<extension>rtxextension>
<mime-type>text/richtextmime-type>
mime-mapping>
<mime-mapping>
<extension>shextension>
<mime-type>application/x-shmime-type>
mime-mapping>
<mime-mapping>
<extension>sharextension>
<mime-type>application/x-sharmime-type>
mime-mapping>

<mime-mapping>
<extension>smfextension>
<mime-type>audio/x-midimime-type>
mime-mapping>
<mime-mapping>
<extension>sitextension>
<mime-type>application/x-stuffitmime-type>
mime-mapping>
<mime-mapping>
<extension>sndextension>
<mime-type>audio/basicmime-type>
mime-mapping>
<mime-mapping>
<extension>srcextension>
<mime-type>application/x-wais-sourcemime-type>
mime-mapping>
<mime-mapping>
<extension>sv4cpioextension>
<mime-type>application/x-sv4cpiomime-type>
mime-mapping>
<mime-mapping>
<extension>sv4crcextension>
<mime-type>application/x-sv4crcmime-type>
mime-mapping>
<mime-mapping>
<extension>swfextension>
<mime-type>application/x-shockwave-flashmime-type>
mime-mapping>
<mime-mapping>
<extension>textension>
<mime-type>application/x-troffmime-type>
mime-mapping>
<mime-mapping>
<extension>tarextension>
<mime-type>application/x-tarmime-type>
mime-mapping>
<mime-mapping>
<extension>tclextension>
<mime-type>application/x-tclmime-type>
mime-mapping>
<mime-mapping>
<extension>texextension>
<mime-type>application/x-texmime-type>
mime-mapping>
<mime-mapping>
<extension>texiextension>
<mime-type>application/x-texinfomime-type>
mime-mapping>
<mime-mapping>
<extension>texinfoextension>
<mime-type>application/x-texinfomime-type>
mime-mapping>
<mime-mapping>
<extension>tifextension>
<mime-type>image/tiffmime-type>
mime-mapping>
<mime-mapping>
<extension>tiffextension>
<mime-type>image/tiffmime-type>
mime-mapping>
<mime-mapping>
<extension>trextension>
<mime-type>application/x-troffmime-type>
mime-mapping>
<mime-mapping>
<extension>tsvextension>
<mime-type>text/tab-separated-valuesmime-type>
mime-mapping>
<mime-mapping>
<extension>txtextension>
<mime-type>text/plainmime-type>
mime-mapping>
<mime-mapping>
<extension>ulwextension>
<mime-type>audio/basicmime-type>
mime-mapping>
<mime-mapping>
<extension>ustarextension>
<mime-type>application/x-ustarmime-type>
mime-mapping>
<mime-mapping>
<extension>vxmlextension>
<mime-type>application/voicexml+xmlmime-type>
mime-mapping>
<mime-mapping>
<extension>xbmextension>
<mime-type>image/x-xbitmapmime-type>
mime-mapping>
<mime-mapping>
<extension>xhtextension>
<mime-type>application/xhtml+xmlmime-type>
mime-mapping>
<mime-mapping>
<extension>xhtmlextension>
<mime-type>application/xhtml+xmlmime-type>
mime-mapping>
<mime-mapping>
<extension>xmlextension>
<mime-type>application/xmlmime-type>
mime-mapping>
<mime-mapping>
<extension>xpmextension>
<mime-type>image/x-xpixmapmime-type>
mime-mapping>
<mime-mapping>
<extension>xslextension>
<mime-type>application/xmlmime-type>
mime-mapping>
<mime-mapping>
<extension>xsltextension>
<mime-type>application/xslt+xmlmime-type>
mime-mapping>
<mime-mapping>
<extension>xulextension>
<mime-type>application/vnd.mozilla.xul+xmlmime-type>
mime-mapping>
<mime-mapping>
<extension>xwdextension>
<mime-type>image/x-xwindowdumpmime-type>
mime-mapping>
<mime-mapping>
<extension>wavextension>
<mime-type>audio/x-wavmime-type>
mime-mapping>
<mime-mapping>
<extension>svgextension>
<mime-type>image/svg+xmlmime-type>
mime-mapping>
<mime-mapping>
<extension>svgzextension>
<mime-type>image/svg+xmlmime-type>
mime-mapping>
<mime-mapping>
<extension>vsdextension>
<mime-type>application/x-visiomime-type>
mime-mapping>
<mime-mapping>

<extension>wbmpextension>
<mime-type>image/vnd.wap.wbmpmime-type>
mime-mapping>
<mime-mapping>

<extension>wmlextension>
<mime-type>text/vnd.wap.wmlmime-type>
mime-mapping>
<mime-mapping>

<extension>wmlcextension>
<mime-type>application/vnd.wap.wmlcmime-type>
mime-mapping>
<mime-mapping>

<extension>wmlsextension>
<mime-type>text/vnd.wap.wmlscriptmime-type>
mime-mapping>
<mime-mapping>

<extension>wmlscriptcextension>
<mime-type>application/vnd.wap.wmlscriptcmime-type>
mime-mapping>
<mime-mapping>
<extension>wmvextension>
<mime-type>video/x-ms-wmvmime-type>
mime-mapping>
<mime-mapping>
<extension>wrlextension>
<mime-type>x-world/x-vrmlmime-type>
mime-mapping>
<mime-mapping>
<extension>wspolicyextension>
<mime-type>application/wspolicy+xmlmime-type>
mime-mapping>
<mime-mapping>
<extension>Zextension>
<mime-type>application/x-compressmime-type>
mime-mapping>
<mime-mapping>
<extension>zextension>
<mime-type>application/x-compressmime-type>
mime-mapping>
<mime-mapping>
<extension>zipextension>
<mime-type>application/zipmime-type>
mime-mapping>
<mime-mapping>
<extension>xlsextension>
<mime-type>application/vnd.ms-excelmime-type>
mime-mapping>
<mime-mapping>
<extension>docextension>
<mime-type>application/vnd.ms-wordmime-type>
mime-mapping>
<mime-mapping>
<extension>pptextension>
<mime-type>application/vnd.ms-powerpointmime-type>
mime-mapping>











<welcome-file-list>
<welcome-file>index.htmlwelcome-file>
<welcome-file>index.htmwelcome-file>
<welcome-file>index.jspwelcome-file>
welcome-file-list>
web-app>

         3>catalina.bat(tomcat/bin)这个文件只是添加了一个对tomcat内存优化配置的更改(前两行)

catalina.bat
  1 set CATALINA_OPTS=-Xms256m -Xmx256m 
  2 set JAVA_OPTS=-Xms256m -Xmx256m
  3 @echo off
  4 rem Licensed to the Apache Software Foundation (ASF) under one or more
  5 rem contributor license agreements.  See the NOTICE file distributed with
  6 rem this work for additional information regarding copyright ownership.
  7 rem The ASF licenses this file to You under the Apache License, Version 2.0
  8 rem (the "License"); you may not use this file except in compliance with
  9 rem the License.  You may obtain a copy of the License at
 10 rem
 11 rem     http://www.apache.org/licenses/LICENSE-2.0
 12 rem
 13 rem Unless required by applicable law or agreed to in writing, software
 14 rem distributed under the License is distributed on an "AS IS" BASIS,
 15 rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 16 rem See the License for the specific language governing permissions and
 17 rem limitations under the License.
 18 
 19 if "%OS%" == "Windows_NT" setlocal
 20 rem ---------------------------------------------------------------------------
 21 rem Start/Stop Script for the CATALINA Server
 22 rem
 23 rem Environment Variable Prequisites
 24 rem
 25 rem   CATALINA_HOME   May point at your Catalina "build" directory.
 26 rem
 27 rem   CATALINA_BASE   (Optional) Base directory for resolving dynamic portions
 28 rem                   of a Catalina installation.  If not present, resolves to
 29 rem                   the same directory that CATALINA_HOME points to.
 30 rem
 31 rem   CATALINA_OPTS   (Optional) Java runtime options used when the "start",
 32 rem                   or "run" command is executed.
 33 rem
 34 rem   CATALINA_TMPDIR (Optional) Directory path location of temporary directory
 35 rem                   the JVM should use (java.io.tmpdir).  Defaults to
 36 rem                   %CATALINA_BASE%\temp.
 37 rem
 38 rem   JAVA_HOME       Must point at your Java Development Kit installation.
 39 rem                   Required to run the with the "debug" argument.
 40 rem
 41 rem   JRE_HOME        Must point at your Java Runtime installation.
 42 rem                   Defaults to JAVA_HOME if empty.
 43 rem
 44 rem   JAVA_OPTS       (Optional) Java runtime options used when the "start",
 45 rem                   "stop", or "run" command is executed.
 46 rem
 47 rem   JSSE_HOME       (Optional) May point at your Java Secure Sockets Extension
 48 rem                   (JSSE) installation, whose JAR files will be added to the
 49 rem                   system class path used to start Tomcat.
 50 rem
 51 rem   JPDA_TRANSPORT  (Optional) JPDA transport used when the "jpda start"
 52 rem                   command is executed. The default is "dt_shmem".
 53 rem
 54 rem   JPDA_ADDRESS    (Optional) Java runtime options used when the "jpda start"
 55 rem                   command is executed. The default is "jdbconn".
 56 rem
 57 rem   JPDA_SUSPEND    (Optional) Java runtime options used when the "jpda start"
 58 rem                   command is executed. Specifies whether JVM should suspend
 59 rem                   execution immediately after startup. Default is "n".
 60 rem
 61 rem   JPDA_OPTS       (Optional) Java runtime options used when the "jpda start"
 62 rem                   command is executed. If used, JPDA_TRANSPORT, JPDA_ADDRESS,
 63 rem                   and JPDA_SUSPEND are ignored. Thus, all required jpda
 64 rem                   options MUST be specified. The default is:
 65 rem
 66 rem                   -Xdebug -Xrunjdwp:transport=%JPDA_TRANSPORT%,
 67 rem                       address=%JPDA_ADDRESS%,server=y,suspend=%JPDA_SUSPEND%
 68 rem
 69 rem $Id: catalina.bat 656834 2008-05-15 21:04:04Z markt $
 70 rem ---------------------------------------------------------------------------
 71 
 72 rem Guess CATALINA_HOME if not defined
 73 set CURRENT_DIR=%cd%
 74 if not "%CATALINA_HOME%" == "" goto gotHome
 75 set CATALINA_HOME=%CURRENT_DIR%
 76 if exist "%CATALINA_HOME%\bin\catalina.bat" goto okHome
 77 cd ..
 78 set CATALINA_HOME=%cd%
 79 cd %CURRENT_DIR%
 80 :gotHome
 81 if exist "%CATALINA_HOME%\bin\catalina.bat" goto okHome
 82 echo The CATALINA_HOME environment variable is not defined correctly
 83 echo This environment variable is needed to run this program
 84 goto end
 85 :okHome
 86 
 87 rem Get standard environment variables
 88 if "%CATALINA_BASE%" == "" goto gotSetenvHome
 89 if exist "%CATALINA_BASE%\bin\setenv.bat" call "%CATALINA_BASE%\bin\setenv.bat"
 90 goto gotSetenvBase
 91 :gotSetenvHome
 92 if exist "%CATALINA_HOME%\bin\setenv.bat" call "%CATALINA_HOME%\bin\setenv.bat"
 93 :gotSetenvBase
 94 
 95 rem Get standard Java environment variables
 96 if exist "%CATALINA_HOME%\bin\setclasspath.bat" goto okSetclasspath
 97 echo Cannot find %CATALINA_HOME%\bin\setclasspath.bat
 98 echo This file is needed to run this program
 99 goto end
100 :okSetclasspath
101 set BASEDIR=%CATALINA_HOME%
102 call "%CATALINA_HOME%\bin\setclasspath.bat" %1
103 if errorlevel 1 goto end
104 
105 rem Add on extra jar files to CLASSPATH
106 if "%JSSE_HOME%" == "" goto noJsse
107 set CLASSPATH=%CLASSPATH%;%JSSE_HOME%\lib\jcert.jar;%JSSE_HOME%\lib\jnet.jar;%JSSE_HOME%\lib\jsse.jar
108 :noJsse
109 set CLASSPATH=%CLASSPATH%;%CATALINA_HOME%\bin\bootstrap.jar
110 
111 if not "%CATALINA_BASE%" == "" goto gotBase
112 set CATALINA_BASE=%CATALINA_HOME%
113 :gotBase
114 
115 if not "%CATALINA_TMPDIR%" == "" goto gotTmpdir
116 set CATALINA_TMPDIR=%CATALINA_BASE%\temp
117 :gotTmpdir
118 
119 if not exist "%CATALINA_BASE%\conf\logging.properties" goto noJuli
120 set JAVA_OPTS=%JAVA_OPTS% -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djava.util.logging.config.file="%CATALINA_BASE%\conf\logging.properties"
121 :noJuli
122 
123 rem ----- Execute The Requested Command ---------------------------------------
124 
125 echo Using CATALINA_BASE:   %CATALINA_BASE%
126 echo Using CATALINA_HOME:   %CATALINA_HOME%
127 echo Using CATALINA_TMPDIR: %CATALINA_TMPDIR%
128 if ""%1"" == ""debug"" goto use_jdk
129 echo Using JRE_HOME:        %JRE_HOME%
130 goto java_dir_displayed
131 :use_jdk
132 echo Using JAVA_HOME:       %JAVA_HOME%
133 :java_dir_displayed
134 
135 set _EXECJAVA=%_RUNJAVA%
136 set MAINCLASS=org.apache.catalina.startup.Bootstrap
137 set ACTION=start
138 set SECURITY_POLICY_FILE=
139 set DEBUG_OPTS=
140 set JPDA=
141 
142 if not ""%1"" == ""jpda"" goto noJpda
143 set JPDA=jpda
144 if not "%JPDA_TRANSPORT%" == "" goto gotJpdaTransport
145 set JPDA_TRANSPORT=dt_shmem
146 :gotJpdaTransport
147 if not "%JPDA_ADDRESS%" == "" goto gotJpdaAddress
148 set JPDA_ADDRESS=jdbconn
149 :gotJpdaAddress
150 if not "%JPDA_SUSPEND%" == "" goto gotJpdaSuspend
151 set JPDA_SUSPEND=n
152 :gotJpdaSuspend
153 if not "%JPDA_OPTS%" == "" goto gotJpdaOpts
154 set JPDA_OPTS=-agentlib:jdwp=transport=%JPDA_TRANSPORT%,address=%JPDA_ADDRESS%,server=y,suspend=%JPDA_SUSPEND%
155 :gotJpdaOpts
156 shift
157 :noJpda
158 
159 if ""%1"" == ""debug"" goto doDebug
160 if ""%1"" == ""run"" goto doRun
161 if ""%1"" == ""start"" goto doStart
162 if ""%1"" == ""stop"" goto doStop
163 if ""%1"" == ""version"" goto doVersion
164 
165 echo Usage:  catalina ( commands ... )
166 echo commands:
167 echo   debug             Start Catalina in a debugger
168 echo   debug -security   Debug Catalina with a security manager
169 echo   jpda start        Start Catalina under JPDA debugger
170 echo   run               Start Catalina in the current window
171 echo   run -security     Start in the current window with security manager
172 echo   start             Start Catalina in a separate window
173 echo   start -security   Start in a separate window with security manager
174 echo   stop              Stop Catalina
175 echo   version           What version of tomcat are you running?
176 goto end
177 
178 :doDebug
179 shift
180 set _EXECJAVA=%_RUNJDB%
181 set DEBUG_OPTS=-sourcepath "%CATALINA_HOME%\..\..\java"
182 if not ""%1"" == ""-security"" goto execCmd
183 shift
184 echo Using Security Manager
185 set SECURITY_POLICY_FILE=%CATALINA_BASE%\conf\catalina.policy
186 goto execCmd
187 
188 :doRun
189 shift
190 if not ""%1"" == ""-security"" goto execCmd
191 shift
192 echo Using Security Manager
193 set SECURITY_POLICY_FILE=%CATALINA_BASE%\conf\catalina.policy
194 goto execCmd
195 
196 :doStart
197 shift
198 if not "%OS%" == "Windows_NT" goto noTitle
199 set _EXECJAVA=start "Tomcat" %_RUNJAVA%
200 goto gotTitle
201 :noTitle
202 set _EXECJAVA=start %_RUNJAVA%
203 :gotTitle
204 if not ""%1"" == ""-security"" goto execCmd
205 shift
206 echo Using Security Manager
207 set SECURITY_POLICY_FILE=%CATALINA_BASE%\conf\catalina.policy
208 goto execCmd
209 
210 :doStop
211 shift
212 set ACTION=stop
213 set CATALINA_OPTS=
214 goto execCmd
215 
216 :doVersion
217 %_EXECJAVA% -classpath "%CATALINA_HOME%\lib\catalina.jar" org.apache.catalina.util.ServerInfo
218 goto end
219 
220 
221 :execCmd
222 rem Get remaining unshifted command line arguments and save them in the
223 set CMD_LINE_ARGS=
224 :setArgs
225 if ""%1""=="""" goto doneSetArgs
226 set CMD_LINE_ARGS=%CMD_LINE_ARGS% %1
227 shift
228 goto setArgs
229 :doneSetArgs
230 
231 rem Execute Java with the applicable properties
232 if not "%JPDA%" == "" goto doJpda
233 if not "%SECURITY_POLICY_FILE%" == "" goto doSecurity
234 %_EXECJAVA% %JAVA_OPTS% %CATALINA_OPTS% %DEBUG_OPTS% -Djava.endorsed.dirs="%JAVA_ENDORSED_DIRS%" -classpath "%CLASSPATH%" -Dcatalina.base="%CATALINA_BASE%" -Dcatalina.home="%CATALINA_HOME%" -Djava.io.tmpdir="%CATALINA_TMPDIR%" %MAINCLASS% %CMD_LINE_ARGS% %ACTION%
235 goto end
236 :doSecurity
237 %_EXECJAVA% %JAVA_OPTS% %CATALINA_OPTS% %DEBUG_OPTS% -Djava.endorsed.dirs="%JAVA_ENDORSED_DIRS%" -classpath "%CLASSPATH%" -Djava.security.manager -Djava.security.policy=="%SECURITY_POLICY_FILE%" -Dcatalina.base="%CATALINA_BASE%" -Dcatalina.home="%CATALINA_HOME%" -Djava.io.tmpdir="%CATALINA_TMPDIR%" %MAINCLASS% %CMD_LINE_ARGS% %ACTION%
238 goto end
239 :doJpda
240 if not "%SECURITY_POLICY_FILE%" == "" goto doSecurityJpda
241 %_EXECJAVA% %JAVA_OPTS% %CATALINA_OPTS% %JPDA_OPTS% %DEBUG_OPTS% -Djava.endorsed.dirs="%JAVA_ENDORSED_DIRS%" -classpath "%CLASSPATH%" -Dcatalina.base="%CATALINA_BASE%" -Dcatalina.home="%CATALINA_HOME%" -Djava.io.tmpdir="%CATALINA_TMPDIR%" %MAINCLASS% %CMD_LINE_ARGS% %ACTION%
242 goto end
243 :doSecurityJpda
244 %_EXECJAVA% %JAVA_OPTS% %CATALINA_OPTS% %JPDA_OPTS% %DEBUG_OPTS% -Djava.endorsed.dirs="%JAVA_ENDORSED_DIRS%" -classpath "%CLASSPATH%" -Djava.security.manager -Djava.security.policy=="%SECURITY_POLICY_FILE%" -Dcatalina.base="%CATALINA_BASE%" -Dcatalina.home="%CATALINA_HOME%" -Djava.io.tmpdir="%CATALINA_TMPDIR%" %MAINCLASS% %CMD_LINE_ARGS% %ACTION%
245 goto end
246 
247 :end

                以上最后的两个文件及前面有些配置使用该优化tomcat和jdk的,配置完成后的各个配置文件,具体操作步骤如下:

  (1)负载均衡 

    找到Apache安装目录下conf目录中的httpd.conf文件。
    在文件最后添加一句:include "D:\webserver\Apache Group\Apache2\conf\mod_jk.conf"(具体路径是你放置的位置而定)
    接着在conf目录中新建文件mod_jk.conf并添加下面的内容:
      #加载mod_jk Module
      LoadModule jk_module modules/mod_jk-apache-2.0.59.so
      #指定 workers.properties文件路径
      JkWorkersFile conf/workers.properties
      #指定哪些请求交给tomcat处理,"controller"为在workers.propertise里指定的负载分配控制器名
      JkMount /*.jsp controller  

    在conf目录下新建workers.properties文件并添加如下内容:
    #server
    worker.list = controller
    #========tomcat1========
    worker.tomcat1.port=11009
    worker.tomcat1.host=localhost
    worker.tomcat1.type=ajp13
    worker.tomcat1.lbfactor = 1
    #========tomcat2========
    worker.tomcat2.port=12009
    worker.tomcat2.host=localhost
    worker.tomcat2.type=ajp13
    worker.tomcat2.lbfactor = 1
    #(解释一下AJP13是 Apache JServ Protocol version 1.3)
    #========controller,负载均衡控制器========
    worker.controller.type=lb
    worker.controller.balanced_workers=tomcat1,tomcat2
    worker.controller.sticky_session=1

    将mod_jk-apache-2.0.59.so 复制到Apache的modules目录中。

    接下来配置2个Tomcat
    打开tomcat1\conf\ server.xml
    将Server port 改为11005:
    将Define Connector port改为11080:    将AJP13 Connector port改为11009:

    打开tomcat2\conf\server.xml
    将Server port 改为12005:
    将Define Connector port改为12080:    将AJP13 Connector port改为12009:

    好了,现在建立一个测试程序
    分别在两个Tomcat的webapps中建立test目录,并新建test.jsp文件,内容如下:
    <%
      System.out.println("test");
    %>

    启动apache, tomcat1, tomcat2
    访问http://localhost:8080/test/test.jsp (或者 http://localhost/test/test.jsp)不断刷新页面,看不到交替输出"test",你需要换两台机器或者开两个浏览器(即两个会话)这样可以在两个Tomcat的控制台中看到,交替输出"test", 这样就实现了负载均衡,由于没有开启session共享所以一次会话集中到了一个toamcat上多个会话会分配道不同的tomact中。

   (2)集群配置

    集群除了负载均衡,另一个主要功能是Session Replication。
    打开tomcat1\conf\ server.xml将部分的注释去掉。
    再打开tomcat2\conf\ server.xml将部分的注释也去掉,并将的tcpListenPort的值改为4002。以避免与Tomcat1冲突。

    分别在2个tomcat的webapps\test中新建WEB-INF目录,在WEB-INF中添加web.xml内容如下:
      
        TomcatDemo
        
      

    主要是添加,distributable元素用来告诉servlet容器,程序将部署在分布式Web容器中。
    重新启动tomcat1和tomcat2. 访问http://localhost:8080/test/test2.jsp (或http://localhost/test/test2.jsp)
    随意添加key-value, 可以看到两个tomcat交替显示session中的值,各个tomcat的session是同步的。

    再来修改tomcat1\conf\server.xml,找到为其添加jvmRoute属性,值为apache的conf\workers.properties中配置的tomcat名字。
    同样修改tomcat2\conf\server.xml的相同部分jvmRoute是tomcat路由标示,由此区分两台tomcat主机。一次会话,就有一个sessionID,这个sessionID后面会跟上jvmRoute设置的值,这样一次会话,就只会让一个tomcat处理。
    重新启动tomcat1, tomcat2
    访问http://localhost:8080/test/test2.jsp 可以看到session.getId()的值在原session id后面多了jvmRoute的值。ID 46A5843FF4A1E0A84338225AC02F6430.tomcat1
    随意添加key-value,可以看到session信息只在tomcat1中输出。
    再打开一个浏览器,并访问http://localhost:8080/test/test2.jsp 其session id可能变为ID 11478E5BE5FE388E4845205B4133A30F.tomcat2
    其值也只会在tomcat2中输出。
    现在把tomcat1关闭,再次刷新访问tomcat1的那个浏览器,可以看到session信息输出到了tomcat2的控制台中,并且session信息仍然保留着。

  2. Apache 2.2以后集成了mod_jk功能,相对于1.3版本,不需要再进行繁琐的worker.properties配置,配置过程大幅简化。

       (1)apache的配置

            a. 首先,在Apache安装目录下找到conf/httpd.conf文件,以文本编辑器打开。去掉以下文本前的注释符(#)以便让Apache在启动时自动加载代理(proxy)模块。

LoadModule proxy_module modules/mod_proxy.so 
LoadModule proxy_ajp_module modules/mod_proxy_ajp.so 
LoadModule proxy_balancer_module modules/mod_proxy_balancer.so 
LoadModule proxy_connect_module modules/mod_proxy_connect.so 
LoadModule proxy_ftp_module modules/mod_proxy_ftp.so 
LoadModule proxy_http_module modules/mod_proxy_http.so

 

          b. 向下拉动文档找到节点,在DirectoryIndex index.html后加上index.jsp,这一步只是为了待会配置完tomcat后能看到小猫首页,可以不做。
        c. 继续下拉文档找到"Include conf/extra/httpd-vhosts.conf",去掉前面的注释符。
          然后找到conf/extra/httpd-vhosts.conf文件,用文本编辑器打开conf/extra/httpd-vhosts.conf,配置虚拟站点,在最下面加上

> 
  ServerAdmin 管理员邮箱 
  ServerName localhost(没有可用IP地址代替) 
  ServerAlias localhost 
  ProxyPass / balancer://cluster/ stickysession=jsessionid nofailover=On 
  ProxyPassReverse / balancer://cluster/ 
  ErrorLog "logs/lbtest-error.log" 
  CustomLog "logs/lbtest-access.log" common 

     d. 这里balancer://是告诉Apache需要进行负载均衡的代理,后面的cluster是集群名,可以随意取,两个日志引擎ErrorLog负责记录错误,CustomLog负责记录所有的http访问以及返回状态,日志名可以自己取,笔者取为lbtest。httpd-vhosts.conf配置完毕,回到httpd.conf,在文档最下面加上    

ProxyRequests Off 
 
 BalancerMember ajp://127.0.0.1:8009 loadfactor=1 route=jvm1 
 BalancerMember ajp://127.0.0.1:9009 loadfactor=1 route=jvm2 
 

     ProxyRequests Off 是告诉Apache需要使用反向代理(利用Apache进行负载均衡必须使用反向代理,用于配置工作在tomcat集群中的所有节点,这里的"cluster"必须与上面的集群名保持一致。
     Apache通过ajp协议与tomcat进行通信,ip地址和端口唯一确定了tomcat节点和配置的ajp接受端口。loadfactor是负载因子,Apache会按负载因子的比例向后端tomcat节点转发请求,负载因子越大,对应的tomcat服务器就会处理越多的请求,如两个tomcat都是1,Apache就按1:1的比例转发,如果是2和1就按2:1的比例转发。route参数对应后续tomcat配置中的引擎路径(jvmRoute)。
     重启Apache服务,如果此时访问http://localhost/将会返回503错误,打开刚才配置的错误日志logs/lbtest-error.log,可以看到错误原因是因为后台服务器没有响应,因为此时tomcat尚未配置和启动。

   (2)tomcat配置

           如果仅仅为了配置一个可用的集群,Tomcat的配置将会非常简单。分别打开t1和t2的server.xml配置文件,对于t1,尽量采用默认的设置,而对t2作较大改动以避免与t1冲突。如果t2和t1不在同一台服务器上运行,对于端口就不需做改动
      a. 首先是配置关闭端口,找到,t1不变,把t2改为9005。
      b. 下面配置Connector的端口,找到non-SSL HTTP/1.1 Connector,即tomcat单独工作时的默认Connector,保留t1默认配置,在8080端口侦听,而把t2设置为在9080端口侦听。
      c. 往下找到AJP 1.3 Connector,,这是tomcat接收从Apache过来的ajp连接请求时使用的端口,保留t1默认设置,把t2端口改为9009。注意,这里的端口对应Apache httpd.conf中BalancerMember中配置的ajp连接端口
      d. 继续向下配置引擎,找到,去掉这段或改为注释,把上方紧挨的注释符去掉,对于t2,去掉注释符并把jvm1改为jvm2。这里的jvmRoute对应Apache httpd.conf中BalancerMember中配置的route参数
      e. 向下找到,打开注释,这里的配置是为了可以在集群中的所有tomcat节点间共享会话(Session)。如果仅仅为了获得一个可用的tomcat集群,Cluster只需要这么配置就可以了,对于更多的Cluster配置笔者将另文解释
       server.xml的配置修改完毕,下一步需要对具体的应用进行配置。在webapps目录下新建test目录,在test目录下新建test.jsp文件,代码如下:

test.jsp
 1 ?<%@ page contentType="text/html; charset=GBK" %>  
 2 <%@ page import="java.util.*" %>  
 3 <html>
 4     <head>
 5         <title>Cluster App Testtitle>
 6     head>  
 7 <body>
 8   Server Info:   
 9     <%  out.println(request.getLocalAddr() + " : " + request.getLocalPort()+"
");%> 10 <% out.println("
ID
" + session.getId()+"
"); 11 String dataName = request.getParameter("dataName"); 12 if (dataName != null && dataName.length() > 0) { 13 String dataValue = request.getParameter("dataValue"); 14 session.setAttribute(dataName, dataValue); 15 } 16 out.print("Session 列表"); 17 Enumeration e = session.getAttributeNames(); 18 while (e.hasMoreElements()) { 19 String name = (String)e.nextElement(); 20 String value = session.getAttribute(name).toString(); 21 out.println( name + " = " + value+"
"); 22 System.out.println( name + " = " + value); 23 } 24 %> 25 <form action="test.jsp" method="POST"> 26 名称:<input type=text size=20 name="dataName"><br/> 27 值:<input type=text size=20 name="dataValue"><br/> 28 <input type=submit/> 29 form> 30 body> 31 html>

         f. 在test目录下继续新建WEB-INF目录和web.xml,在节点下加入,这一步非常重要,是为了通知tomcat服务器,当前应用需要在集群中的所有节点间实现Session共享。如果tomcat中的所有应用都需要Session共享,也可以把conf/context.xml中的改为,这样就不需对所有应用的web.xml再进行单独配置(修改需要Session复制的应用中WEB-INF/web.xml文件,在文件中的标签中增加:在应用的web.xml中增加上述配置后,就表示该应用需要进行Session复制)。 

      启动t1,待t1启动完成后再启动t2。再次访问http://localhost,可以看到小猫页面。访问http://localhost/test/test.jsp。可以看到包括服务器地址,端口,sessionid等信息在内的页面。

      注意这里的sessionid,与平常的sessionid相比多了小数点和后面的部分,这里的jvm1即处理当前请求tomcat服务器的jvmRoute,通过这里可以知道是集群中的哪一个服务器处理了当前请求。在文本框中输入名称和值,点击按钮,信息就保存到了Session中,并且显示到页面上。不断点击按钮,可以发现输入的信息并未丢失,而且sessionid小数点之前的部分保持不变,而小数点后面的字符不停的变化,表明是由不同的tomcat服务器处理了这些请求。这样就实现了负载均衡,并且集群中的不同节点间可以实现会话的共享。此时如果停止一个tomcat服务器t2,Apache将会自动把后续请求转发到集群中的其他服务器即t1。重启t2后,Apache会自动侦测到t2的状态为可用,然后会继续在t1和t2间进行负载均衡。

      如果需要向集群中增加节点,首先需要对tomcat作类似配置,然后修改Apache httpd.conf,增加BalancerMember,指向新增的tomcat即可。

转载于:https://www.cnblogs.com/jice/archive/2012/04/17/2410417.html

你可能感兴趣的:(windows下tomcat集群配置(两种方法))