标签:red down while nts lin false director classname pac
和之前 tomcat整合apache中的一样,这次集群用的软件版本号例如以下:
jdk 7 ,tomcat 6.0.44,apache2.2.4,mod_jk的版本号是1.2.26。
更改apache下的httpd.conf
先把listen 80改成listen 81或者别的,大家都知道,80这个port常常被占用的。include "C:\Program Files (x86)\Apache Software Foundation\Apache2.2\conf\mod_jk.conf"之后 在conf文件夹下再建立一个mod_jk.conf,写上
LoadModule jk_module modules/mod_jk.so JkWorkersFile conf/workers.properties #指定那些请求交给tomcat处理,"controller"为在workers.propertise里指定的负载分配控制器名 JkMount /*.jsp controller假设看完了我之前的那个博客,mod_jk的内容就非常easy理解了。
大家看到conf/workers.properties这行代码了,非常easy,相对路径conf下建立workers.properties
#server worker.list = controller #========tomcat1======== worker.tomcat1.port=18009 worker.tomcat1.host=localhost worker.tomcat1.type=ajp13 worker.tomcat1.lbfactor = 1 #========tomcat2======== worker.tomcat2.port=28009 worker.tomcat2.host=localhost worker.tomcat2.type=ajp13 worker.tomcat2.lbfactor = 1 #========tomcat3======== worker.tomcat3.port=38009 worker.tomcat3.host=localhost worker.tomcat3.type=ajp13 worker.tomcat3.lbfactor = 1 #========controller,负载均衡控制器======== worker.controller.type=lb worker.controller.balanced_workers=tomcat1,tomcat2,tomcat3 worker.controller.sticky_session=false worker.controller.sticky_session_force=1 #worker.controller.sticky_session=1OK搞定
lbfactor是干什么的?
假设tomcat1,tomcat2,tomcat3的lbfactor各自是2,5,4那么全部的请求中2/11会分配给tomcat1处理,5/11会给tomcat2....
<Connector port="8080" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" /> ....... <Connector port="8009" protocol="AJP/1.3" redirectPort="8443" /> ....... <Server port="8005" shutdown="SHUTDOWN">普通情况下,我们修改的都是8080,也就是支持http1.1协议的这端口。
<Engine name="Catalina" defaultHost="localhost" jvmRoute="tomcat1">
<Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"/>
mytest.jsp <%@ page contentType="text/html; charset=GBK" %> <%@ page import="java.util.*" %> <html><head><title>Cluster App Test</title></head> <body> Server Info: <% out.println(request.getLocalAddr() + " : " + request.getLocalPort()+"<br>");%> <% out.println("<br> ID " + session.getId()+"<br>"); // 假设有新的 Session 属性设置 String dataName = request.getParameter("dataName"); if (dataName != null && dataName.length() > 0) { String dataValue = request.getParameter("dataValue"); session.setAttribute(dataName, dataValue); } out.println("<b>Session 列表</b><br>"); System.out.println("============================"); Enumeration e = session.getAttributeNames(); while (e.hasMoreElements()) { String name = (String)e.nextElement(); String value = session.getAttribute(name).toString(); out.println( name + " = " + value+"<br>"); System.out.println( name + " = " + value); } %> <form action="mytest.jsp" method="POST"> 名称:<input type=text size=20 name="dataName"> <br> 值:<input type=text size=20 name="dataValue"> <br> <input type=submit> </form> </body> </html>然后我们訪问
以上为charyle的理解。详细评述见http://www.iteye.com/topic/1017961
把mod_jk改成以下的样子。
LoadModule jk_module modules/mod_jk.so JkWorkersFile conf/workers.properties # 设置虚拟主机,定义port为81 <VirtualHost 127.0.0.1:81> ServerName 127.0.0.1 DocumentRoot "E:/cluster/tomcat1/webapps" #定义站点项目所在路径,把路径指向 tomcat 中的默认站点文件夹 DirectoryIndex index.html index.htm index.jsp ErrorLog logs/shsc-error_log.txt #指定那些请求交给tomcat处理,"controller"为在workers.propertise里指定的负载分配控制器名 JkMount /*.jsp controller </VirtualHost>
///////////下面是2016-8-16日改动
非常羞愧,发现大家用的都是tomcat8或tomcat7,我这还是6,可是也懒得再去升级了
大家看这个博客吧:
http://blog.csdn.net/flyliuweisky547/article/details/21293071
上面的是tomcat8与apache的集群
假设tomcat要把session放到redis里,再看看以下这博客
http://blog.csdn.net/caiwenfeng_for_23/article/details/45666831
标签:red down while nts lin false director classname pac
原文地址:http://www.cnblogs.com/zhchoutai/p/7397094.html