|
两种方法只是在配置上不同原理一样,因为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 #
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. admin@your-domain.com
173 #
174 ServerAdmin zbjbox@gmail.com
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
2
18
22
23
24
25
26
27
28
29
30
31
32
35
36
39
44
45
46
51
52
53
54
55
57
58
59
66
67
82
83
84
94
95
101
105
110
111
112
113
114
115
120
121
124
125
126
129
130
131
132
134
135
139
144
145
150
155
156
157
158
159
160
161
162
163
164
166
167
174
175
176
177
178
181
184
185
189
191
192
195
198
199
201
204
205
207
211
212
213
214
215
2>web.xml(tomcat/conf)
web.xml(tomcat下的)
default
org.apache.catalina.servlets.DefaultServlet
debug
0
listings
false
1
jsp
org.apache.jasper.servlet.JspServlet
fork
false
xpoweredBy
false
3
default
/
jsp
*.jsp
jsp
*.jspx
30
abs
audio/x-mpeg
ai
application/postscript
aif
audio/x-aiff
aifc
audio/x-aiff
aiff
audio/x-aiff
aim
application/x-aim
art
image/x-jg
asf
video/x-ms-asf
asx
video/x-ms-asf
au
audio/basic
avi
video/x-msvideo
avx
video/x-rad-screenplay
bcpio
application/x-bcpio
bin
application/octet-stream
bmp
image/bmp
body
text/html
cdf
application/x-cdf
cer
application/x-x509-ca-cert
class
application/java
cpio
application/x-cpio
csh
application/x-csh
css
text/css
dib
image/bmp
doc
application/msword
dtd
application/xml-dtd
dv
video/x-dv
dvi
application/x-dvi
eps
application/postscript
etx
text/x-setext
exe
application/octet-stream
gif
image/gif
gtar
application/x-gtar
gz
application/x-gzip
hdf
application/x-hdf
hqx
application/mac-binhex40
htc
text/x-component
htm
text/html
html
text/html
hqx
application/mac-binhex40
ief
image/ief
jad
text/vnd.sun.j2me.app-descriptor
jar
application/java-archive
java
text/plain
jnlp
application/x-java-jnlp-file
jpe
image/jpeg
jpeg
image/jpeg
jpg
image/jpeg
js
text/javascript
jsf
text/plain
jspf
text/plain
kar
audio/x-midi
latex
application/x-latex
m3u
audio/x-mpegurl
mac
image/x-macpaint
man
application/x-troff-man
mathml
application/mathml+xml
me
application/x-troff-me
mid
audio/x-midi
midi
audio/x-midi
mif
application/x-mif
mov
video/quicktime
movie
video/x-sgi-movie
mp1
audio/x-mpeg
mp2
audio/x-mpeg
mp3
audio/x-mpeg
mp4
video/mp4
mpa
audio/x-mpeg
mpe
video/mpeg
mpeg
video/mpeg
mpega
audio/x-mpeg
mpg
video/mpeg
mpv2
video/mpeg2
ms
application/x-wais-source
nc
application/x-netcdf
oda
application/oda
odb
application/vnd.oasis.opendocument.database
odc
application/vnd.oasis.opendocument.chart
odf
application/vnd.oasis.opendocument.formula
odg
application/vnd.oasis.opendocument.graphics
odi
application/vnd.oasis.opendocument.image
odm
application/vnd.oasis.opendocument.text-master
odp
application/vnd.oasis.opendocument.presentation
ods
application/vnd.oasis.opendocument.spreadsheet
odt
application/vnd.oasis.opendocument.text
ogg
application/ogg
otg
application/vnd.oasis.opendocument.graphics-template
oth
application/vnd.oasis.opendocument.text-web
otp
application/vnd.oasis.opendocument.presentation-template
ots
application/vnd.oasis.opendocument.spreadsheet-template
ott
application/vnd.oasis.opendocument.text-template
pbm
image/x-portable-bitmap
pct
image/pict
pdf
application/pdf
pgm
image/x-portable-graymap
pic
image/pict
pict
image/pict
pls
audio/x-scpls
png
image/png
pnm
image/x-portable-anymap
pnt
image/x-macpaint
ppm
image/x-portable-pixmap
ppt
application/powerpoint
ps
application/postscript
psd
image/x-photoshop
qt
video/quicktime
qti
image/x-quicktime
qtif
image/x-quicktime
ras
image/x-cmu-raster
rdf
application/rdf+xml
rgb
image/x-rgb
rm
application/vnd.rn-realmedia
roff
application/x-troff
rtf
application/rtf
rtx
text/richtext
sh
application/x-sh
shar
application/x-shar
smf
audio/x-midi
sit
application/x-stuffit
snd
audio/basic
src
application/x-wais-source
sv4cpio
application/x-sv4cpio
sv4crc
application/x-sv4crc
swf
application/x-shockwave-flash
t
application/x-troff
tar
application/x-tar
tcl
application/x-tcl
tex
application/x-tex
texi
application/x-texinfo
texinfo
application/x-texinfo
tif
image/tiff
tiff
image/tiff
tr
application/x-troff
tsv
text/tab-separated-values
txt
text/plain
ulw
audio/basic
ustar
application/x-ustar
vxml
application/voicexml+xml
xbm
image/x-xbitmap
xht
application/xhtml+xml
xhtml
application/xhtml+xml
xml
application/xml
xpm
image/x-xpixmap
xsl
application/xml
xslt
application/xslt+xml
xul
application/vnd.mozilla.xul+xml
xwd
image/x-xwindowdump
wav
audio/x-wav
svg
image/svg+xml
svgz
image/svg+xml
vsd
application/x-visio
wbmp
image/vnd.wap.wbmp
wml
text/vnd.wap.wml
wmlc
application/vnd.wap.wmlc
wmls
text/vnd.wap.wmlscript
wmlscriptc
application/vnd.wap.wmlscriptc
wmv
video/x-ms-wmv
wrl
x-world/x-vrml
wspolicy
application/wspolicy+xml
Z
application/x-compress
z
application/x-compress
zip
application/zip
xls
application/vnd.ms-excel
doc
application/vnd.ms-word
ppt
application/vnd.ms-powerpoint
index.html
index.htm
index.jsp
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: 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
26 名称:
27 值:
28
29
30
31
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即可。 |
|