Apache,Tomcat集群,负载均衡
1软件列表
·apache_2.2.4-win32-x86-no_ssl.msi
·tomcat6.0
·mod_jk-1.2.26-httpd-2.2.4.so
2安装方法
·编辑系统配置文件WINDOWS/system32/drivers/etc/hosts,追加一行:127.0.0.1 localhost
· 将tomcat的连接文件mod_jk-1.2.26-httpd-2.2.4.so复制到Apache安装目录下的modulers目录下
·编辑Apache配置文件conf/httpd.conf
在文件尾部追加内容:
LoadModule jk_module modules/mod_jk-1.2.26-httpd-2.2.4.so
JkWorkersFile conf/workers.properties
JkMount /* lbcontroller
·在Apache安装目录下的conf目录下,新建workers.properties文件,编辑内容如下:
#分发控制器,lbcontroller值对应conf/httpd.conf中的JkMount /* lbcontroller
worker.list=lbcontroller
######Tomcat1实例配置#####
#tomcat1,对应tomcat的server.xml 中<Engine name="tomcat1" defaultHost="localhost" jvmRoute="tomcat1">的jvmRoute值
#host值对应server.xml中的<Host name="localhost" appBase="webapps">以及hosts文件中的值
worker.tomcat1.host=localhost
#port值对应server.xml中的节点<Connector port="8010" protocol="AJP/1.3" redirectPort="8443" />
worker.tomcat1.port=8010
worker.tomcat1.type=ajp13
#分发权重,值越大负载越大
worker.tomcat1.lbfactor=1
#Tomcat2实例配置
worker.tomcat2.host=localhost
worker.tomcat2.port=8011
worker.tomcat2.type=ajp13
worker.tomcat2.lbfactor=1
#负载均衡分发控制器
worker.lbcontroller.type=lb
worker.lbcontroller.balance_workers=tomcat1,tomcat2
worker.lbcontroller.sticky_session=1
·修改各个tomcat配置文件server.xml,保持各端口相异
<Server port="8006" shutdown="SHUTDOWN">
<Connector port="8001" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" URIEncoding="UTF-8"/>
<Connector port="8010" protocol="AJP/1.3" redirectPort="8443" />
<Engine name="tomcat1" defaultHost="localhost" jvmRoute="tomcat1">
<Host name="localhost" appBase="webapps"
unpackWARs="true" autoDeploy="true"
xmlValidation="false" xmlNamespaceAware="false">
增加或从注释中释放以下两个节点:
1,<Valve className="org.apache.catalina.valves.RequestDumperValve"/>
2,<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"
port="4000"
autoBind="100"
selectorTimeout="5000"
maxThreads="6"/>
<!-- timeout="60000"-->
<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>
如果需要实现session 复制 需要在web.xml 中加上<distributable/>
<?xml version="1.0" encoding="ISO-8859-1"?>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<distributable/>
</web-app>
说明:
将web系统发布至各个tomcat的webapp下
通过localhost/myweb即可访问