Windows XP Windows 7 Windows 2003 Windows Vista Windows教程綜合 Linux 系統教程
Windows 10 Windows 8 Windows 2008 Windows NT Windows Server 電腦軟件教程
 Windows教程網 >> Linux系統教程 >> Linux教程 >> Liunx下Apache和Tomcat集群

Liunx下Apache和Tomcat集群

日期:2017/2/7 14:40:07      編輯:Linux教程
 

所需組件包

jdk-1_5_0-linux-i586-rpm.bin ----Jkd

apache-tomcat-5.5.27.tar.gz ---Tomcat

httpd-2.0.63.tar.gz ---Apache

jakarta-tomcat-connectors-jk-1.2.1-src.tar.gz ---Apache和Tomcat連接器

 

安裝

1、 安裝Tomcat,Apache , mod_jk 上一篇文章已經講解

文件配置

 

配置
1、 修改Apache2/conf/httpd.conf文件

在最後加入

LoadModule jk_module modules/mod_jk.so
JkWorkersFile "conf/workers.properties"
JkLogFile "logs/mod_jk.log"
JkLogLevel Info

JkMount /*. workers


 


2、在apache2/conf/目錄下新建workers.properties文件內容如下

worker.list=workers,tomcat1,tomcat2

#========tomcat1========

worker.tomcat1.type=ajp13
worker.tomcat1.port=8009 #ajp13 端口號,在tomcat下server.xml配置,默認8009
worker.tomcat1.host=localhost #tomcat的主機地址,如不為本機,請填寫ip地址
worker.tomcat1.lbfactor=1
worker.tomcat1.fail_on_status=-500,-503,404

#========tomcat2========
worker.tomcat2.type=ajp13
worker.tomcat2.port=8010
worker.tomcat2.host=localhost
worker.tomcat2.lbfactor=1
worker.tomcat2.fail_on_status=500,503,-404

#========controller,負載均衡控制器========
worker.workers.type=lb
worker.retries=5
worker.workers.balance_workers=tomcat1,tomcat2
worker.workers.sticky_session=true
worker.workers.sticky_session_force=false

 


 

3、解決沖突,如果在同一台電腦上部署多個Tomcat 就要修改Tomcat端口, < xmlnamespace prefix ="o" ns ="urn:schemas-microsoft-com:office:office" />

找到tomcat/conf/server.xml文件 中如下地方

<Server port="8005" shutdown="SHUTDOWN">

<Connector port="8080" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" />

<Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />

修改為

8005 -------> 8015

8080 ------> 8081

8009------.>8019

注:<Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />

中的端口要與workers.properties文件中的worker.tomcat2.port=8019 配置一致

 

4 配置Session復制

1》分別找到每個Tomcat/conf/server.xl中

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

修改為

<Engine name="Catalina" defaultHost="localhost" jvmRoute="tomcat1">

<Engine name="Catalina" defaultHost="localhost" jvmRoute="tomcat2">

2》分別在每個Tomcat/conf/server.xml的

<Engine name="Catalina" defaultHost="localhost" jvmRoute="tomcat1">

標簽中加入

<Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"

channelSendOptions="6">

 

<!--

<Manager className="org.apache.catalina.ha.session.BackupManager"

expireSessionsOnShutdown="false"

notifyListenersOnReplication="true"

mapSendOptions="6"/>

-->

<Manager className="org.apache.catalina.ha.session.DeltaManager"

expireSessionsOnShutdown="false"

notifyListenersOnReplication="true"/>

 

<Channel className="org.apache.catalina.tribes.group.GroupChannel">

<Membership className="org.apache.catalina.tribes.membership.McastService"

address="228.0.0.4"

port="45564"

frequency="500"

dropTime="3000"/>

<Receiver className="org.apache.catalina.tribes.transport.nio.NioReceiver"

address="auto"

port="5002"

selectorTimeout="100"

maxThreads="6"/>

 

<Sender className="org.apache.catalina.tribes.transport.ReplicationTransmitter">

<Transport className="org.apache.catalina.tribes.transport.nio.PooledParallelSender"/>

</Sender>

<Interceptor className="org.apache.catalina.tribes.group.interceptors.TcpFailureDetector"/>

<Interceptor className="org.apache.catalina.tribes.group.interceptors.MessageDispatch15Interceptor"/>

<Interceptor className="org.apache.catalina.tribes.group.interceptors.ThroughputInterceptor"/>

</Channel>

 

<Valve className="org.apache.catalina.ha.tcp.ReplicationValve"

filter=".*\.gif;.*\.js;.*\.jpg;.*\.png;.*\.htm;.*\.html;.*\.css;.*\.txt;"/>

 

<Deployer className="org.apache.catalina.ha.deploy.FarmWarDeployer"

Copyright © Windows教程網 All Rights Reserved