Before I wrote an article in my blog http://blog.csdn.net/yannanying/article/details/43018175, this article is to supplement that article and write. I remember at that time is the reference Baidu experience inside an article wrote, article address is http://jingyan.baidu.com/article/ Ab0b5630b632dbc15afa7dc4.html, winter vacation in accordance with the relevant content of this article to build a APACHE+TOMCAT server cluster, was successful, back to school once again want to try how to build, but found that they do not remember very clearly, Then I wrote this article.
Load Balancer cluster configuration (1): Tomcat configuration
Modify the "Tomcat/conf/server.xml" file
Edit the Server.xml file, locate the " <Connector>
" element node, and there are two element nodes that are not commented out in the Server.xml file <Connector>
. Find the second one, which is the comment above
<!-- Definean AJP 1.3 Connector on port 8009 -->
The node. The revision was changed to
——————————— – The code that needs to be manipulated ———————————————-
<!-- Define an AJP 1.3 Connector on port 8009 --><Connector port="8009" protocolhandlerclassname="org.apache.jk.server.jkcoyotehandler" protocol="AJP/1.3" redirectPort="8443" />
Note: If you are running multiple tomcat at the same time on a single PC, you must <Connector>
set the port (port number) inside the "" element node of each tomcat pair's Server.xml file to a different value. Here the difference is only the second one, but the two " <Connector>
" element nodes need to be modified.
Load Balancer cluster configuration (2):
Then continue to modify this file, find the " <Connector>
" element node below the comment below
<!-- 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"> -->
? There are
<Engine name="Catalina" defaultHost="localhost" jvmRoute="jvm1">
Open its comment. This is where Tomcat is named, which modifies the value of Jvmroute to the Tomcat instance name, and different tomcat sets different values (whether or not the same PC must be different). Like my changes to TOMCAT1 and TOMCAT2.
——————————— – The code that needs to be manipulated ———————————————-
<Engine name="Catalina" defaultHost="localhost" jvmRoute="tomcat1" >
Load Balancer cluster configuration (3):
Next, or manipulate Tomcat's Server.xml file, <Engine>
add the <Host>
following under the or element node
——————————— – The code that needs to be manipulated ———————————————-
<Cluster className="Org.apache.catalina.ha.tcp.SimpleTcpCluster"> <Manager className="Org.apache.catalina.ha.session.BackupManager" Expiresessionsonshutdown="false"notifylistenersonreplication="true" mapsendoptions="6"/> <!--<manager classname= "Org.apache.catalina.ha.session.DeltaManager" Expiresessionsonshut Down= "false" notifylistenersonreplication= "true"/> -- <Channel className="Org.apache.catalina.tribes.group.GroupChannel"> <membership classN Ame = "Org.apache.catalina.tribes.membership.McastService" address = por T = "45564" frequency =" " droptime =" + "/& gt; <ReceiverclassName="Org.apache.catalina.tribes.transport.nio.NioReceiver" Address="192.168.11.128"port="4002"autobind=" Selectortimeout="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"/> <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>
Please continue to the 4th step for the use of the code added above.
Load Balancer cluster configuration (4):
Here's the continuation of the Tomcat Server.xml file.
Locate the element node in the long string of code that you just added, and then <Cluster>
start modifying it, and the code meaning is explained in the comment
——————————— – The code that needs to be manipulated ———————————————-
<membershipclassName="Org.apache.catalina.tribes.membership.McastService" Address="228.0.1.99"port="45564"frequency="$" Droptime="/>" <!--explain the previous code. If the host has a vpn-virtual private network, you need to bind, that is, add bind= "127.0.0.1" in the membership element node as a property. If not, you can not add bind, otherwise it will cause the session cannot be copied. The value of address represents the broadcast address, and the same set of Tomcat-built cluster configurations must be the same. Port port number, the same group of Tomcat-built cluster configuration must be the same. -<ReceiverclassName="Org.apache.catalina.tribes.transport.nio.NioReceiver" Address="192.168.11.128"port="4002"autobind=" Selectortimeout="maxthreads" = "6"/> <!--explain the previous code. The value of address represents a native IP address and must be set to the native IP address. Port port number (Tomcat can detect ports between 4000~4100 by default). If you configure load balancing on the same PC, you need to modify it, using a different port number, or it will fail because of a port conflict. -
Load Balancer cluster configuration (5): Configuration of Project Deployment files
Modify the Web. XML for the project to be published
Locate the project's Web. xml file, open the Modify, and <web-app>
add a line above the element node end tag
——————————— – The code that needs to be manipulated ———————————————-
<distributable/>
This ensures that the session can be duplicated.
?
Load Balancer cluster configuration (6): Apache Configuration
Next to the Apache configuration file modification, find the Apache installation folder under the Conf folder inside the httpd.conf file open and modify, at the end of the add a bit of content
——————————— – The code that needs to be manipulated ———————————————-
#加载mod_jk ModuleLoadModule Jk_module Modules/mod_jk.so<ifmodule mod_jk.c>#指定workers. properties File Pathjkworkersfile/usr/Local/apache2/conf/workers.properties#指定jk logs file storage locationjklogfile/usr/Local/apache2/logs/mod_jk.Log#Set the JK log level [Debug/error/info]Jkloglevel Info#Select the log formatJklogstampformat"[%a %b %d%H:%M:%s %Y]"#JkOptions indicate to send SSL KEYSIZE,Jkoptions +forwardkeysize +forwarduricompat-forwarddirectories#JkRequestLogFormat Set the RequestformatJkrequestlogformat"%w %V %T %q %u%R"#JkShmFile to put logsjkshmfile/usr/Local/apache2/logs/mod_jk.shm</ifmodule> #指定哪些请求交给tomcat处理, which requests are given to Apache processing # Note: "LoadBalancer" is the load assignment controller jkmount specified in Workers.propertise/ *.JSP LoadBalancer#所有的jsp都交给tomcat处理
Load Balancer cluster configuration (7):
? The Workers.properties file in the last added configuration of the httpd.conf file added in the previous step does not exist and requires that we create one in the specified location to see the previous step to find the file in the/usr/local/apache2/conf/ The path is created below.
The Workers.properties file is used to specifically register load-balanced load workers (that is, Tomcat), where 2 Tomcat is registered as 2 workers in this file.
The workers.properties is configured as follows:
——————————— – The code that needs to be manipulated ———————————————-
#workers. Properties## in Unix, Weuse forward slashes:ps=/# Workers ListWorker. List=tomcat1,tomcat2,tomcat3,loadbalancer,status#--------------------------------------------------------------------# First Tomcat#--------------------------------------------------------------------Worker. Tomcat1. Port=8009 AJP13 port number configured in #对应tomcat的server. XMLWorker. Tomcat1. Host=127.0. 0. 1 #tomcat1的主机地址, if not for this machine, please fill in the IP addressWorker. Tomcat1. Type=ajp13#定向包协议Worker. Tomcat1. Lbfactor=1 #server的负载分配权重, the higher the value, the more requests to be divided#以下为非必要配置, this section configures the configuration of the TOMCAT2 with TOMCAT1#worker. tomcat1.cachesize=1000 #配置tomcat的jk连接缓存大小 (not necessary)#worker. tomcat1.cachesize_timeout=600 # (not necessary)#worker. tomcat1.reclycle_timeout=300 # (not necessary)#worker. tomcat1.socket_keepalive=1 #防止防火墙切断未激活的网络连接 (not necessary)#worker. tomcat1.socket_timeout=300 # (not necessary)#worker. Tomcat1.local_worker=1 # (not necessary)#worker. Tomcat1.retries=3 # (not necessary)#----------------------------------------------------------------------# a second tomcat#----------------------------------------------------------------------Worker. Tomcat2. Port=8809Worker. Tomcat2. Host=127.0. 0. 1 #tomcat2的主机IP地址Worker. Tomcat2. Type=ajp13worker. Tomcat2. Lbfactor=1#---------------------------------------------------------------------#第三个tomcat, use tomcat corresponding to the other IP#---------------------------------------------------------------------Worker. Tomcat3. Port=8009Worker. Tomcat3. Host=192.168. One.Worker. Tomcat3. Type=ajp13worker. Tomcat3. Lbfactor=1#----------------------------------------------------------------------# Load Balancerworker-load Balancer Controller# --------------------------------------------------------------------Worker. LoadBalancer. Type=lbworker. LoadBalancer. Balanced_workers=tomcat1,tomcat2,tomcat3#指定分担请求的tomcatWorker. LoadBalancer. Sticky_session=1 #设置为粘性sessionWorker. LoadBalancer. Sticky_session_force=0 #设置当多次请求未响应, the request will be forwardedWorker. Status. Type=status## End Workers.properties
Load Balancer cluster configuration (8):
Modify the httpd.conf file in the Conf folder under the Apache installation.
Open the httpd.conf file and modify it. Locate DocumentRoot and directory and modify it to locate the file access path to the Tomcat WebApps folder, where the item to be published is stored
——————————— – The code that needs to be manipulated ———————————————-
## DocumentRoot: The directory out of which you will serve your# documents. By default, all requests are taken from this directory, but# symbolic links and aliases may be used to point to other locations.#"/usr/local/tomcat1/webapps""/usr/local/tomcat1/webapps"> Require all granted Orderallow,deny Allow from all</Directory>
To this configuration is basically complete.
It's time to test it.
Linux under Apache+tomcat build load Balancer server cluster