Apache+tomcat Deploying load balancing (or clustering)

Source: Internet
Author: User
Tags server installation and configuration

Originally intended only to write Tomcat cluster deployment, simplify the Apache and Tomcat integration process. Later thought, this does not facilitate the use of Apache friends to learn the contents of this article. So simply increase the length, so that the Apache does not understand the friend can have a preliminary understanding of Apache, Apache.

If you do not understand the concept of clustering, you can look at one of the previous writing: WebLogic Deployment cluster and proxy Server This article is a detailed explanation of the concept of the cluster, and unlike the WebLogic cluster, the deployment of the application on each sub-server is done automatically by the WebLogic container. and Tomcat needs to copy the project manually.

One, load balanced network topology diagram.

One, Apache server installation and configuration.

1. First download the Apache Server installation version, double-click the installation, the next step directly next do not need to do any configuration.

2. Install and open the installation directory and locate the Conf directory.

1. Manual creation of two files

1234567891011121314151617181920 mod_jk.conf#================从这里复制================#加载mod_jk Module   注意文件名根据实际情况而填LoadModule jk_module modules/mod_jk-1.2.31-httpd-2.2.3.so#指定 workers.properties文件路径JkWorkersFile conf/workers.properties#指定那些请求交给tomcat处理,"controller"为在workers.propertise里指定的负载分配控制器  JkMount /*.docontrollerJkMount /*WEB-INF controllerJkMount /*j_spring_security_check controllerJkMount /*.action controllerJkMount /servlet/* controllerJkMount /*.jsp controllerJkMount /*.docontrollerJkMount /*.action controllerJkMount /* controller#================文件内容================

+ View Code

2. Modify the contents of the httpd.conf file

Open the httpd.conf file with the last line plus: Include conf/mod_jk.conf

Apache default port is 80, if you need to change the port directly to find the file under the Listen 80 field, the 80 to get rid of it.

3. Add Mod_jk-1.2.31-httpd-2.2.3.so Plugin

Download the mod_jk-1.2.31-httpd-2.2.3.so file and add it to the Modules folder. This so file is a plugin that must be used to configure load balancing.

With this, Apache doesn't have to move.

Third, the installation and configuration of Tomcat server.

1. Download Tomcat directly after the extraction.

2. Open the Server.xml file under the Conf folder to modify the following to ensure that the corresponding ports of the two Tomcat do not conflict:

First place: Port

<server port= "9011" shutdown= "Shutdown" >

The second place: port, Redirectport Note that the encoding format needs to be set to GBK, otherwise there is garbled problem

<connector port= "9001" protocol= "http/1.1"

connectiontimeout= "20000"

Redirectport= "9441"

uriencoding= "GBK"/>

Third place: Port corresponds to port, Redirectport configured in Apache configuration file, note encoding

<connector port= "8009" protocol= "ajp/1.3" redirectport= "8443"/>

Replace with:

+ View Code

Section four: Jvmroute the Tomcat name that is configured in the Apache configuration file

<engine name= "Catalina" defaulthost= "localhost" jvmroute= "TOMCAT1" >

Place five: Only the blue flag is changed to port

In <engine name= "Catalina" defaulthost= "localhost" jvmroute= "TOMCAT1" > Add the following fields below:

1234567891011121314151617181920212223242526272829 <Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"                  channelSendOptions="6">              <ManagerclassName="org.apache.catalina.ha.session.BackupManager"                    expireSessionsOnShutdown="false"                    notifyListenersOnReplication="true"                    mapSendOptions="6"/>           <ChannelclassName="org.apache.catalina.tribes.group.GroupChannel">            <MembershipclassName="org.apache.catalina.tribes.membership.McastService"                         bind="127.0.0.1"                         address="228.0.0.4"                         port="45564"                         frequency="500"                         dropTime="3000"/>             <ReceiverclassName="org.apache.catalina.tribes.transport.nio.NioReceiver"                       address="auto"                       port="4001"                       selectorTimeout="100"                       maxThreads="6"/>             <SenderclassName="org.apache.catalina.tribes.transport.ReplicationTransmitter">               <TransportclassName="org.apache.catalina.tribes.transport.nio.PooledParallelSender" timeout="60000"/>              </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;"/>           <ClusterListenerclassName="org.apache.catalina.ha.session.ClusterSessionListener"/></Cluster>

Iv. Application Deployment and operation

1. Copy the project to the WebApps folder under all Tomcat.

2. Locate the Startup.bat file in the Tomcat Server bin directory and double-click Start Tomcat

3. Start Apache after all Tomcat is started: directly click on the icon to start

V. Copy of Session

Open the Web. xml file under the Web-inf folder in the project, and add <distributable/> to the penultimate line

Five, test page

Create the following files to be placed in the project for testing load balancing and session replication

File name: test.jsp

 1 <%@ page contenttype= "text/html; CHARSET=GBK "%> 2 <%@ page import=" java.util.* "%> 3 

This is the APACHE+TOMCAT deployment load balancer (or cluster), and if there is a need to deploy multiple sets of clusters on the same computer, there will be some changes in the configuration

Apache+tomcat Deploying load balancing (or clustering)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.