Apache Load Balancer +tomcat cluster
httpd-2.4.9 + apache-tomcat-7.0.47 Configuring load Balancing
Target :
use Apache and Tomcat to configure a Web site that can be applied , to meet the following requirements:
1,Apache as httpserver, behind the connection of multiple Tomcat application instances, and load balancing.
2. Set the Session timeout for the system , including Apache and Tomcat
3, for the System screen file list, including Apache and Tomcat
Note: This example takes 3 machines As an example, that is, the same machine is loaded with Apache and another 2 Tomcat.
principle :
3 different ways to integrate Apache and Tomcat
1.JK Mode integration
download mod_jk-1.2.31-httpd-2.2.3.so, please download the appropriate mod_jk version, change the name to mod_jk.so in modules Folder inside
modifying The conf/httpd.conf configuration
LoadModule Jk_module modules/mod_jk.so
Jkworkersfile conf/workers.properties
Jklogfile Logs/mod_jk.log
Jkloglevel Debug
Jkmount/*.do LoadBalancer
Jkmount/*.jsp LoadBalancer
Add a conf/workers.properties file, adding content
Worker.list=loadbalancer
worker.worker2.port=9009 #ajp Listening Port
worker.worker2.host=10.0.0.51
Worker.worker2.type=ajp13
Worker.worker2.lbfactor=1
worker.worker3.port=9009
worker.worker3.host=10.0.0.52
Worker.worker3.type=ajp13
Worker.worker3.lbfactor=1
Worker.loadbalancer.type=lb
worker.loadbalancer.balance_workers=worker2,worker3# here in the worker2,Worker3 for the need with the top Tomcat sets the alias of the same
Worker.loadbalancer.sticky_session=1
Configuration complete
visit http://10.0.0.51:8080/test/test.jspto check for normal access.
visit http://10.0.0.52:8080/test/test.jspto check for normal access.
visit http://10.0.0.31:80/test/test.jspto check for normal access.
2,ajp_proxy
Remove The note from the httpd.conf file ( Delete #)to open the configuration below
Include conf/extra/httpd-vhosts.conf
LoadModule proxy_modulemodules/mod_proxy.so
LoadModule proxy_ajp_modulemodules/mod_proxy_ajp.so
LoadModule proxy_balancer_modulemodules/mod_proxy_balancer.so
LoadModule proxy_connect_modulemodules/mod_proxy_connect.so
LoadModule proxy_ftp_modulemodules/mod_proxy_ftp.so
LoadModule proxy_http_modulemodules/mod_proxy_http.so
Note :
except mod_proxy.so,mod_proxy_balancer.so, mod_proxy_connect.so.
if the use of Ajp_proxy, need to load mod_proxy_ajp.so this module;
if the use of Http_proxy, need to load mod_proxy_http.so this module;
Proxyrequests OFF
<proxy balancer://loadbalancer>
Balancermember ajp://10.0.0.51:9009loadfactor=1 ROUTE=JVM1
Balancermember ajp://10.0.0.52:9009loadfactor=1 ROUTE=JVM1
</proxy>
Modify conf/extra/httpd-vhosts.conf Add configuration
<virtualhost *:8081>
ServerAdmin [email protected]
ServerName localhost
Serveralias localhost
Proxypass/balancer://loadbalancer/stickysession=jsessionid Nofailover=on
proxypassreverse/balancer://loadbalancer/
Errorlog "Logs/loadbalancer-error.log"
Customlog "Logs/loadbalancer-access.log" common
</VirtualHost>
Configure complete tasks, Access http://127.0.0.1:8081/test/test.jsp, and check for normal access.
3,http_proxy
Http_proxy configuration is similar to Ajp_proxy, modify method 2 httpd.conf configuration as follows, other unchanged
Proxyrequests OFF
<proxy balancer://loadbalancer>
Balancermember http://10.0.0.51:9009loadfactor=1 ROUTE=JVM1
Balancermember http://10.0.0.52:9009loadfactor=1 ROUTE=JVM1
</proxy>
Configure complete tasks, Access http://127.0.0.1:8081/test/test.jsp, and check for normal access.
First, preparatory work: The installation of the program (the prerequisite is that the installation of JDK1.7 more than the version)
Second, the installation process
Yum Remove Apr-util-devel aprapr-util-mysql apr-docs apr-devel apr-util Apr-util-docs
Yum Install Flex Bison Lynx
The steps are as follows :
1. Resolving Apr
APR and apr-util :http://apr.apache.org/download.cgi
[Email protected] test]# tar-zxfapr-1.4.5.tar.gz
[Email protected] apr-1.4.5]#./configure--prefix=/usr/local/apr
[[email protected] apr-1.4.5]# make
[[email protected] apr-1.4.5]# make install
2. Resolve Apr-util
[Email protected] test]# tar-zxfapr-util-1.3.12.tar.gz
[Email protected] apr-util-1.3.12]#/configure--prefix=/usr/local/apr-util--with-apr=/usr/local/apr/bin/ Apr-1-config
[[email protected] apr-util-1.3.12]# make
[[email protected] apr-util-1.3.12]# make install
3 settlement Pcre
Download:http://sourceforge.net/projects/pcre
Two:http://ftp.exim.llorien.org/pcre/
#unzip-O Pcre-8.10.zip
#cd pcre-8.10
#./configure--prefix=/usr/local/pcre
#make
#make Install
Cp-r apr-1.5.1 HTTPD-2.4.9/SRCLIB/APR
Cp-r Apr-util-1.5.1httpd-2.4.9/srclib/apr-util
Installing httpd
CD httpd-2.4.9
./configure--prefix=/local/apache2--enable-so--enable-mods-shared=all--enable-proxy-- Enable-proxy-connect--enable-proxy-ftp--enable-proxy-http--ENABLE-PROXY-AJP--enable-proxy-balancer--with-apr=/ USR/LOCAL/APR--with-apr-util=/usr/local/apr-util--with-pcre=/usr/local/pcre--WITH-INCLUDED-APR
Make
Make install
Third, the configuration
1.Apache Configuration
httpd.conf Configuration
and then find <ifmodule dir_module></ifmodule> plus index.jsp modified into
<ifmodule dir_module>
DirectoryIndex index.html index.jsp
</IfModule>
Join at the bottom
Proxyrequests OFF
<proxy balancer://cluster>
Balancermember ajp://10.0.0.51:8009loadfactor=1 ROUTE=JVM1
Balancermember ajp://10.0.0.52:9009loadfactor=1 ROUTE=JVM1
</proxy>
the 2 balancermember members above are the Tomcat clusters that we configured . It will be explained later.
Include Virtual host
Include conf/extra/httpd-vhosts.conf # remove the annotations.
httpd-vhosts.conf Settings
Atthe bottom of the file (extra/httpd-vhosts.conf), add
<virtualhost *:80>
ServerAdmin [email protected]
ServerName localhost
Serveralias localhost
Proxypass/balancer://cluster/stickysession=jsessionid Nofailover=on
proxypassreverse/balancer://cluster/
</VirtualHost>
2 Tomcat Configuration
Configuration Engine
Comment out the original configuration and remove the comment from the following sentence.
<engine name= "Standalone" defaulthost= "localhost" jvmroute= "jvm1" >
Configuration Connector
The original default configuration.
<!--Define an AJP 1.3 Connector on port8009-
<connector port= "8009" protocol= "ajp/1.3" redirectport= "8443"/>
Configuration Cluster ( modified in each tomcat)
The original configuration.
<clusterclassname= "Org.apache.catalina.ha.tcp.SimpleTcpCluster"/>
Modify to the following code:<receiver port="XX"/>port also to ensure uniqueness.
<clusterclassname= "Org.apache.catalina.ha.tcp.SimpleTcpCluster" channelsendoptions= "6" >
<managerclassname= "Org.apache.catalina.ha.session.BackupManager"
Expiresessionsonshutdown= "false"
Notifylistenersonreplication= "true"
mapsendoptions= "6"/>
<!--
<managerclassname= "Org.apache.catalina.ha.session.DeltaManager"
Expiresessionsonshutdown= "false"
Notifylistenersonreplication= "true"/>
-
<channelclassname= "Org.apache.catalina.tribes.group.GroupChannel" >
<membershipclassname= "Org.apache.catalina.tribes.membership.McastService"
Address= "228.0.0.4"
Port= "45564"
Frequency= "500"
Droptime= "/>"
<receiverclassname= "Org.apache.catalina.tribes.transport.nio.NioReceiver"
address= "Auto"
Port= "5001"
selectortimeout= "100"
maxthreads= "6"/>
<sender classname= "Org.apache.catalina.tribes.transport.ReplicationTransmitter" >
<transportclassname= "Org.apache.catalina.tribes.transport.nio.PooledParallelSender"/>
</Sender>
<interceptorclassname= "Org.apache.catalina.tribes.group.interceptors.TcpFailureDetector"/>
<interceptorclassname= "Org.apache.catalina.tribes.group.interceptors.MessageDispatch15Interceptor"/>
<interceptorclassname= "Org.apache.catalina.tribes.group.interceptors.ThroughputInterceptor"/>
</Channel>
<valveclassname= "Org.apache.catalina.ha.tcp.ReplicationValve"
Filter= ". *\.gif;. *\.js;. *\.jpg;. *\.png;. *\.htm;. *\.html;. *\.css;. *\.txt; " />
<deployerclassname= "Org.apache.catalina.ha.deploy.FarmWarDeployer"
Tempdir= "/tmp/war-temp/"
Deploydir= "/tmp/war-deploy/"
Watchdir= "/tmp/war-listen/"
Watchenabled= "false"/>
<clusterlistenerclassname= "Org.apache.catalina.ha.session.ClusterSessionListener"/>
</Cluster>
This setting is used primarily for Tomcat clusters.
Iv. Start the service and test The example of Tomcat's own
1.test Apache and Tomcat collaboration.
The following section of the test code is addedto the index.jsp under \webapps\root in each tomcat: (X represents different tomcat the output of different information ) , Remove the index.html , so as not to affect the test results. Plus on the last side . that is , between </table></body>.
<%
System.out.println ("tomcat6.0x deal with request");
%>
and then through the http://10.0.0.31 visit, you will be familiar with the cat cat.
And then through the separate access
http://10.0.0.51:8080,http://10.0.0.52:8080 the content they access is the same as the http://10.0.0.31 above .
This illustrates the success of Apache and TOMCAT integration!
2. Test Equalizer
through http//127.0.0.1 Multiple access, to see the real effect, you must use some stress testing tools, Microsoft Microsoft Web Application Stress tool can be used Do a simple stress test, or you can't keep on refreshing, you will only have output results in a Tomcat console. Using only the stress test tool to simulate a large number of simultaneous users, you will find four tomcat consoles with control information indicating that the equalizer is working properly.
finish the document very late, and despite the intensity of the work each day, I would like to make progress with you. Hehe every day progress a little.
follow up the other modules, what is the problem please do not mean to point out, together to improve. Welcome everyone and the technical enthusiasts join our QQ Group 262407268, build our "Chinanetcloud Smart city"
At present, has completed three relatively small modules: common, service, application in fact, to achieve high performance inside there is a lot of content to learn to accumulate, follow-up will do to supplement. Next we should share the Data Warehouse section, first relational database Oracle, MySQL and then non-relational database mogondb, Redis, hbase, finally we open the path of distributed computing Hadoop, mainly for data analysis and processing. Here we will mention a collection of the production of the engine: sphinx+ Chinese word coreseek, will also do a log analysis of the architecture Splunk products. Together to build our "Chinanetcloud smart city".
Please consciously revise the notes, thank you. Affirm that this group is a community of public welfare, we are willing to undertake some architectural design, construction and consulting business, for you and your business to improve the business rack
This article is from the "Davideylee" blog, make sure to keep this source http://davideylee.blog.51cto.com/8703117/1440442
Lab-bill-sys_apachetomcatloadbalance