刚看视频学的,怕丢,记录下来
第一步:下载mod_jk文件
https://download.csdn.net/download/ac_mock/10329518
然后将他放到apache的modules目录中
第二步:在apache的conf目录中创建mod_jk.conf、workers.properties两个文件。
第三步:mod_jk.conf中的内容:
#加载mod_jk Module
LoadModule jk_module modules/mod_jk.so
#指定workers.properties文件路径
JkWorkersFile conf/workers.properties
#指定那些请求交给tomcat处理,"controller"为在workers.propertise里指定的负载分配控制器名
JkMount /* controller
第四步:workers.properties中的内容
#server
worker.list = controller
#========tomcat1========
#ajp13端口号,在tomcat下server.xml配置,默认8009
worker.tomcat1.port=9009
#tomcat的主机地址,如不为本机,请填写ip地址
worker.tomcat1.host=localhost
#协议类型
worker.tomcat1.type=ajp13
#server的加权比重,值越高,分得的请求越多。lbfactor是负载平衡因数(Load Balance Factor)
worker.tomcat1.lbfactor=1
#========tomcat2========
worker.tomcat2.port=10009(tomcat中AJP13端口)
worker.tomcat2.host= localhost
worker.tomcat2.type=ajp13
worker.tomcat2.lbfactor=1
#========controller,负载均衡控制器========
#负载均衡控制器类型,lbfactor是负载平衡因数(Load Balance Factor)
worker.controller.type=lb
#指定分担请求的tomcat列表
worker.controller.balanced_workers=tomcat1,tomcat2
#粘性session(默认是打开的) 当该属性值=true(或1)时,代表session是粘性的,即同一session在集群中的同一个节点上处理,session不跨越节点。在集群环境中,一般将该值设置为false
worker.controller.sticky_session=false
#设置用于负载均衡的server的session可否共享
worker.controller.sticky_session_force=1
第五步:配置tomcat 将下面的配置信息粘贴到server.xml中的Engine节点中(需要注意的是:Engine标签中需要写上:jvmRoute="tomcat2" tomcat2为workers.properties配置的(不要忘记修改端口))
<Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster" channelSendOptions="8"/>
<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="4000"
autoBind="100"
selectorTimeout="5000"
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"/>
</Channel>
<Valve className="org.apache.catalina.ha.tcp.ReplicationValve" filter=""/>
<Valve className="org.apache.catalina.ha.session.JvmRouteBinderValve"/>
<Deployer className="org.apache.catalina.ha.deploy.FarmWarDeployer"
tempDir="/tmp/war-temp/"
deployDir="/tmp/war-deploy/"
watchDir="/tmp/war-listen/"
watchEnabled="false"/>
<ClusterListener className="org.apache.catalina.ha.session.JvmRouteSessionIDBinderListener"/>
<ClusterListener className="org.apache.catalina.ha.session.ClusterSessionListener"/>
然后启动tomcat就Ok啦,访问即可(亲自实验,可以使用)