码迷,mamicode.com
首页 > Web开发 > 详细

Apache Http Server与Tomcat6 的负载均衡(二)

时间:2015-08-13 17:37:43      阅读:238      评论:0      收藏:0      [点我收藏+]

标签:

一般来说,实现Apache与Tomcat6的负载均衡有两种方式,一种是使用mod_jk,另一种是使用mod_proxy模块。本文只讨论mod_jk方式。

无论使用哪种方式,一般都要经过以下这几个步骤(同一台机器):

  1. 修改startup.bat中的CATALINA_HOME变量的值。因为每个Tomcat实体的CATALINA_HOME都是不一样的,如果设置为系统的环境变量,那么在启动这几个Tomcat时就会出问题。
  2. 设置不同的Tomcat服务器(启动)端口
  3. 对不同的Tomcat实体设置不同的AJP connector
  4. 停止Coyote HTTP/1.1  连接器(Http请求交给Apache Http Server处理)
  5. 在Standalone Engine中设置jvmRoute
  6. 注释掉Catalina Engine
  7. 在worker.properties中配置Tomcat worker

下面来详细说下详细的配置步骤

在Tomcat startup.bat中修改CATALINA_HOME的值

注:这一步跟负载均衡没关系,没有负载均衡也要进行这一步

首先下载Tomcat6.*.*.zip,解压后进行重命名,复制三个,分别是Tomcat6A,Tomcat6B,Tomcat6C

startup.bat只是在.zip格式的Tomcat压缩包里才有,使用安装包安装的好像没有。找到这个文件,打开后修改

对与Tomcat6A:

set CATALINA_HOME=%CURRENT_DIR%为set CATALINA_HOME=C:/Program Files/Apache Software Foundation/Tomcat6A、

对于Tomcat6B:

set CATALINA_HOME=%CURRENT_DIR%为set CATALINA_HOME=C:/Program Files/Apache Software Foundation/Tomcat6B、 
对于Tomcat6C:
set CATALINA_HOME=%CURRENT_DIR%为set CATALINA_HOME=C:/Program Files/Apache Software Foundation/Tomcat6C、

设置不同的服务器端口

注:这一步与负载均衡没有直接关系,是为了处理多个Tomcat的问题,如果这些Tomcat分布在 不同的机器上,应该不会有这个问题
打开conf/server.xml,找到下面这个标签:
<Server port="8005" shutdown="SHUTDOWN" debug="0">
在本例中, Tomcat6A使用8005端口
Tomcat6B使用8006端口
Tomcat6C使用8007端口

设置Tomcat中的AJP连接器接口

注:这是第一步跟负载均衡直接相关的步骤
打开conf/server.xml,找到这样一个xml标签:
<!--Define an AJP1.3 connector on port 8009-->
<Connector port="8009" protocol="AJP/1.3" redirectPort="8443">
在本例中, Tomcat6A使用8009端口
Tomcat6B使用8010端口
Tomcat6C使用8011端口

停止监听默认的Http/1.1连接器

注:这步也是和负载均衡直接相关,但不是负载均衡中的关键,只是个副产品(byproduct)

为了防止人们直接访问某个Tomcat(因为这样会使负载均衡器失去意义),所以我们要关掉它的HTTP连接器,使得这些Tomcat只能通过AJP协议接收Apache转发过来的请求,因此需要停止HTTP/1.1连接器

打开conf/server.xml,像下面的代码这样注释掉HTTP/1.1连接器的监听
<!--Define
<Connector port="8080" protocol="HTTP/1.1"
maxThreads="150" connectionTimeout="20000"
redirectPort="8443 />"
-->

在Standalone Engine中设置jvmRoute属性

注:这是实现负载均衡的关键一步,这一步做了两件事,一是配置了Standalone Engine,二是赋予这个Engine一个id:jvmRoute

每个Tomcat worker的server.xml中都有有关Engine的配置(语句)。这个Engine是一个和Catalina Engine一样级别最高的Engine,代表整个Catalina Servlet Engine。这条配置语句在server.xml中,jvmRoute的值必须是唯一的,在本例中,各个Tomcat实例的配置如下

Tomcat6A:

<!--You should set jvmRoute to support load-balancing via AJP-->

<Engine name="Standalone" defaultHost="localhost" jvmRoute="Tomcat6A">

Tomcat6B:

 

<!--You should set jvmRoute to support load-balancing via AJP-->

<Engine name="Standalone" defaultHost="localhost" jvmRoute="Tomcat6A">

 

Tomcat6C:

 

<!--You should set jvmRoute to support load-balancing via AJP-->

<Engine name="Standalone" defaultHost="localhost" jvmRoute="Tomcat6A">

 

注释掉Catalina Engine

注:这一步其实可以和上一步合并

因为我们配置了Standalone Engine,因此需要注释掉Catalina Engine。具体做法是:在server.xml中找到相应代码进行注释,结果如下:、

<!--

<Engine name=-"Catalina" defaultHost="localhost">

-->

 

在httpd.conf中配置Tomcat与Apache

 

注:粗体字为与负载均衡有直接关系的配置语句

在Apache Http Server下的conf文件夹中打开httpd.conf,添加下面的语句到其末尾

 

LoadModule jk_module modules/mod_jk.so

JkWorkersFile conf/workers.properties

JkLogLevel error

JkLogFile "C:/Program Files/Apache Software Foundation/Apache2.2/logs/mod_jk.Log"

JkMount /examples/jsp/*bal1
JkMount/jkstatus/stat1

配置workers.proterties

配置每一个Tomcat实例

在workers.proterties中每一个Tomcat实例一般有这几个属性需要配置,分别是:

type(类型): 一般有ajp13(代表Tomcat的worker),lb负载

host(主机): Tomcat所在机器的ip地址

port(端口): worker所监听的端口号

lbfactor(负载权重): 影响负载均衡器在分发请求时所分配的请求数,相对大小更重要

 

在本例中,具体配置如下:

 

Tomcat6A:

worker.Tomcat6A.type = ajp13

worker.Tomcat6A.host = 192.168.9.182

worker.Tomcat6A.port = 8009

worker.Tomcat6A.lbfactor=10

 

Tomcat6B:

worker.Tomcat6B.type = ajp13

worker.Tomcat6B.host = 192.168.9.182

worker.Tomcat6B.port = 8010

worker.Tomcat6B.lbfactor = 10

 

Tomcat6C:

worker.Tomcat6C.type = ajp13

worker.Tomcat6C.host = 192.168.9.182

worker.Tomcat6C.port = 8011

worker.Tomcat6C.lbfactor = 10

 

(这里的host值就是自己机器的ip地址,需要查看自己的机器的ip地址来替代这个地址)

在worker.properties中配置负载均衡器

在worker.properties文件中添加这两条配置语句

worker.bal1.type = lb

worker.bal1.sticky_session = 1

worker.bal1.balance = Tomcat6A, Tomcat6B, Tomcat6C

 

sticky_session属性设为1,这样负载均衡器lb就会尽量保持一个session,也就是使用户在一次会话中跟同一个Tomcat进行交互。(我猜如果不能保持跟同一个Tomcat进行交互,也就不能保持一个session)。

balance属性可以告诉mod_jk模块那些worker由lb负载均衡器控制

 

在worker.properties中配置Status Worker

利用这个Worker,我们可以获得负载的实时统计信息

在worker.properties中添加

worker.staat1.type = status

 

给mod_jk配置workes.list

到现在为止,我们已经配置好了三个ajp13 worker,一个lb worker,一个status worker。接下来需要做的就是告诉mod_jk这些worker的信息,在worker.properties中添加这条配置语句就可以做到:

worker.list = bal1, stat1

 

一个配置好的worker.properties实例

worker.list = bal1, stat1

worker.Tomcat6A.type = ajp13

worker.Tomcat6A.host = 192.168.9.182

worker.Tomcat6A.port = 8009

worker.Tomcat6A.lbfactor = 10

worker.Tomcat6B.type = ajp13

worker.Tomcat6B.host = 192.168.9.182

worker.Tomcat6B.port = 8010

worker.Tomcat6B.lbfactor = 10

worker.Tomcat6C.type = ajp13

worker.Tomcat6C.host = 192.168.9.182

worker.Tomcat6C.port = 8011

worker.Tomcat6C.lbfactor = 10

worker.bal1.type = lb

worker.bal1.stick_session = 1

worker.bal1.balance_workers = Tomcat6A, Tomcat6B, Tomcat6C

worker.stat1.type = status

 

测试配置是否成功

在Tomcat的目录下找到webapps/examples/jsp/目录下创建一个index.jsp文件,内容如下:

 

  1. <%@page language="java"%>  
  2. <html>  
  3.   <body>  
  4.     <h1>Index Page Of Tomcat6A</h1>  
  5.   </body>  
  6. </html>  

 

 

其他两个Tomcat所做的操作类似,只是index.jsp中的内容变了一下,分别是:

 

  1. <%@page language="java"%>  
  2. <html>  
  3.   <body>  
  4.     <h1>Index Page Of Tomcat6A</h1>  
  5.   </body>  
  6. </html>  

 

 

 

 

  1. <%@page language="java"%>  
  2. <html>  
  3.   <body>  
  4.     <h1>Index Page Of Tomcat6A</h1>  
  5.   </body>  
  6. </html>  

 

 

 

配好后,重启Tomcat和Apache Http Server,顺序为 关闭Apache->关闭Tomcat->启动Tomcat->启动Apache

 

在浏览器中输入http://localhost/examples/jsp/index.jsp,然后运行多个浏览器实例(同一个浏览器的标签式浏览不行,因为很多标签式浏览被设置为共享session),如果出现不同的页面,就说明负载均衡配置成功了。

在浏览器中输入http://localhost/jkstatus/,,将出现目前负载情况的统计资料,如下图所示:

 

技术分享

 

 

 

  1 <?xml version=‘1.0‘ encoding=‘utf-8‘?>
  2 <!--
  3   Licensed to the Apache Software Foundation (ASF) under one or more
  4   contributor license agreements.  See the NOTICE file distributed with
  5   this work for additional information regarding copyright ownership.
  6   The ASF licenses this file to You under the Apache License, Version 2.0
  7   (the "License"); you may not use this file except in compliance with
  8   the License.  You may obtain a copy of the License at
  9 
 10       http://www.apache.org/licenses/LICENSE-2.0
 11 
 12   Unless required by applicable law or agreed to in writing, software
 13   distributed under the License is distributed on an "AS IS" BASIS,
 14   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 15   See the License for the specific language governing permissions and
 16   limitations under the License.
 17 -->
 18 <!-- Note:  A "Server" is not itself a "Container", so you may not
 19      define subcomponents such as "Valves" at this level.
 20      Documentation at /docs/config/server.html
 21  -->
 22 <Server port="8005" shutdown="SHUTDOWN">
 23   <Listener className="org.apache.catalina.startup.VersionLoggerListener" />
 24   <!-- Security listener. Documentation at /docs/config/listeners.html
 25   <Listener className="org.apache.catalina.security.SecurityListener" />
 26   -->
 27   <!--APR library loader. Documentation at /docs/apr.html -->
 28   <Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" />
 29   <!--Initialize Jasper prior to webapps are loaded. Documentation at /docs/jasper-howto.html -->
 30   <Listener className="org.apache.catalina.core.JasperListener" />
 31   <!-- Prevent memory leaks due to use of particular java/javax APIs-->
 32   <Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener" />
 33   <Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" />
 34   <Listener className="org.apache.catalina.core.ThreadLocalLeakPreventionListener" />
 35 
 36   <!-- Global JNDI resources
 37        Documentation at /docs/jndi-resources-howto.html
 38   -->
 39   <GlobalNamingResources>
 40     <!-- Editable user database that can also be used by
 41          UserDatabaseRealm to authenticate users
 42     -->
 43     <Resource name="UserDatabase" auth="Container"
 44               type="org.apache.catalina.UserDatabase"
 45               description="User database that can be updated and saved"
 46               factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
 47               pathname="conf/tomcat-users.xml" />
 48   </GlobalNamingResources>
 49 
 50   <!-- A "Service" is a collection of one or more "Connectors" that share
 51        a single "Container" Note:  A "Service" is not itself a "Container",
 52        so you may not define subcomponents such as "Valves" at this level.
 53        Documentation at /docs/config/service.html
 54    -->
 55   <Service name="Catalina">
 56 
 57     <!--The connectors can use a shared executor, you can define one or more named thread pools-->
 58     <!--
 59     <Executor name="tomcatThreadPool" namePrefix="catalina-exec-"
 60         maxThreads="150" minSpareThreads="4"/>
 61     -->
 62 
 63 
 64     <!-- A "Connector" represents an endpoint by which requests are received
 65          and responses are returned. Documentation at :
 66          Java HTTP Connector: /docs/config/http.html (blocking & non-blocking)
 67          Java AJP  Connector: /docs/config/ajp.html
 68          APR (HTTP/AJP) Connector: /docs/apr.html
 69          Define a non-SSL HTTP/1.1 Connector on port 8080
 70     -->
 71     <Connector port="8080" protocol="HTTP/1.1"
 72                connectionTimeout="20000"
 73                redirectPort="8443"  URIEncoding="UTF-8" />
 74     <!-- A "Connector" using the shared thread pool-->
 75     <!--
 76     <Connector executor="tomcatThreadPool"
 77                port="8080" protocol="HTTP/1.1"
 78                connectionTimeout="20000"
 79                redirectPort="8443" />
 80     -->
 81     <!-- Define a SSL HTTP/1.1 Connector on port 8443
 82          This connector uses the BIO implementation that requires the JSSE
 83          style configuration. When using the APR/native implementation, the
 84          OpenSSL style configuration is required as described in the APR/native
 85          documentation -->
 86     <!--
 87     <Connector port="8443" protocol="org.apache.coyote.http11.Http11Protocol"
 88                maxThreads="150" SSLEnabled="true" scheme="https" secure="true"
 89                clientAuth="false" keystoreFile="C:/tomcat.keystore" keystorePass="password" sslProtocol="TLS" />
 90                -->
 91 <!--
 92   <Connector port="8081" protocol="HTTP/1.1"
 93                connectionTimeout="20000"
 94                redirectPort="8443"  URIEncoding="UTF-8" />
 95 
 96   <Connector port="8082" protocol="HTTP/1.1"
 97                connectionTimeout="20000"
 98                redirectPort="8443"  URIEncoding="UTF-8" />
 99 
100 
101   <Connector port="8083" protocol="HTTP/1.1"
102                connectionTimeout="20000"
103                redirectPort="8443"  URIEncoding="UTF-8" />
104 
105  <Connector port="8084" protocol="HTTP/1.1"
106                connectionTimeout="20000"
107                redirectPort="8443"  URIEncoding="UTF-8" />
108 -->
109 
110     
111 
112     <!-- Define an AJP 1.3 Connector on port 8009 -->
113     <Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />
114  
115      
116 
117     <!-- An Engine represents the entry point (within Catalina) that processes
118          every request.  The Engine implementation for Tomcat stand alone
119          analyzes the HTTP headers included with the request, and passes them
120          on to the appropriate Host (virtual host).
121          Documentation at /docs/config/engine.html -->
122 
123     <!-- You should set jvmRoute to support load-balancing via AJP ie :
124     <Engine name="Catalina" defaultHost="localhost" jvmRoute="jvm1">
125     -->
126     <Engine name="Catalina" defaultHost="localhost"  jvmRoute="worker1">
127 
128       <!--For clustering, please take a look at documentation at:
129           /docs/cluster-howto.html  (simple how to)
130           /docs/config/cluster.html (reference documentation) -->
131       <!--
132       <Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"/>
133       -->
134       <Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster" channelSendOptions="8">
135 
136             <Manager className="org.apache.catalina.ha.session.DeltaManager" 
137                 expireSessionsOnShutdown="false"
138                 notifyListenersOnReplication="true" />
139 
140             <Channel className="org.apache.catalina.tribes.group.GroupChannel">
141                 <Membership className="org.apache.catalina.tribes.membership.McastService" 
142                     address="228.0.0.4"
143                     port="45564" 
144                     frequency="500" 
145                     dropTime="3000" />
146                 <Receiver className="org.apache.catalina.tribes.transport.nio.NioReceiver" 
147                     address="auto"
148                     port="4000" 
149                     autoBind="100" 
150                     selectorTimeout="5000" 
151                     maxThreads="6" />
152 
153                 <Sender className="org.apache.catalina.tribes.transport.ReplicationTransmitter">
154                     <Transport className="org.apache.catalina.tribes.transport.nio.PooledParallelSender" />
155                 </Sender>
156                 <Interceptor className="org.apache.catalina.tribes.group.interceptors.TcpFailureDetector" />
157                 <Interceptor className="org.apache.catalina.tribes.group.interceptors.MessageDispatch15Interceptor" />
158             </Channel>
159 
160             <Valve className="org.apache.catalina.ha.tcp.ReplicationValve" filter="" />
161             <Valve className="org.apache.catalina.ha.session.JvmRouteBinderValve" />
162 
163             <Deployer className="org.apache.catalina.ha.deploy.FarmWarDeployer" 
164                 tempDir="/tmp/war-temp/"
165                 deployDir="/tmp/war-deploy/" 
166                 watchDir="/tmp/war-listen/" 
167                 watchEnabled="false" />
168 
169             <ClusterListener className="org.apache.catalina.ha.session.JvmRouteSessionIDBinderListener" />
170             <ClusterListener className="org.apache.catalina.ha.session.ClusterSessionListener" />
171         </Cluster>
172 
173       <!-- Use the LockOutRealm to prevent attempts to guess user passwords
174            via a brute-force attack -->
175       <Realm className="org.apache.catalina.realm.LockOutRealm">
176         <!-- This Realm uses the UserDatabase configured in the global JNDI
177              resources under the key "UserDatabase".  Any edits
178              that are performed against this UserDatabase are immediately
179              available for use by the Realm.  -->
180         <Realm className="org.apache.catalina.realm.UserDatabaseRealm"
181                resourceName="UserDatabase"/>
182       </Realm>
183 
184       <Host name="localhost"  appBase="webapps"
185             unpackWARs="true" autoDeploy="true">
186 
187         <!-- SingleSignOn valve, share authentication between web applications
188              Documentation at: /docs/config/valve.html -->
189         <!--
190         <Valve className="org.apache.catalina.authenticator.SingleSignOn" />
191         -->
192 
193         <!-- Access log processes all example.
194              Documentation at: /docs/config/valve.html
195              Note: The pattern used is equivalent to using pattern="common" -->
196         <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
197                prefix="localhost_access_log." suffix=".txt"
198                pattern="%h %l %u %t &quot;%r&quot; %s %b" />
199 
200       </Host>
201     </Engine>
202   </Service>
203   
204   <Service name="Catalina1">
205 
206     <!--The connectors can use a shared executor, you can define one or more named thread pools-->
207     <!--
208     <Executor name="tomcatThreadPool" namePrefix="catalina-exec-"
209         maxThreads="150" minSpareThreads="4"/>
210     -->
211 
212 
213     <!-- A "Connector" represents an endpoint by which requests are received
214          and responses are returned. Documentation at :
215          Java HTTP Connector: /docs/config/http.html (blocking & non-blocking)
216          Java AJP  Connector: /docs/config/ajp.html
217          APR (HTTP/AJP) Connector: /docs/apr.html
218          Define a non-SSL HTTP/1.1 Connector on port 8080
219     -->
220     <Connector port="8081" protocol="HTTP/1.1"
221                connectionTimeout="20000"
222                redirectPort="8443"  URIEncoding="UTF-8" />
223     <!-- A "Connector" using the shared thread pool-->
224     <!--
225     <Connector executor="tomcatThreadPool"
226                port="8080" protocol="HTTP/1.1"
227                connectionTimeout="20000"
228                redirectPort="8443" />
229     -->
230     <!-- Define a SSL HTTP/1.1 Connector on port 8443
231          This connector uses the BIO implementation that requires the JSSE
232          style configuration. When using the APR/native implementation, the
233          OpenSSL style configuration is required as described in the APR/native
234          documentation -->
235     <!--
236     <Connector port="8443" protocol="org.apache.coyote.http11.Http11Protocol"
237                maxThreads="150" SSLEnabled="true" scheme="https" secure="true"
238                clientAuth="false" keystoreFile="C:/tomcat.keystore" keystorePass="password" sslProtocol="TLS" />
239                -->
240 <!--
241   <Connector port="8081" protocol="HTTP/1.1"
242                connectionTimeout="20000"
243                redirectPort="8443"  URIEncoding="UTF-8" />
244 
245   <Connector port="8082" protocol="HTTP/1.1"
246                connectionTimeout="20000"
247                redirectPort="8443"  URIEncoding="UTF-8" />
248 
249 
250   <Connector port="8083" protocol="HTTP/1.1"
251                connectionTimeout="20000"
252                redirectPort="8443"  URIEncoding="UTF-8" />
253 
254  <Connector port="8084" protocol="HTTP/1.1"
255                connectionTimeout="20000"
256                redirectPort="8443"  URIEncoding="UTF-8" />
257 -->
258 
259     
260 
261     <!-- Define an AJP 1.3 Connector on port 8009 -->
262     <Connector port="8010" protocol="AJP/1.3" redirectPort="8443" />
263     
264      
265 
266     <!-- An Engine represents the entry point (within Catalina) that processes
267          every request.  The Engine implementation for Tomcat stand alone
268          analyzes the HTTP headers included with the request, and passes them
269          on to the appropriate Host (virtual host).
270          Documentation at /docs/config/engine.html -->
271 
272     <!-- You should set jvmRoute to support load-balancing via AJP ie :
273     <Engine name="Catalina" defaultHost="localhost" jvmRoute="jvm1">
274     -->
275     <Engine name="Catalina" defaultHost="localhost"  jvmRoute="worker2">
276 
277       <!--For clustering, please take a look at documentation at:
278           /docs/cluster-howto.html  (simple how to)
279           /docs/config/cluster.html (reference documentation) -->
280       <!--
281       <Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"/>
282       -->
283       <Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster" channelSendOptions="8">
284 
285             <Manager className="org.apache.catalina.ha.session.DeltaManager" 
286                 expireSessionsOnShutdown="false"
287                 notifyListenersOnReplication="true" />
288 
289             <Channel className="org.apache.catalina.tribes.group.GroupChannel">
290                 <Membership className="org.apache.catalina.tribes.membership.McastService" 
291                     address="228.0.0.4"
292                     port="45564" 
293                     frequency="500" 
294                     dropTime="3000" />
295                 <Receiver className="org.apache.catalina.tribes.transport.nio.NioReceiver" 
296                     address="auto"
297                     port="4000" 
298                     autoBind="100" 
299                     selectorTimeout="5000" 
300                     maxThreads="6" />
301 
302                 <Sender className="org.apache.catalina.tribes.transport.ReplicationTransmitter">
303                     <Transport className="org.apache.catalina.tribes.transport.nio.PooledParallelSender" />
304                 </Sender>
305                 <Interceptor className="org.apache.catalina.tribes.group.interceptors.TcpFailureDetector" />
306                 <Interceptor className="org.apache.catalina.tribes.group.interceptors.MessageDispatch15Interceptor" />
307             </Channel>
308 
309             <Valve className="org.apache.catalina.ha.tcp.ReplicationValve" filter="" />
310             <Valve className="org.apache.catalina.ha.session.JvmRouteBinderValve" />
311 
312             <Deployer className="org.apache.catalina.ha.deploy.FarmWarDeployer" 
313                 tempDir="/tmp/war-temp/"
314                 deployDir="/tmp/war-deploy/" 
315                 watchDir="/tmp/war-listen/" 
316                 watchEnabled="false" />
317 
318             <ClusterListener className="org.apache.catalina.ha.session.JvmRouteSessionIDBinderListener" />
319             <ClusterListener className="org.apache.catalina.ha.session.ClusterSessionListener" />
320         </Cluster>
321 
322       <!-- Use the LockOutRealm to prevent attempts to guess user passwords
323            via a brute-force attack -->
324       <Realm className="org.apache.catalina.realm.LockOutRealm">
325         <!-- This Realm uses the UserDatabase configured in the global JNDI
326              resources under the key "UserDatabase".  Any edits
327              that are performed against this UserDatabase are immediately
328              available for use by the Realm.  -->
329         <Realm className="org.apache.catalina.realm.UserDatabaseRealm"
330                resourceName="UserDatabase"/>
331       </Realm>
332 
333       <Host name="localhost"  appBase="webapps"
334             unpackWARs="true" autoDeploy="true">
335 
336         <!-- SingleSignOn valve, share authentication between web applications
337              Documentation at: /docs/config/valve.html -->
338         <!--
339         <Valve className="org.apache.catalina.authenticator.SingleSignOn" />
340         -->
341 
342         <!-- Access log processes all example.
343              Documentation at: /docs/config/valve.html
344              Note: The pattern used is equivalent to using pattern="common" -->
345         <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
346                prefix="localhost_access_log." suffix=".txt"
347                pattern="%h %l %u %t &quot;%r&quot; %s %b" />
348 
349       </Host>
350     </Engine>
351   </Service>
352 
353   <Service name="Catalina2">
354 
355     <!--The connectors can use a shared executor, you can define one or more named thread pools-->
356     <!--
357     <Executor name="tomcatThreadPool" namePrefix="catalina-exec-"
358         maxThreads="150" minSpareThreads="4"/>
359     -->
360 
361 
362     <!-- A "Connector" represents an endpoint by which requests are received
363          and responses are returned. Documentation at :
364          Java HTTP Connector: /docs/config/http.html (blocking & non-blocking)
365          Java AJP  Connector: /docs/config/ajp.html
366          APR (HTTP/AJP) Connector: /docs/apr.html
367          Define a non-SSL HTTP/1.1 Connector on port 8080
368     -->
369     <Connector port="8082" protocol="HTTP/1.1"
370                connectionTimeout="20000"
371                redirectPort="8443"  URIEncoding="UTF-8" />
372     <!-- A "Connector" using the shared thread pool-->
373     <!--
374     <Connector executor="tomcatThreadPool"
375                port="8080" protocol="HTTP/1.1"
376                connectionTimeout="20000"
377                redirectPort="8443" />
378     -->
379     <!-- Define a SSL HTTP/1.1 Connector on port 8443
380          This connector uses the BIO implementation that requires the JSSE
381          style configuration. When using the APR/native implementation, the
382          OpenSSL style configuration is required as described in the APR/native
383          documentation -->
384     <!--
385     <Connector port="8443" protocol="org.apache.coyote.http11.Http11Protocol"
386                maxThreads="150" SSLEnabled="true" scheme="https" secure="true"
387                clientAuth="false" keystoreFile="C:/tomcat.keystore" keystorePass="password" sslProtocol="TLS" />
388                -->
389 
390     <!-- Define an AJP 1.3 Connector on port 8009 -->
391     <Connector port="8011" protocol="AJP/1.3" redirectPort="8443" />
392     
393      
394 
395     <!-- An Engine represents the entry point (within Catalina) that processes
396          every request.  The Engine implementation for Tomcat stand alone
397          analyzes the HTTP headers included with the request, and passes them
398          on to the appropriate Host (virtual host).
399          Documentation at /docs/config/engine.html -->
400 
401     <!-- You should set jvmRoute to support load-balancing via AJP ie :
402     <Engine name="Catalina" defaultHost="localhost" jvmRoute="jvm1">
403     -->
404     <Engine name="Catalina" defaultHost="localhost"  jvmRoute="worker3">
405 
406       <!--For clustering, please take a look at documentation at:
407           /docs/cluster-howto.html  (simple how to)
408           /docs/config/cluster.html (reference documentation) -->
409       <!--
410       <Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"/>
411       -->
412       <Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster" channelSendOptions="8">
413 
414             <Manager className="org.apache.catalina.ha.session.DeltaManager" 
415                 expireSessionsOnShutdown="false"
416                 notifyListenersOnReplication="true" />
417 
418             <Channel className="org.apache.catalina.tribes.group.GroupChannel">
419                 <Membership className="org.apache.catalina.tribes.membership.McastService" 
420                     address="228.0.0.4"
421                     port="45564" 
422                     frequency="500" 
423                     dropTime="3000" />
424                 <Receiver className="org.apache.catalina.tribes.transport.nio.NioReceiver" 
425                     address="auto"
426                     port="4000" 
427                     autoBind="100" 
428                     selectorTimeout="5000" 
429                     maxThreads="6" />
430 
431                 <Sender className="org.apache.catalina.tribes.transport.ReplicationTransmitter">
432                     <Transport className="org.apache.catalina.tribes.transport.nio.PooledParallelSender" />
433                 </Sender>
434                 <Interceptor className="org.apache.catalina.tribes.group.interceptors.TcpFailureDetector" />
435                 <Interceptor className="org.apache.catalina.tribes.group.interceptors.MessageDispatch15Interceptor" />
436             </Channel>
437 
438             <Valve className="org.apache.catalina.ha.tcp.ReplicationValve" filter="" />
439             <Valve className="org.apache.catalina.ha.session.JvmRouteBinderValve" />
440 
441             <Deployer className="org.apache.catalina.ha.deploy.FarmWarDeployer" 
442                 tempDir="/tmp/war-temp/"
443                 deployDir="/tmp/war-deploy/" 
444                 watchDir="/tmp/war-listen/" 
445                 watchEnabled="false" />
446 
447             <ClusterListener className="org.apache.catalina.ha.session.JvmRouteSessionIDBinderListener" />
448             <ClusterListener className="org.apache.catalina.ha.session.ClusterSessionListener" />
449         </Cluster>
450 
451       <!-- Use the LockOutRealm to prevent attempts to guess user passwords
452            via a brute-force attack -->
453       <Realm className="org.apache.catalina.realm.LockOutRealm">
454         <!-- This Realm uses the UserDatabase configured in the global JNDI
455              resources under the key "UserDatabase".  Any edits
456              that are performed against this UserDatabase are immediately
457              available for use by the Realm.  -->
458         <Realm className="org.apache.catalina.realm.UserDatabaseRealm"
459                resourceName="UserDatabase"/>
460       </Realm>
461 
462       <Host name="localhost"  appBase="webapps"
463             unpackWARs="true" autoDeploy="true">
464 
465         <!-- SingleSignOn valve, share authentication between web applications
466              Documentation at: /docs/config/valve.html -->
467         <!--
468         <Valve className="org.apache.catalina.authenticator.SingleSignOn" />
469         -->
470 
471         <!-- Access log processes all example.
472              Documentation at: /docs/config/valve.html
473              Note: The pattern used is equivalent to using pattern="common" -->
474         <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
475                prefix="localhost_access_log." suffix=".txt"
476                pattern="%h %l %u %t &quot;%r&quot; %s %b" />
477 
478       </Host>
479     </Engine>
480   </Service>
481    
482 </Server>

 

Apache Http Server与Tomcat6 的负载均衡(二)

标签:

原文地址:http://www.cnblogs.com/wangjuneng/p/4727634.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!