软件:1个apache,2个tomcat
module包:mod_jk.so(下载地址:http://tomcat.apache.org/download-connectors.cgi)
下载文件解压即可得到mod_jk.so 并放置到apache/module下
apache/conf/http.cnf
LoadModule jk_module modules/mod_jk.so JkWorkersFile conf/workers.properties JkLogFile logs/mod_jk.log JkLogLevel debug JkMount /*.jsp loadbalancer #JkMount /j2eeTest/* loadbalancer
conf文件夹下新加workers.properties文件
worker.list = worker1,worker2,loadbalancer worker.worker1.port = 8109 worker.worker1.host = localhost worker.worker1.type = ajp13 worker.worker1.lbfactor = 300 worker.worker2.port = 8009 worker.worker2.host = localhost worker.worker2.type = ajp13 worker.worker2.lbfactor = 100 worker.loadbalancer.type = lb worker.loadbalancer.balanced_workers = worker1,worker2 worker.loadbalancer.sticky_session=false worker.loadbalancer.sticky_session_force = false
由于本地测试,tomcat端口不能重复 一个tomcat的8080改成别的
端口有改动的主要文件配置conf/server.xml(80相关端口号全部改成81)
<Server port="8105" shutdown="SHUTDOWN"> <Connector port="8180" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" /> <Connector port="8109" protocol="AJP/1.3" redirectPort="8443" /> <Engine name="Catalina" defaultHost="localhost" jvmRoute="worker1">
端口不需要改动的(80)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" /> <Engine name="Catalina" defaultHost="localhost" jvmRoute="worker2">
测试:新建一个web项目
j2eeTest 测试jsp
<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <% System.out.println("1111");%> <title>Insert title here</title> </head> <body> <b>Hello : <%=request.getAttribute("User") %></b> </body> </html>
连续刷新12次,查看输出结果为3:1