apache server和tomcat集群配置二:垂直负载
垂直负载就是同一个机器中的不同服务器之间的负载。跟水平负载(ip不一样的服务器之间的负载)的最大区别就是要修改tomcat的端口号,避免引起冲突。
还要注意apache中workers.properties的配置(worker.controller.sticky_session=false),这个一定要取消session的粘性,不然会一直发到同一个服务器中。
主要的修改点为
1.修改Tomcat 的ajp端口号,避免引起冲突
2.workers.properties的配置,worker.controller.sticky_session=false,取消粘性session。要说明的是worker.controller.sticky_session=1,等同于worker.controller.sticky_session=true.此处指定集群是否需要会话复制,如果设为true,则表明为会话粘性,不进行会话复制,当某用户的请求第一次分发到哪台Tomcat后,后继的请求会一直分发到此Tomcat服务器上处理;如果设为false,则表明会按照负载配置分发到相应的服务器中去。
3.打开tomcat的cluster标签,使其支持集群,在打开一个Tomcat之后,打开另一个tomcat下,如果出现以下的输出,则表示集群加入成功:
信息: Replication member added:org.apache.catalina.tribes.membership.MemberImpl[tcp://{169, 254, 81, 38}:4001,{169, 254, 81, 38},4001, alive=1029, securePort=-1, UDP Port=-1, id={44 -83 62 97 -76 55 65 79 -85 47 35 -124 127 75 26 26 }, payload={}, command={}, domain={}, ]
4.打开apache,测试集群,不同的tomcat节点下sessionId是一样的表示集群成功:


以下为worker.properties配置文件:
#下面是Tomcat实例列表,一个apache带一个或多个tomcat
worker.list=controller,tomcat1,tomcat2 #Tomcatbbs实例配置
worker.tomcat1.host=127.0.0.1
worker.tomcat1.port=
#ajp13 端口号,在tomcat下server.xml配置,默认8009
worker.tomcat1.type=ajp13
worker.tomcat1.lbfactor = #server的加权比重,值越高,分得的请求越多 #Tomcatwap实例配置
worker.tomcat2.host=127.0.0.1
worker.tomcat2.port=
worker.tomcat2.type=ajp13
#server的加权比重,值越高,分得的请求越多
worker.tomcat2.lbfactor = #========controller,负载均衡控制器========
worker.controller.type=lb
#指定分担请求的tomcat
worker.controller.balanced_workers=tomcat1,tomcat2
#设置用于负载均衡的server的session可否共享 :共享
worker.controller.sticky_session=false
tomcat的server.xml的主要配置:
<Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />
<!-- An Engine represents the entry point (within Catalina) that processes
every request. The Engine implementation for Tomcat stand alone
analyzes the HTTP headers included with the request, and passes them
on to the appropriate Host (virtual host).
Documentation at /docs/config/engine.html -->
<!-- You should set jvmRoute to support load-balancing via AJP ie :
<Engine name="Catalina" defaultHost="localhost" jvmRoute="jvm1">
-->
<Engine name="Catalina" defaultHost="localhost" jvmRoute="tomcat1">
<!--For clustering, please take a look at documentation at:
/docs/cluster-howto.html (simple how to)
/docs/config/cluster.html (reference documentation) -->
<!--
<Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"/>
-->
<!-- Use the LockOutRealm to prevent attempts to guess user passwords
via a brute-force attack -->
<Realm className="org.apache.catalina.realm.LockOutRealm">
<!-- This Realm uses the UserDatabase configured in the global JNDI
resources under the key "UserDatabase". Any edits
that are performed against this UserDatabase are immediately
available for use by the Realm. -->
<Realm className="org.apache.catalina.realm.UserDatabaseRealm"
resourceName="UserDatabase"/>
</Realm>
<Host name="localhost" appBase="webapps"
unpackWARs="true" autoDeploy="true">
<!-- SingleSignOn valve, share authentication between web applications
Documentation at: /docs/config/valve.html -->
<!--
<Valve className="org.apache.catalina.authenticator.SingleSignOn" />
-->
<!-- Access log processes all example.
Documentation at: /docs/config/valve.html
Note: The pattern used is equivalent to using pattern="common" -->
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
prefix="localhost_access_log" suffix=".txt"
pattern="%h %l %u %t "%r" %s %b" />
</Host>
</Engine>
另外一个tomcat的配置:
<!-- Define an AJP 1.3 Connector on port 8009 -->
<Connector port="9009" protocol="AJP/1.3" redirectPort="8443"/> <!-- An Engine represents the entry point (within Catalina) that processes
every request. The Engine implementation for Tomcat stand alone
analyzes the HTTP headers included with the request, and passes them
on to the appropriate Host (virtual host).
Documentation at /docs/config/engine.html --> <!-- You should set jvmRoute to support load-balancing via AJP ie :
<Engine name="Catalina" defaultHost="localhost" jvmRoute="jvm1">
-->
<Engine defaultHost="localhost" name="Catalina" jvmRoute="tomcat2"> <!--For clustering, please take a look at documentation at:
/docs/cluster-howto.html (simple how to)
/docs/config/cluster.html (reference documentation) --> <Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"/> <!-- Use the LockOutRealm to prevent attempts to guess user passwords
via a brute-force attack -->
<Realm className="org.apache.catalina.realm.LockOutRealm">
<!-- This Realm uses the UserDatabase configured in the global JNDI
resources under the key "UserDatabase". Any edits
that are performed against this UserDatabase are immediately
available for use by the Realm. -->
<Realm className="org.apache.catalina.realm.UserDatabaseRealm" resourceName="UserDatabase"/>
</Realm> <Host appBase="webapps" autoDeploy="true" name="localhost" unpackWARs="true"> <!-- SingleSignOn valve, share authentication between web applications
Documentation at: /docs/config/valve.html -->
<!--
<Valve className="org.apache.catalina.authenticator.SingleSignOn" />
--> <!-- Access log processes all example.
Documentation at: /docs/config/valve.html
Note: The pattern used is equivalent to using pattern="common" -->
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" pattern="%h %l %u %t "%r" %s %b" prefix="localhost_access_log." suffix=".txt"/> <Context docBase="TestCluster" path="/TestCluster" reloadable="true" source="org.eclipse.jst.jee.server:TestCluster"/></Host>
</Engine>
apache server和tomcat集群配置二:垂直负载的更多相关文章
- apache server和tomcat集群配置三:水平集群下的tomcat集群配置
在jsp文件中加入以下代码,用来测试是否共享session: SessionID: <%= session.getId() %> 之前尝试在linux中,但是因为模拟环境是虚拟机,虚拟机只 ...
- apache server和tomcat集群配置一:水平负载
下载apache server,最新链接http://archive.apache.org/dist/httpd/binaries/win32 当前实验版本2.2.4 下载apache tomca ...
- window xp Apache与Tomcat集群配置--转载
转载地址:http://www.cnblogs.com/obullxl/archive/2011/06/09/apache-tomcat-cluster-config.html 一. 环境说明 Win ...
- Linux+Apache+Tomcat集群配置
参考: http://blog.csdn.net/bluishglc/article/details/6867358# http://andashu.blog.51cto.com/8673810/13 ...
- Apache负载均衡与Tomcat集群配置学习(Windows环境)
本文主要参考自http://www.iteye.com/topic/985404?dhcc,经由实际操作配置操并记录而成. 由于最近的一个Java开发项目用到了Tomcat中间件作为web服务器,刚开 ...
- Apache + Tomcat集群配置详解 (1)
一.软件准备 Apache 2.2 : http://httpd.apache.org/download.cgi,下载msi安装程序,选择no ssl版本 Tomcat 6.0 : http://to ...
- (转)Apache+Tomcat集群配置
本文Apache+Tomcat集群配置 基于最新的Apache和Tomcat,具体是2011年4月20日最新的Tomcat和Apache集群和负载均衡配置. 准备环境 Apache Apache是ht ...
- Tomcat集群配置学习篇-----分布式应用
Tomcat集群配置学习篇-----分布式应用 现目前基于javaWeb开发的应用系统已经比比皆是,尤其是电子商务网站,要想网站发展壮大,那么必然就得能够承受住庞大的网站访问量:大家知道如果服务器访问 ...
- Nginx+Memcached+Tomcat集群配置(MSM--win7 64bit)
本次主要是在win7 64 上演示操作. web应用构建 Memcached安装配置启动 Tomcat配置 所需jar包 memcached-session-manager 序列化 contextxm ...
随机推荐
- iOS学习笔记之正则表达式
前言 基本上每个 App 都有登录注册功能,在登录注册时需要验证用户所输入的内容是否符合规定:有时要在字符串中查找并截取符合要求的字符串,这时就需要用到正则表达式.正则表达式看起来晦涩难懂,没有什么规 ...
- shitf+tab
在eclipse中,shitf+tab可以使代码向左移动.
- zhly
5. 百叶002 名字2008 1.新浪 阿里矢量图库账号 15031116087 名字2008 2.acdsee 账号 1173209945 同密码一样 3.zhly 我的名字2016 ...
- html5学习笔记(audio)
来源于<HTML5高级程序设计> audio api <audio controls> controls告诉浏览器显示播放控件 不指定 type 浏览器自解 oggMP3 ty ...
- DH02-策略模式
模式简介 面向对象的编程,并不是类越多越好,类的划分是为了封装,但分类的基础是抽象,具有相同属性和功能的对象的抽象集合才是类. 策略模式(Strategy)定义了算法家族,分别封装起来,让他们相互间可 ...
- 条款47:请使用traits class表示类型信息
在stl的算法中,我们的希望往往是根据不同的迭代器类型进行不同的更有效率的操作: template<typename IterT, typename DistT> void advance ...
- WinForm判断程序是否已经在运行,且只允许运行一个实例
我们开发WinFrom程序,很多时候都希望程序只有一个实例在运行,避免运行多个同样的程序,一是没有意义,二是容易出错. 为了更便于使用,笔者整理了一段自己用的代码,可以判断程序是否在运行,只运行一个实 ...
- New Concept English three (56)
The river which forms the eastern boundary of our farm has always played an important part in our li ...
- 超简单tensorflow入门优化程序&&tensorboard可视化
程序1 任务描述: x = 3.0, y = 100.0, 运算公式 x×W+b = y,求 W和b的最优解. 使用tensorflow编程实现: #-*- coding: utf-8 -*-) im ...
- 统计日志中ip出现的次数
grep -r 'GET /weixin/weixin_izp/index.html' ./chunyun.access.log > ~/access.log cat access.log |a ...