Apache2.2 Tomcat7 集群 session共享 [windows]
2021-04-25 03:29
标签:one more method 下载 getattr 1.3 oca 新建 system Apache2.2 Tomcat7 集群 session共享 下载: Apache2.2、apache-tomcat-7.0.42.zip、tomcat-connectors-1.2.37-windows-i386-httpd-2.2.x.zip【mod_jk】 分别解压缩Apache2.2、apache-tomcat-7.0.42.zip、tomcat-connectors-1.2.37-windows-i386-httpd-2.2.x.zip 此处:C:\Apache2.2、C:\tomcat\tomcat71、C:\tomcat\tomcat72 copy从comcat-connectors-1.2.37-windows-i386-httpd-2.2.x.zip解压缩后的文件mod_jk.so至C:\Apache2.2\modules中。 在C:\Apache2.2\conf下新建文件workers.properties、内容如下: 在C:\Apache2.2\conf下新建文件mod_jk.conf、内容如下: 修改C:\Apache2.2\conf\httpd.conf,在最后一行,添加: 此时,apache修改完毕; 接下来修改tomcat、修改tomcat1的C:\tomcat\tomcat71\conf\server.xml 主要是修改端口,使其同tomcat1的端口避免有冲突。 创建test文件夹,在其下新建test.jsp,内容如下: 将test文件夹分别copy至C:\tomcat\tomcat71\webapps、C:\tomcat\tomcat72\webapps下。 分别启动或重启tomcat1、tomcat2、apache、无先后顺序。 浏览器输入: http://localhost/test/test.jsp 观察效果。 Done. ----------------- Apache2.2 Tomcat7 集群 session共享 [windows] 标签:one more method 下载 getattr 1.3 oca 新建 system 原文地址:http://www.cnblogs.com/syc001/p/3232343.html#server 列表
worker.list = controller,tomcat1,tomcat2
#========tomcat1========
worker.tomcat1.port=8009 #注意这是 ajp1.3 端口号,在tomcat下server.xml配置,默认8009。不是tomcat的web端口
worker.tomcat1.host=localhost #tomcat的主机地址,如不为本机,请填写ip地址
worker.tomcat1.type=ajp13
worker.tomcat1.lbfactor = 1 #server的加权比重,值越高,分得的请求越多
#========tomcat2========
worker.tomcat2.port=9009
worker.tomcat2.host=localhost
worker.tomcat2.type=ajp13
worker.tomcat2.lbfactor = 1
#========controller,负载均衡控制器========
worker.controller.type=lb
worker.controller.balanced_workers=tomcat1,tomcat2 #指定分担请求的tomcat
#session复制模式
worker.controller.sticky_session=false
worker.controller.sticky_session_force=1
#sticky模式,即黏性会话模式
#worker.controller.sticky_session=1
#加载mod_jk Module
LoadModule jk_module modules/mod_jk.so
#指定 workers.properties文件路径
JkWorkersFile conf/workers.properties
#指定那些请求交给tomcat处理,"controller"为在workers.propertise里指定的负载分配控制器名
JkMount /*.jsp controller
include "C:\Apache2.2\conf\mod_jk.conf"
Engine name="Catalina" defaultHost="localhost" jvmRoute="tomcat1">
...
Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"/>
修改tomcat2的server.xml文件Server port="9005" shutdown="SHUTDOWN">
。。。
Connector port="9090" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />
。。。
Connector port="9009" protocol="AJP/1.3" redirectPort="8443" />
。。。
Engine name="Catalina" defaultHost="localhost" jvmRoute="tomcat2">
。。。
Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"/>
@ page contentType="text/html; charset=GBK"%>
@ page import="java.util.*"%>
html>
head>
title>Cluster App Testtitle>
head>
body>
Server Info:
out.println(request.getLocalAddr() + " : " + request.getLocalPort()
+ "
");
%>
out.println("
ID " + session.getId() + "
");
// if have new Session attr set
String dataName = request.getParameter("dataName");
if (dataName != null && dataName.length() > 0) {
String dataValue = request.getParameter("dataValue");
session.setAttribute(dataName, dataValue);
}
out.println("Session list
");
System.out.println("=============tomcat 1===============");
Enumeration e = session.getAttributeNames();
while (e.hasMoreElements()) {
String name = (String) e.nextElement();
String value = session.getAttribute(name).toString();
out.println(name + " = " + value + "
");
System.out.println(name + " = " + value);
}
%>
form action="test.jsp" method="POST">
name:input type=text size=20 name="dataName"> br>
value:input type=text size=20 name="dataValue"> br> input
type=submit>
form>
body>
html>
文章标题:Apache2.2 Tomcat7 集群 session共享 [windows]
文章链接:http://soscw.com/index.php/essay/79233.html