大家好,又见面了,我是全栈君。
mod_jk: mod_jk_1.2.28_httpd_2.2.3.so (1个)
tomcat: tomcat5.5.7(2个)
2.把mod_jk_1.2.28_httpd_2.2.3.so拷入apache安装目录modules下。
3.在apache的安装目录下找到httpd.conf文件,我的目录为D:\Apache2.2\conf。
在该目录下新建mod_jk.conf文件,内容如上:
#============================================
#加载mod_jk Module
LoadModule jk_module modules/mod_jk-apache-2.0.55.so
#指定 workers.properties文件路径(在第三步我们建立该文件)
JkWorkersFile conf/workers.properties
#指定那些请求交给tomcat处理,”controller”为在workers.propertise里指定的负载分配控制器
JkMount /*.jsp controller
#==============================================
修改httpd.conf, 在文件最后加上下面一句话:
include “D:\Apache2.2\conf\mod_jk.conf”
3.同上一目录新建workers.properties,内容如下:
worker.list = controller,tomcat1,tomcat2 #server 列表
#========tomcat1========
worker.tomcat1.port=8009 #ajp13 端口号,在tomcat下server.xml配置,默认8009
worker.tomcat1.host=localhost #tomcat的主机地址,如不为本机,请填写ip地址
worker.tomcat1.type=ajp13
worker.tomcat1.lbfactor = 1 #server的加权比重,值越高,分得的请求越多
#========tomcat2========
worker.tomcat2.port=9009 #ajp13 端口号,在tomcat下server.xml配置,默认8009
worker.tomcat2.host=localhost #tomcat的主机地址,如不为本机,请填写ip地址
worker.tomcat2.type=ajp13
worker.tomcat2.lbfactor = 1 #server的加权比重,值越高,分得的请求越多
#========controller,负载均衡控制器========
worker.controller.type=lb
worker.controller.balanced_workers=tomcat1,tomcat2 #指定分担请求的tomcat
worker.controller.sticky_session=1 #会话粘性,大于0表示同一会有同一TOMCAT处理
4.修改TOMCAT的配置,这里主要是防止端口冲突,如果TOMCAT位于不同主机上,可SHIP该步。
tomcat1: <Server port=”8005″ shutdown=”SHUTDOWN”>
<!– Define a non-SSL HTTP/1.1 Connector on port 8080 –>
<Connector port=”8080″ maxHttpHeaderSize=”8192″
maxThreads=”150″ minSpareThreads=”25″ maxSpareThreads=”75″
enableLookups=”false” redirectPort=”8443″ acceptCount=”100″
connectionTimeout=”20000″ disableUploadTimeout=”true” />
tomcat2: <Server port=”8005″ shutdown=”SHUTDOWN”>
<!– Define a non-SSL HTTP/1.1 Connector on port 8080 –>
<Connector port=”8090″ maxHttpHeaderSize=”8192″
maxThreads=”150″ minSpareThreads=”25″ maxSpareThreads=”75″
enableLookups=”false” redirectPort=”8443″ acceptCount=”100″
connectionTimeout=”20000″ disableUploadTimeout=”true” />
tomcat1: <Cluster className=”org.apache.catalina.cluster.tcp.SimpleTcpCluster”
managerClassName=”org.apache.catalina.cluster.session.DeltaManager”
expireSessionsOnShutdown=”false”
useDirtyFlag=”true”
notifyListenersOnReplication=”true”>
className=”org.apache.catalina.cluster.mcast.McastService”
mcastAddr=”228.0.0.4″
mcastPort=”45564″
mcastFrequency=”500″
mcastDropTime=”3000″/>
className=”org.apache.catalina.cluster.tcp.ReplicationListener”
tcpListenAddress=”auto”
tcpListenPort=”4001″
tcpSelectorTimeout=”100″
tcpThreadCount=”6″/>
className=”org.apache.catalina.cluster.tcp.ReplicationTransmitter”
replicationMode=”pooled”
ackTimeout=”15000″
waitForAck=”true”/>
filter=”.*\.gif;.*\.js;.*\.jpg;.*\.png;.*\.htm;.*\.html;.*\.css;.*\.txt;”/>
<Deployer className=”org.apache.catalina.cluster.deploy.FarmWarDeployer”
tempDir=”/tmp/war-temp/”
deployDir=”/tmp/war-deploy/”
watchDir=”/tmp/war-listen/”
watchEnabled=”false”/>
<ClusterListener className=”org.apache.catalina.cluster.session.ClusterSessionListener”/>
</Cluster>
tomcat2: 同上,tcpListenPort=”4001″ 这里改为tcpListenPort=”4002″
6.添加<distributable/>到web.xml.
例:<?xml version=”1.0″ encoding=”UTF-8″?>
<web-app version=”2.5″ xmlns=”
http://java.sun.com/xml/ns/javaee”
xmlns:xsi=”
http://www.w3.org/2001/XMLSchema-instance”
xsi:schemaLocation=”
http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd“>
<distributable/>
….
发布者:全栈程序员-用户IM,转载请注明出处:https://javaforall.cn/107896.html原文链接:https://javaforall.cn
【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛
【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...