centos环境下apache集群tomcat与负载均衡装备笔记ITeye - 威尼斯人

centos环境下apache集群tomcat与负载均衡装备笔记ITeye

2019年02月20日11时15分10秒 | 作者: 鸿博 | 标签: 装备,机器,端口 | 浏览: 1229

体系环境:centos4.8
使用版别:
apache:2.2.3
tomcat:7.0.14
装备关键:
1.tomcat session仿制:
server.xml,在 Engine 节点下添加:
 Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"
 channelSendOptions="8" 
 Manager className="org.apache.catalina.ha.session.DeltaManager"
 expireSessionsOnShutdown="false"
 notifyListenersOnReplication="true"/ 
 Channel className="org.apache.catalina.tribes.group.GroupChannel" 
 Membership className="org.apache.catalina.tribes.membership.McastService"
 address="228.0.0.4" ! 此地址不变  
 port="45564"
 frequency="500"
 dropTime="3000"/ 
 Receiver className="org.apache.catalina.tribes.transport.nio.NioReceiver"
 address="auto"
//tcpListenPort假如是同一机器布置两个tomcat7使用,则修正tomcat7_b为4001,避免抵触. 不同机器下,不必更改此项.
 port="4000"
 autoBind="100"
 selectorTimeout="5000"
 maxThreads="6"/ 
 Sender className="org.apache.catalina.tribes.transport.ReplicationTransmitter" 
 Transport className="org.apache.catalina.tribes.transport.nio.PooledParallelSender"/ 
 /Sender 
 Interceptor className="org.apache.catalina.tribes.group.interceptors.TcpFailureDetector"/ 
 Interceptor className="org.apache.catalina.tribes.group.interceptors.MessageDispatch15Interceptor"/ 
 /Channel 
 Valve className="org.apache.catalina.ha.tcp.ReplicationValve"
 filter=""/ 
 Valve className="org.apache.catalina.ha.session.JvmRouteBinderValve"/ 
// 假如tomcat发动呈现:严峻: FarmWarDeployer can only work as host cluster subelement! 能够将此节点去掉 
 Deployer className="org.apache.catalina.ha.deploy.FarmWarDeployer"
 tempDir="/tmp/war-temp/"
 deployDir="/tmp/war-deploy/"
 watchDir="/tmp/war-listen/"
 watchEnabled="false"/ 
 ClusterListener className="org.apache.catalina.ha.session.JvmRouteSessionIDBinderListener"/ 
 ClusterListener className="org.apache.catalina.ha.session.ClusterSessionListener"/ 
 /Cluster 


2. 为tomcat添加仅有标明(个人了解),添加jvmRoute特点,apache负载均衡用到
Engine name="Catalina" defaultHost="localhost" jvmRoute="tomcat7_1"
Engine name="Catalina" defaultHost="localhost" jvmRoute="tomcat7_2"

3.同一机子上有多个tomcat,SHUTDOWN 端口不能抵触。
tomcat7_1: Server port="8006" shutdown="SHUTDOWN"
tomcat7_2: Server port="8007" shutdown="SHUTDOWN"

4.同理,http端口和ajp端口都不能抵触:
eg:
connector port="8082" protocol="HTTP/1.1" onnectionTimeout="20000" edirectPort="8443" /
Connector port="8009" protocol="AJP/1.3" redirectPort="8443" /

5. 为了便利测验,直接用到了webapps 中的examples工程,
tomcat7_1\webapps\examples\WEB-INF\web.xml中参加 distributable/
tomcat7_2\webapps\examples\WEB-INF\web.xml中参加 distributable/
两个tomcat中examples工程都参加test.jsp
代码如下:

 %@ page contentType="text/html; charset=UTF-8" % 
 %@ page import="java.util.*" % 
 html head title Cluster Test /title /head 
 body 
 //HttpSession session = request.getSession(true);
 System.out.println(session.getId());
 out.println(" br SESSION ID:" + session.getId()+" br 
 String name = request.getParameter("name");
 if (name != null name.length() 0) {
 String value = request.getParameter("value");
 session.setAttribute(name, value);
 out.print(" b Session List: /b 
 Enumeration String names = session.getAttributeNames();
 while (names.hasMoreElements()) {
 String sname = names.nextElement(); 
 String value = session.getAttribute(sname).toString();
 out.println( sname + " = " + value+" br 
 System.out.println( sname + " = " + value);
 form action="test.jsp" method="post" 
 session称号: input type=text size=20 name="name" 
 session值: input type=text size=20 name="value" 
 input type=submit value="提交" 
 /form 
 /body 
 /html 


在此,session仿制作业结束,测验:
拜访tomcat7_1输入session称号和值提交今后再拜访tomcat7_2,假如session列表中有tomcat7_1的称号和值阐明session同步作业成功!


6.负载均衡装备:

负载方法有jk和 mod_proxy
jk方法从前现已做过,本次测验mod_proxy

装备过程:
httpd.conf中添加以下模块:
LoadModule proxy_module modules/mod_proxy.so 
LoadModule proxy_ajp_module modules/mod_proxy_ajp.so 
LoadModule proxy_balancer_module modules/mod_proxy_balancer.so 
LoadModule proxy_connect_module modules/mod_proxy_connect.so 
LoadModule proxy_ftp_module modules/mod_proxy_ftp.so 
LoadModule proxy_http_module modules/mod_proxy_http.so 


再添加:

#虚拟机装备,负载均衡装备
VirtualHost *:80
ServerAdmin xxxx@qq.com
ServerName localhost
ServerAlias localhost
ProxyPass / balancer://cluster/ stickysession=JSESSIONID|jsessionid nofailover=On
ProxyPassReverse / balancer://cluster/
#ErrorLog "logs/error.log"
#CustomLog "logs/access.log" common
/VirtualHost

ProxyRequests Off
proxy balancer://cluster
BalancerMember ajp://内网ip:8009 loadfactor=1 route=tomcat7_1  smax=5 max=20 ttl=120 retry=300 timeout=15
BalancerMember ajp://内网ip:8010 loadfactor=1 route=tomcat7_2  smax=5 max=20 ttl=120 retry=300 timeout=15

# status=+H为装备热备,当一切机器都over时,才会恳求该机器
#BalancerMember http://xxxxxxx:8009 status=+H

#lbmethod=byrequests 依照恳求次数均衡(默许)
#lbmethod=bytraffic 依照流量均衡
#lbmethod=bybusyness 依照繁忙程度均衡(总是分配给活泼恳求数最少的服务器)
ProxySet lbmethod=bytraffic
/proxy

装备结束。将今日的奋战成果记录下来,便利今后参阅。好记忆不如iteye的博客,
版权声明
本文来源于网络,版权归原作者所有,其内容与观点不代表威尼斯人立场。转载文章仅为传播更有价值的信息,如采编人员采编有误或者版权原因,请与我们联系,我们核实后立即修改或删除。

猜您喜欢的文章