windows xp下Apache2.2.11整合Tomcat6.0.20(集群模式&无集群模式)
一、使用mod_jk.so方式
1.无集群方式
1)下载、安装Apache2.2.11,Tomcat6.0.20略
2)下载mod_jk-1.2.28-httpd-2.2.3.so改名为mod_jk.so放到%APACHE_HOME%\modules下(不改名会出错,不知道为什么)
3)打开%APACHE_HOME%\conf\httpd.conf,找到最末一个Include节点,加入mod-jk_nocluster.conf
4)在%APACHE_HOME%\conf\新建mod-jk_nocluster.conf,加入以下内容:
LoadModule jk_module modules/mod_jk.so
1.无集群方式
1)下载、安装Apache2.2.11,Tomcat6.0.20略
2)下载mod_jk-1.2.28-httpd-2.2.3.so改名为mod_jk.so放到%APACHE_HOME%\modules下(不改名会出错,不知道为什么)
3)打开%APACHE_HOME%\conf\httpd.conf,找到最末一个Include节点,加入mod-jk_nocluster.conf
4)在%APACHE_HOME%\conf\新建mod-jk_nocluster.conf,加入以下内容:
LoadModule jk_module modules/mod_jk.so
JkWorkersFile conf/workers_nocluster.properties
JkLogFile logs/mod_jk_nocluster.log
JkLogLevel info
JkLogStampFormat "[%a %b %d %H:%M:%S %Y] "
JkOptions +ForwardKeySize +ForwardURICompat -ForwardDirectories
JkRequestLogFormat "%w %V %T"
JkMount /* ajp13
#关掉主机Lookup,如果为on,很影响性能,可以有10多秒钟的延迟。
HostnameLookups Off
HostnameLookups Off
5)在%APACHE_HOME%\conf\新建workers_nocluster.properties,加入以下内容:
worker.list=ajp13
worker.maintain=60
worker.list=ajp13
worker.maintain=60
worker.ajp13.port=8009
worker.ajp13.host=localhost
worker.ajp13.type=ajp13
worker.ajp13.lbfactor=1
6)启动Apache,tomcat,在地址栏输入http://localhost看到tomcat画面成功了
2.使用集群(以两个tomcat为例)
1)、2)同上
3)打开%APACHE_HOME%\conf\httpd.conf,找到最末一个Include节点,更改mod-jk_nocluster.conf为mod-jk_cluster.conf
worker.ajp13.host=localhost
worker.ajp13.type=ajp13
worker.ajp13.lbfactor=1
6)启动Apache,tomcat,在地址栏输入http://localhost看到tomcat画面成功了
2.使用集群(以两个tomcat为例)
1)、2)同上
3)打开%APACHE_HOME%\conf\httpd.conf,找到最末一个Include节点,更改mod-jk_nocluster.conf为mod-jk_cluster.conf
4)在%APACHE_HOME%\conf\新建mod-jk_cluster.conf,加入以下内容:
LoadModule jk_module modules/mod_jk.so
LoadModule jk_module modules/mod_jk.so
JkWorkersFile conf/workers_cluster.properties
JkLogFile logs/mod_jk_cluster.log
JkLogLevel info
JkLogStampFormat "[%a %b %d %H:%M:%S %Y] "
JkOptions +ForwardKeySize +ForwardURICompat -ForwardDirectories
JkRequestLogFormat "%w %V %T"
JkMount /* controller
HostnameLookups Off
5)在%APACHE_HOME%\conf\新建workers_cluster.properties,加入以下内容:
worker.list = controller,tomcat1,tomcat2 #server 列表
#========tomcat1========
worker.tomcat1.port=18109 #ajp13 端口号,在tomcat下server.xml配置,默认8009
worker.tomcat1.host=localhost #tomcat的主机地址,如不为本机,请填写ip地址
worker.tomcat1.type=ajp13
worker.tomcat1.lbfactor = 1 #server的加权比重,值越高,分得的请求越多
#worker.tomcat1.redirect=tomcat2 #是在cluster环境之下,当tomcat1挂点或无回应,jk会将request导向这个指令指定的其他worker作处理。
#========tomcat2========
worker.tomcat2.port=18209 #ajp13 端口号,在tomcat下server.xml配置,默认8009
worker.tomcat2.host=localhost #tomcat的主机地址,如不为本机,请填写ip地址
worker.tomcat2.type=ajp13
worker.tomcat2.lbfactor = 1 #server的加权比重,值越高,分得的请求越多
#worker.tomcat2.activation=disabled #
5)在%APACHE_HOME%\conf\新建workers_cluster.properties,加入以下内容:
worker.list = controller,tomcat1,tomcat2 #server 列表
#========tomcat1========
worker.tomcat1.port=18109 #ajp13 端口号,在tomcat下server.xml配置,默认8009
worker.tomcat1.host=localhost #tomcat的主机地址,如不为本机,请填写ip地址
worker.tomcat1.type=ajp13
worker.tomcat1.lbfactor = 1 #server的加权比重,值越高,分得的请求越多
#worker.tomcat1.redirect=tomcat2 #是在cluster环境之下,当tomcat1挂点或无回应,jk会将request导向这个指令指定的其他worker作处理。
#========tomcat2========
worker.tomcat2.port=18209 #ajp13 端口号,在tomcat下server.xml配置,默认8009
worker.tomcat2.host=localhost #tomcat的主机地址,如不为本机,请填写ip地址
worker.tomcat2.type=ajp13
worker.tomcat2.lbfactor = 1 #server的加权比重,值越高,分得的请求越多
#worker.tomcat2.activation=disabled #
#========controller,负载均衡控制器========
worker.controller.type=lb
worker.controller.balanced_workers=tomcat1,tomcat2 #指定分担请求的tomcat
worker.controller.sticky_session=1
6)修改tomcat1配置文件server.xml,tomcat2配置修改地方同tomcat1,仅需注意相关端口号,在同一台服务器上时不能重复
以下列出需修改节点地方:
#默认为8005
<Server port="8105" shutdown="SHUTDOWN">
#默认8080,此处可根据需求修改线程并发等
<Connector port="8180" ...>
#默认8009,
<Connector port="8109" protocol="AJP/1.3" redirectPort="8443" />
#name可为Standalone
<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"
mcastBindAddress="127.0.0.1" #安装了VPN、svn等,会导致绑定失败需加上此句
address="228.0.0.4" port="45564"
frequency="500" dropTime="3000" />
<Receiver
className="org.apache.catalina.tribes.transport.nio.NioReceiver"
address="auto" port="4001" 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;" />
worker.controller.type=lb
worker.controller.balanced_workers=tomcat1,tomcat2 #指定分担请求的tomcat
worker.controller.sticky_session=1
6)修改tomcat1配置文件server.xml,tomcat2配置修改地方同tomcat1,仅需注意相关端口号,在同一台服务器上时不能重复
以下列出需修改节点地方:
#默认为8005
<Server port="8105" shutdown="SHUTDOWN">
#默认8080,此处可根据需求修改线程并发等
<Connector port="8180" ...>
#默认8009,
<Connector port="8109" protocol="AJP/1.3" redirectPort="8443" />
#name可为Standalone
<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"
mcastBindAddress="127.0.0.1" #安装了VPN、svn等,会导致绑定失败需加上此句
address="228.0.0.4" port="45564"
frequency="500" dropTime="3000" />
<Receiver
className="org.apache.catalina.tribes.transport.nio.NioReceiver"
address="auto" port="4001" 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;" />
<ClusterListener
className="org.apache.catalina.ha.session.ClusterSessionListener" />
</Cluster>
在<Host>节点加入
<Deployer className="org.apache.catalina.ha.deploy.FarmWarDeployer"
tempDir="/tmp/war-temp/"
deployDir="/tmp/war-deploy/"
watchDir="/tmp/war-listen/"
watchEnabled="false"/>
7)将Web应用打成war包放到每一个webapps下,确保web.xml中加了
<display-name>xxx/display-name>
<distributable />
或者直接放到tomcat的web.xml中
至此mod-jk.so方式全配好了,启动服务就OK了!
className="org.apache.catalina.ha.session.ClusterSessionListener" />
</Cluster>
在<Host>节点加入
<Deployer className="org.apache.catalina.ha.deploy.FarmWarDeployer"
tempDir="/tmp/war-temp/"
deployDir="/tmp/war-deploy/"
watchDir="/tmp/war-listen/"
watchEnabled="false"/>
7)将Web应用打成war包放到每一个webapps下,确保web.xml中加了
<display-name>xxx/display-name>
<distributable />
或者直接放到tomcat的web.xml中
至此mod-jk.so方式全配好了,启动服务就OK了!