实现tomcat高可用性负载均衡
CentOS5.4、pcre-8.12、nginx-upstream-jvm-route-0.1、nginx-1.0.10、apache-tomcat-7.0.23 、keepalived-1.1.17.tar.gz、jdk-7u2-linux-x64.tar.gz
主nginx服务器地址:10.29.9.200
辅nginx服务器地址:10.29.9.201
tomcat1: 10.29.9.202
tomcat2: 10.29.9.203
cd pcre-8.12
./configure
make;make install
user www www;
辅keepalived 配置
1)安装tomcat_1
tar zxvf apache-tomcat-7.0.23.tar.gz
mv apache-tomcat-7.0.23 /usr/local/tomcat
2)安装tomcat_2,步骤同1)
cat >>/etc/profile <<EOF
export JAVA_HOME=/usr/local/jdk1.7.0_02
export CLASSPATH=$CLASSPATH:$JAVA_HOME/lib:$JAVA_HOME/jre/lib
export PATH=$JAVA_HOME/bin:$JAVA_HOME/jre/bin:$PATH:$HOMR/bin
tomcat1配置:
修改conf/server.xml配置文件
<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=”224.0.0.4″
port=”45564″
frequency=”500″
dropTime=”3000″/>
<Receiver className=”org.apache.catalina.tribes.transport.nio.NioReceiver”
address=”10.29.9.202″ //tomcat1 所在服务器的 IP地址
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”/>
<Interceptor className=”org.apache.catalina.tribes.group.interceptors.ThroughputInterceptor”/>
</Channel>
<Valve className=”org.apache.catalina.ha.tcp.ReplicationValve”
filter=””/>
<Valve className=”org.apache.catalina.ha.session.JvmRouteBinderValve”/>
<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>
修改conf/server.xml配置文件
<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=”224.0.0.4″
port=”45564″
frequency=”500″
dropTime=”3000″/>
<Receiver className=”org.apache.catalina.tribes.transport.nio.NioReceiver”
address=”10.29.9.203″ //tomcat2所在服务器 IP
port=”4001″ //端口号不能和tomcat1重复
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”/>
<Interceptor className=”org.apache.catalina.tribes.group.interceptors.ThroughputInterceptor”/>
</Channel>
<Valve className=”org.apache.catalina.ha.tcp.ReplicationValve”
filter=””/>
<Valve className=”org.apache.catalina.ha.session.JvmRouteBinderValve”/>
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>
<distributable/>
直接加在</web-app>之前
开启网卡组播功能:
route add -net 224.0.0.0 netmask 240.0.0.0 dev eth0
mkdir /opt/project
vi index.jsp
<html>
<title>
tomcat1 jsp
</title>
<%
String showMessage=”Hello,This is 10.29.9.202 server”;
out.print(showMessage);
%>
</html>
—————————-
mkdir /opt/project
vi index.jsp
<html>
<title>
tomcat2 jsp
</title>
<%
String showMessage=” Hello,This is 10.29.9.203 server”;
out.print(showMessage);
%>
</html>
转载于:https://blog.51cto.com/gxjluck/774814
发布者:全栈程序员-用户IM,转载请注明出处:https://javaforall.cn/110476.html原文链接:https://javaforall.cn
【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛
【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...