12
返回列表 发新帖
楼主: Sky-Tiger

apache和TOMCAT对接

[复制链接]
论坛徽章:
350
2006年度最佳版主
日期:2007-01-24 12:56:49NBA大富翁
日期:2008-04-21 22:57:29地主之星
日期:2008-11-17 19:37:352008年度最佳版主
日期:2009-03-26 09:33:53股神
日期:2009-04-01 10:05:56NBA季后赛大富翁
日期:2009-06-16 11:48:01NBA季后赛大富翁
日期:2009-06-16 11:48:01ITPUB年度最佳版主
日期:2011-04-08 18:37:09ITPUB年度最佳版主
日期:2011-12-28 15:24:18ITPUB年度最佳技术原创精华奖
日期:2012-03-13 17:12:05
11#
 楼主| 发表于 2008-12-27 10:51 | 只看该作者
There are a number of situations in which you may need to use multiple workers, including the
following:

❏ When you want different Web application contexts to be served by different Tomcat workers :
In production, this may happen when some workers are privy to specialized hardware connectivity
or setup (say, access to a Fiber Channel Storage Area Network). During testing, this setup
can provide a development environment in which all the developers share the same Web server
but have a dedicated Tomcat worker.
❏ When you want different virtual hosts served by different Tomcat processes to provide a clear
separation between sites belonging to different entities : This is useful when hardware is paid
for by different clients in a shared hosting environment, or when stability of operation requires
that applications from different sources be isolated physically.
❏ When you want to service more requests than the capacity of a single physical machine
allows : You can implement a cluster of machines with Tomcat workers running on them and
distribute the load between them.

使用道具 举报

回复
论坛徽章:
350
2006年度最佳版主
日期:2007-01-24 12:56:49NBA大富翁
日期:2008-04-21 22:57:29地主之星
日期:2008-11-17 19:37:352008年度最佳版主
日期:2009-03-26 09:33:53股神
日期:2009-04-01 10:05:56NBA季后赛大富翁
日期:2009-06-16 11:48:01NBA季后赛大富翁
日期:2009-06-16 11:48:01ITPUB年度最佳版主
日期:2011-04-08 18:37:09ITPUB年度最佳版主
日期:2011-12-28 15:24:18ITPUB年度最佳技术原创精华奖
日期:2012-03-13 17:12:05
12#
 楼主| 发表于 2008-12-27 10:52 | 只看该作者
In order for the Apache Web server to forward incoming requests to the Tomcat 6 instances, it must
know where they are located on the network. To describe where the Tomcat servers are located on the
network, and to provide specific instructions on how to work with each Tomcat instance, you need to
create a configuration information file called workers.properties . This file is placed in the conf directory
of your Apache Web server. mod_jk will scan the conf directory for the workers.properties file
during startup, and then process the configuration file and instantiate connections to the workers

使用道具 举报

回复
论坛徽章:
350
2006年度最佳版主
日期:2007-01-24 12:56:49NBA大富翁
日期:2008-04-21 22:57:29地主之星
日期:2008-11-17 19:37:352008年度最佳版主
日期:2009-03-26 09:33:53股神
日期:2009-04-01 10:05:56NBA季后赛大富翁
日期:2009-06-16 11:48:01NBA季后赛大富翁
日期:2009-06-16 11:48:01ITPUB年度最佳版主
日期:2011-04-08 18:37:09ITPUB年度最佳版主
日期:2011-12-28 15:24:18ITPUB年度最佳技术原创精华奖
日期:2012-03-13 17:12:05
13#
 楼主| 发表于 2008-12-27 10:53 | 只看该作者
The general flow of a workers.properties file is:
1. Description of the list of workers
2. Description of each of the worker instance in the list from the previous step
To describe the list of workers operating with an Apache server, you can use one or more of the following
statements.
worker.list = < a comma separated list of worker names >

To describe each instance of the workers named in the worker.list statement(s), you can use as many
statements of the following format as you need:
worker. <worker name>.<property> = <property value>

使用道具 举报

回复
论坛徽章:
350
2006年度最佳版主
日期:2007-01-24 12:56:49NBA大富翁
日期:2008-04-21 22:57:29地主之星
日期:2008-11-17 19:37:352008年度最佳版主
日期:2009-03-26 09:33:53股神
日期:2009-04-01 10:05:56NBA季后赛大富翁
日期:2009-06-16 11:48:01NBA季后赛大富翁
日期:2009-06-16 11:48:01ITPUB年度最佳版主
日期:2011-04-08 18:37:09ITPUB年度最佳版主
日期:2011-12-28 15:24:18ITPUB年度最佳技术原创精华奖
日期:2012-03-13 17:12:05
14#
 楼主| 发表于 2008-12-27 10:55 | 只看该作者
One of the more important properties for a worker instance that can be set in the worker.properties
file is the type of the worker. Each defined Tomcat worker must be assigned a type. Tomcat 6 integration
with the mod_jk Connector supports the following types of workers:
❏ ajp13 : This type of worker represents a running Tomcat instance. There are various possible
attributes for this worker. The main attributes include tomcatId (which represents the identity
of the Tomcat instance), channel (which indicates the communication channel associated with
this worker), and max_connections (which is used to specify the maximum number of connections).
By default, the maximum number of connections is unlimited. The default port for
AJP 1.3 is 8009.
❏ lb : This type of worker is used for load balancing . In a load-balancing scenario, the worker
doesn’t actually process any requests. Rather, it handles the communication between a Web
server and other defined Tomcat workers of type ajp13 . The worker supports round-robin load
balancing with a certain level of fault tolerance. One of the main properties for this worker is
worker , which indicates the name of the worker to be used as a load balancer. A number of attributes
are provided by the lb worker. Some of the attributes are explained later in this chapter.
❏ status : This is a special type of worker that is used to show useful information about how the
load among the various Tomcat workers is distributed. It does not process any request, and is
not associated with any Tomcat worker instances. To use it, add a mapping of URL using the
JkMount directive assigned to this worker. Its use is explained in the section “Tomcat Load
Balancing with Apache,” later in this chapter. The jkstatus Web page (again, described later)
typically displays some very vital information, including the available number and names of
workers, the associated lb_factor , and their locations. It also indicates the number of requests
served by a specific worker and any context mappings served. If any worker goes into an error
state, this can be easily detected from this page.
❏ jni : Used in-process, this worker handles the forwarding of requests to in-process Tomcat
workers using JNI. In the in-process mode, the Tomcat Web container and the Web server share
the same memory address space. They communicate via interprocess communication. This
worker holds the details of the Tomcat class to start up, and which parameters to pass. There are
two predefined jni workers: onStartup and onShutdown . These are executed during the
startup and shutdown phase of the connector, respectively. Both must exist in the configuration
in order to be able to start and shut down Tomcat. See the accompanying box about in-process
workers.

使用道具 举报

回复
论坛徽章:
350
2006年度最佳版主
日期:2007-01-24 12:56:49NBA大富翁
日期:2008-04-21 22:57:29地主之星
日期:2008-11-17 19:37:352008年度最佳版主
日期:2009-03-26 09:33:53股神
日期:2009-04-01 10:05:56NBA季后赛大富翁
日期:2009-06-16 11:48:01NBA季后赛大富翁
日期:2009-06-16 11:48:01ITPUB年度最佳版主
日期:2011-04-08 18:37:09ITPUB年度最佳版主
日期:2011-12-28 15:24:18ITPUB年度最佳技术原创精华奖
日期:2012-03-13 17:12:05
15#
 楼主| 发表于 2008-12-27 10:56 | 只看该作者
Depending on the type of a worker instance, additional properties can be defined for the instance in the
worker.properties file. If the worker instance is of ajp13 type, the following additional properties are
available:
❏ host : The host where the worker Tomcat 6 instance resides. You can specify a resolvable host
name or an IP address here.
❏ port : The port the AJP 1.3 Connector of the Tomcat worker instance is listening to for incoming
requests. The default is 8009 for AJP 1.3 connections.
❏ connection_pool_size : The number of connections used for this worker to be kept in a connection
pool. The connection pool enhances response time because re-creation of a socket is an
expensive operation. If there are already connections to a worker in the connection pool, the
Apache Web server can forward requests to the worker immediately, without having to create a
new connection. The default value depends on the server. On Apache 1.3 and 2. x prefork, this
should be set to 1 because they are not multithreaded. On 2. x mpm ( m ulti- p rocessing m odules
— a new 2. x feature designed to take maximum advantage of the underlying operating system),
multithreaded implementation, this is set by default to the threads-per-child value.
❏ connection_pool_minsize : The minimum number of connections kept in the connection
pool. By default, it is set to pool_size/2 for multithreaded Web servers.
❏ connection_pool_timeout : The number of seconds that connections to this worker should be
left in the connection pool before expiry.
❏ mount : The context paths that are serviced by the worker. The paths should be separated by
blank space. This property can be used instead of, or in addition to, the JkMount directive in the
httpd.conf file (described later).

使用道具 举报

回复
论坛徽章:
350
2006年度最佳版主
日期:2007-01-24 12:56:49NBA大富翁
日期:2008-04-21 22:57:29地主之星
日期:2008-11-17 19:37:352008年度最佳版主
日期:2009-03-26 09:33:53股神
日期:2009-04-01 10:05:56NBA季后赛大富翁
日期:2009-06-16 11:48:01NBA季后赛大富翁
日期:2009-06-16 11:48:01ITPUB年度最佳版主
日期:2011-04-08 18:37:09ITPUB年度最佳版主
日期:2011-12-28 15:24:18ITPUB年度最佳技术原创精华奖
日期:2012-03-13 17:12:05
16#
 楼主| 发表于 2008-12-27 10:57 | 只看该作者
❏ retries : Controls the number of times mod_jk will retry a worker when an error is returned
during request forwarding. A small delay is inserted between each retry (100ms). The default is 3 .
❏ socket_timeout : The default is 0 , which means to wait indefinitely. This timeout controls how
long, in seconds, mod_jk will wait for a worker to respond on a socket before indicating an error.
❏ socket_keepalive : Indicates if the connection to the worker should be subjected to keep alive:
1 for true , and 0 for no keep alive on the connection. The default is 0 . The keepalive attribute
is useful when a firewall sitting between the Web server and the worker may drop connections
that have been inactive for a long time.
❏ lbfactor : An integer indicating the load-balance factor used by a load balancer to distribute
work between multiple instances of Tomcat 6 servers. A more detailed description of load balancing,
and how this factor is used, is available in the section “Tomcat Load Balancing with Apache.”

使用道具 举报

回复
论坛徽章:
350
2006年度最佳版主
日期:2007-01-24 12:56:49NBA大富翁
日期:2008-04-21 22:57:29地主之星
日期:2008-11-17 19:37:352008年度最佳版主
日期:2009-03-26 09:33:53股神
日期:2009-04-01 10:05:56NBA季后赛大富翁
日期:2009-06-16 11:48:01NBA季后赛大富翁
日期:2009-06-16 11:48:01ITPUB年度最佳版主
日期:2011-04-08 18:37:09ITPUB年度最佳版主
日期:2011-12-28 15:24:18ITPUB年度最佳技术原创精华奖
日期:2012-03-13 17:12:05
17#
 楼主| 发表于 2008-12-27 10:59 | 只看该作者
Note that an lb worker is not a
physical Tomcat 6 instance. In fact, it does not have a host or port property and does not cause any network
traffic. Instead, it is the control center for configuring the load-balancing behavior for a group of
physical workers.
❏ balance_workers : A list of workers to balance the load between, when using this load balancer.
Any worker that appears here must not appear in a worker.list ; instead, the worker
.list should contain the name of the load-balancer worker.
❏ lock : The default is O (Optimistic lock). The property controls how the load balancer accesses
shared runtime memory containing stats to determine which worker to use. In O mode, there is
no lock on the shared runtime memory used, and the stats value can change during the determination.
It can also be set to P (Pessimistic lock) — in this case, the selection is more accurate but
performance during load balancing may suffer slightly.
❏ method : Can be set to R , T , or B . The default is R . This controls the selection of worker for request
forwarding. When set to R (Requests), the worker to use is based on the number of requests forwarded.
When set to T (Traffic), the worker to use is based on the traffic that had been sent to the
workers. When set to B (Busy-ness), the worker to use is based on the load by dividing the number
of concurrent requests by the load factor.
❏ secret : Sets a default secret password for all workers.
❏ sticky_session : The default is set to 1 . This tells the mod_jk to respect the session ID in the
request, and ensures that the same session is always serviced by the same worker instance.
If you set it to 0 , the request from the same session may be forwarded to any of the worker
instances. You should set it to 0 only if the session manager deployed has some way of providing
shared session information across workers.

使用道具 举报

回复
论坛徽章:
350
2006年度最佳版主
日期:2007-01-24 12:56:49NBA大富翁
日期:2008-04-21 22:57:29地主之星
日期:2008-11-17 19:37:352008年度最佳版主
日期:2009-03-26 09:33:53股神
日期:2009-04-01 10:05:56NBA季后赛大富翁
日期:2009-06-16 11:48:01NBA季后赛大富翁
日期:2009-06-16 11:48:01ITPUB年度最佳版主
日期:2011-04-08 18:37:09ITPUB年度最佳版主
日期:2011-12-28 15:24:18ITPUB年度最佳技术原创精华奖
日期:2012-03-13 17:12:05
18#
 楼主| 发表于 2008-12-27 11:05 | 只看该作者
The default server.xml file already has a configuration entry for the AJP 1.3 Connector, but it may be
commented out. Uncomment this tag if commented. This is what you should see:
<!-- Define an AJP 1.3 Connector on port 8009 -->
<Connector port=”8009” protocol=”AJP/1.3” redirectPort=”8443” />
These lines represent an AJP Connector that will use AJP version 1.3 and listen on AJP’s default port
(8009). The port attribute is configurable, and is the port on which Tomcat listens for AJP requests. Most
of the attributes for the default Java HTTP/1.1 Connector mentioned in Chapter 10 also apply to the AJP
Connector. Here are some of the key configurable attributes for this Connector:
❏ enableLookups : If set to true , calls to request.getRemoteHost() will perform DNS lookup
to return the actual host name of the remote client. Setting this to false will skip the DNS
lookup and return the IP address as a string (thereby improving performance). By default, DNS
lookups are disabled.
❏ redirectPort : If a request is received for which a matching <security-constraint> requires
SSL transport, Tomcat automatically redirects the request to the port number specified here.
❏ scheme : Set this attribute to the name of the protocol you want to have returned by calls to
request.getScheme() . For example, you would set this attribute to https for an SSL Connector.
The default value is http .
❏ secure : If set to true , calls to request.isSecure() will return true where the Connector is
SSL-enabled. The default value is false .
❏ protocol : This attribute value must be AJP/1.3 in order to select the AJP Connector.

使用道具 举报

回复
论坛徽章:
350
2006年度最佳版主
日期:2007-01-24 12:56:49NBA大富翁
日期:2008-04-21 22:57:29地主之星
日期:2008-11-17 19:37:352008年度最佳版主
日期:2009-03-26 09:33:53股神
日期:2009-04-01 10:05:56NBA季后赛大富翁
日期:2009-06-16 11:48:01NBA季后赛大富翁
日期:2009-06-16 11:48:01ITPUB年度最佳版主
日期:2011-04-08 18:37:09ITPUB年度最佳版主
日期:2011-12-28 15:24:18ITPUB年度最佳技术原创精华奖
日期:2012-03-13 17:12:05
19#
 楼主| 发表于 2008-12-27 11:16 | 只看该作者
On the Apache Web server side, you may have a choice of using either mod_jk or mod_proxy , depending
on the version of Apache server you are using.
In either case, you need to perform the following steps:
1. Install the Apache mod_jk or mod_proxy binary module to your Apache Web server. In some
cases, the binary is not available and you must build/compile the binaries yourself from a
download source code.
2. Add directives in the Apache Web server configuration to load the mod_jk module ( httpd.conf ).
3. Configure the worker.properties file describing the Tomcat worker instances that are
available.
The files that are created or modified during this configuration include:
❏ httpd.conf : This is Apache’s main configuration file and is located under <APACHE_HOME>/
conf . You add directives to load the mod_jk module to this file.
❏ worker.properties : This file specifies the communication channel details needed for connecting
Tomcat with Apache. This file is located under <APACHE_HOME>/conf .

Some differences exist between the configuration of mod_jk versus mod_proxy . The next two sections
cover the use of mod_jk first, and then the use of mod_proxy .

使用道具 举报

回复
论坛徽章:
131
乌索普
日期:2017-09-26 13:06:30马上加薪
日期:2014-11-22 01:34:242014年世界杯参赛球队: 尼日利亚
日期:2014-06-17 15:23:23马上有对象
日期:2014-05-11 19:35:172014年新春福章
日期:2014-04-04 16:16:58马上有对象
日期:2014-03-08 16:50:54马上加薪
日期:2014-02-19 11:55:14马上有对象
日期:2014-02-19 11:55:14马上有钱
日期:2014-02-19 11:55:14马上有房
日期:2014-02-19 11:55:14
20#
发表于 2008-12-31 23:38 | 只看该作者
辛苦

使用道具 举报

回复

您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

TOP技术积分榜 社区积分榜 徽章 团队 统计 知识索引树 积分竞拍 文本模式 帮助
  ITPUB首页 | ITPUB论坛 | 数据库技术 | 企业信息化 | 开发技术 | 微软技术 | 软件工程与项目管理 | IBM技术园地 | 行业纵向讨论 | IT招聘 | IT文档
  ChinaUnix | ChinaUnix博客 | ChinaUnix论坛
CopyRight 1999-2011 itpub.net All Right Reserved. 北京盛拓优讯信息技术有限公司版权所有 联系我们 未成年人举报专区 
京ICP备16024965号-8  北京市公安局海淀分局网监中心备案编号:11010802021510 广播电视节目制作经营许可证:编号(京)字第1149号
  
快速回复 返回顶部 返回列表