设为首页 收藏本站
查看: 603|回复: 0

[经验分享] Tomcat配置集群并配置负载均衡器Apache或者Nginx

[复制链接]

尚未签到

发表于 2016-12-28 11:15:42 | 显示全部楼层 |阅读模式
1、Tomcat集群配置关键点:
////////////////////////begin///////////////
<1>All your session attributes must implement java.io.Serializable
   ==>session中存储的对象必须是可序列化的,即实现类【java.io.Serializable】
<2>Uncomment the Cluster element in server.xml
   ==>在server.xml中使用Cluster元素;
<3>If you have defined custom cluster valves, make sure you have the ReplicationValve defined as well under the Cluster element in server.xml
   ==>如果定义了自定义的cluster值,确保在server.xml的元素【ReplicationValve】中包含进去;
<4>If your Tomcat instances are running on the same machine, make sure the tcpListenPort attribute is unique for each instance,
   in most cases Tomcat is smart enough to resolve this on it's own by autodetecting available ports in the range 4000-4100
   ==>如果tomcat实例运行在同一个主机上,确保tcp监听端口号彼此不同,默认有:8080,8009,8443,8005。
<5>Make sure your web.xml has the <distributable/> element
   ==>确保你的应用的web.xml中有元素【<distributable/>】,建议放到根下;
<6>If you are using mod_jk, make sure that jvmRoute attribute is set at your Engine <Engine name="Catalina" jvmRoute="node01" >
   and that the jvmRoute attribute value matches your worker name in workers.properties
   ==>如果你使用了mod_jk,确保server.xml中【<Engine name="Catalina" jvmRoute="node01" >】的jvmRoute属性和负载均衡器的worker中的jvmRoute属性一致;
<7>Make sure that all nodes have the same time and sync with NTP service!
   ==>确保所有的节点有时间一致,并且通过NTP服务进行同步;
<8>Make sure that your loadbalancer is configured for sticky session mode.
   ==>负载均衡器开启session粘贴
<9>注意:Tomcat的content.xml文件不要放开元素 <Manager pathname="" />
   如下:
   ////////////////begin/////////
   <!-- Uncomment this to disable session persistence across Tomcat restarts -->
    <!--
    <Manager pathname="" />
    -->
   ////////////////end///////////
<10>注意:如果有多个节点时,需要保证前面的节点启动完全后,再启动后面的节点;
///////////end//////////
<11>需要检查tomcat日志,看是否有以下类似信息:tomcat6,tomcat7
///////////////begin//////////
Cluster is about to start  ==>集群启动
Receiver Server Socket bound to:/10.88.147.205:4000
Setting cluster mcast soTimeout to 500
JvmRouteBinderValve started
Register manager /bar to cluster element Host with name localhost =>注册受管应用到集群中,和【<distributable/>】相关;
Starting clustering manager at /bar
Manager [/bar]: session state send at 8/28/14 4:22 PM received in 875 ms. =>session是否得到同步;
Received memberDisappeared[org.apache.catalina.tribes.membership.MemberImpl[tcp://{10, 88, 147, 148}:5000,{10, 88, 147, 148},5000, alive=111615,id={49 -1 97 74 27 -115 72 -25 -118 -35 -115 84 -3 -57 77 -61 }, payload={}, command={}, domain={}, ]] message. Will verify.
org.apache.catalina.tribes.group.interceptors.TcpFailureDetector memberDisappeared
Verification complete. Member already disappeared[org.apache.catalina.tribes.membership.MemberImpl[tcp://{10, 88, 147, 148}:5000,{10, 88, 147, 148},5000, alive=111615,id={49 -1 97 74 27 -115 72 -25 -118 -35 -115 84 -3 -57 77 -61 }, payload={}, command={}, domain={}, ]]
///////////////end////////////

2、使用Apache做负载均衡的样例配置,此处采用ajp,而没有使用http,使用http可能导致出现实际地址的问题出现;
///////////////begin//////////
Listen 80
<VirtualHost *:80>
ProxyRequests off
ProxyPass / balancer://test/ lbmethod=byrequests stickysession=JSESSIONID nofailover=Off timeout=5 maxattempts=3  
#ProxyPassReverse / balancer://test/
<Proxy balancer://test>
BalancerMember ajp://10.88.147.148:8009 route=jvm1
BalancerMember ajp://10.88.147.148:9009 route=jvm2
</Proxy>
SetEnv proxy-nokeepalive 0
</VirtualHost>
///////////////end/////////////

3、使用Nginx做负载均衡的样例配置,
/////////////////begin/////////
upstream 10.88.147.205 {
    #enable session stick
    ip_hash;
    server 10.88.112.165:8080 max_fails=3  fail_timeout=5s;
    server 10.88.112.165:80 max_fails=3  fail_timeout=5s;  
    }

location / {
        root   html;
             index  index.html index.htm;   
         proxy_pass  http://10.88.147.205;
         proxy_redirect default;
             proxy_connect_timeout 10;
        }
注意:层次结构上,http元素在最外层,其中包含元素:upstream和server,而server中才包含location元素。
/////////////////end///////////

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.iyunv.com/thread-320671-1-1.html 上篇帖子: 解剖Nginx·自动脚本篇(6)编译器名称变量脚本 auto/cc/name 下篇帖子: Nginx模块开发 从url变量中读取内容并显示
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表