2012-08-30 63 views
1

我想用mod_jk配置Apache负载平衡解决方案。群集工作但不负载平衡。Apache mod_jk负载平衡不工作,但故障转移工作

我有我的笔记本电脑上运行的Apache httpd 2.2服务器。我有两个VMWare虚拟机客户操作系统。这三个都是窗户。 VMware机器承载为Web应用程序提供服务的Apache Tomcat服务器。我使用mod_jk配置了httpd.conf文件,并使用worker信息配置了worker属性文件。我可以使用URL:http://localhost/Web-application访问我的Web应用程序。如果我停止一台服务器,则应用程序将由另一台服务器提供。然而,不是两者同时。一些提取物下面:

httpd.conf文件:

LoadModule jk_module modules/mod_jk.so 
JkWorkersFile conf/workers.properties 
JkLogFile "logs/mod_jk.log" 
JkLogLevel info 
JkMount /MovieBooking loadbalancer 
JkMount /MovieBooking/* loadbalancer 

workers.properties文件

workers.tomcat_home=/worker1 
workers.java_home=$JAVA_HOME 
worker.list=loadbalancer,jkstatus,worker1,worker2 

#Declare Tomcat server workers 1 through n 

worker.loadbalancer.type=lb 
worker.loadbalancer.balance_workers=worker1,worker2 
worker.loadbalancer.sticky_session=1 

worker.worker1.type=ajp13 
worker.worker1.host=192.168.200.244 
worker.worker1.port=8109 
worker.worker1.lbfactor=1 

worker.worker2.type=ajp13 
worker.worker2.port=8109 
worker.worker2.host=192.168.200.243 
worker.worker2.lbfactor=1 

worker.jkstatus.type=status 

我还设置中的jvmRoute在server.xml文件中的这些服务器上:

Server.xml

<Engine name="Catalina" defaultHost="localhost" jvmRoute="worker1">   
    <Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"/> 

是否需要更多的提取物可以上传他们

回答

0

你配置的负载均衡的方式(找OK我)与粘性会话意味着一旦创建了会话,后续请求将被引导到相同的Tomcat实例。您可以通过查看应附加.worker1.worker2的会话cookie值来认识到这一点。 Apache HTTPD使用该后缀来决定将哪个Tomcat实例发送到传入的请求。

如果没有会话cookie,请按循环方式在可用的Tomcat中分发请求。因此,为了测试负载平衡,您通常需要多个浏览器实例持有不同的会话Cookie。或者尝试设置sticky_session=false以查看全部请求转发的循环方式。

1

Apache的

  • 所有会话属性必须实现java.io.Serializable
  • 取消注释在server.xml中
  • 群集元素如果您已定义的自定义集群阀门,确保如果Tomcat实例在同一台计算机上运行,​​请确保tcpListenPort属性对于每个实例都是唯一的,在大多数情况下,Tomcat足够智能,通过自动检测范围为4000-4100的可用端口来解决此问题确保您的web.xml包含元素
  • 如果您使用的是mod_jk,请确保将jvmRoute属性设置为并且jvmRoute属性值与workers.properties中的worker名称匹配
  • 确保所有节点具有相同的时间并与NTP服务同步! 确保您的负载均衡器配置为粘滞会话模式。

我会先尝试 确保是的jvmRoute OK

Session stickyness is not implemented using a tracking table for sessions. Instead each Tomcat instance gets an individual name and adds its name at the end of the session id. When the load balancer sees a session id, it finds the name of the Tomcat instance and sends the request via the correct member worker. For this to work you must set the name of the Tomcat instances as the value of the jvmRoute attribute in the Engine element of each Tomcat's server.xml. The name of the Tomcat needs to be equal to the name of the corresponding load balancer member. In the above example, Tomcat on host "myhost1" needs jvmRoute="worker1", Tomcat on host "myhost2" needs jvmRoute="worker2".

你的tomcat 2的jvmRoute应该是 “worker2”

相关问题