Fully Distributed cluster configuration of Apache and tomcat in Linux (Server Load balancer)

Source: Internet
Author: User

Recently, the company wanted to provide customers with a cluster solution. The project team adopted Apache and tomcat cluster configuration to achieve load balancing.

I have never been familiar with Apache before, so I have some hands-on skills. I also searched for many cluster articles on the Internet, but none of them can be configured from start to end, or incomplete files and unclear interpretations.

I hope to take this opportunity to share and use it.

This cluster is implemented using AJP, which is easy to understand. In fact, the configuration of this cluster is nothing more than to download the required software, modify the corresponding configuration file, and then start it in sequence.

Here I paste the required application software and corresponding configuration files. You can compare whether your files match.

In advance, I am working on a fully distributed cluster, that is, the operations actually performed on different virtual machines. This operation is not performed on the same machine. Therefore, we do not recommend that you perform this operation on the same machine.

Three machines:

System: centos 5.x

Master node: 192.168.1.101

Subnode 1: 192.168.1.151

Subnode 2: 192.168.1.152

1. Required Software: (the installation steps do not need to be described)

Install Apache 2.2.25 on the master node/opt/apache2

Install Apache-Tomcat-6.0.37 on subnode 1 and subnode 2/opt/Apache-Tomcat-6.0.37

2. Configuration File

After installing Apache, You need to modify the following three points:

1) servername localhost: 80 the localhost is the local host name, and the host name is the name displayed in the hosts file. If the configuration is incorrect, HTTPD may occur: cocould not reliably determine ....... error.

2) configure the following text at the end of the file to control the cluster members.

ProxyPass /images ! ProxyPass /css ! ProxyPass /js !ProxyRequests OffProxyPass /test balancer://mycluster/ stickysession=JSESSIONIDProxyPassReverse /test balancer://mycluster/ stickysession=JSESSIONID<Proxy balancer://mycluster>     BalancerMember ajp://192.168.1.152:8009/test/ loadfactor=1      BalancerMember ajp://192.168.1.151:8009/test/ loadfactor=1</Proxy>

This configuration is the reverse proxy of Apache, which is used to access the Tomcat project through Apache. Test is the project context of the blogger, and two balancemember are members in the cluster. Port 8009 is the AJP port name of Tomcat.

The above amendment: This was neglected during the test yesterday and was discovered only during the test at the company today. You must note that route = worker1 and route = worker2 in the balancermember line cannot be added. Once added, distributed access will not be performed through the Apache designation, therefore, you must remove it here. Otherwise, operations will only be performed in a tomcat container.

The following balancer-manager is the path configuration used to view the Server Load balancer running status.

This text needs to be added in

<IfModule ssl_module>SSLRandomSeed startup builtinSSLRandomSeed connect builtin</IfModule>

.

3) Finally

ProxyPass /images ! ProxyPass /css ! ProxyPass /js !

Add the following configuration above:

<Location /server-status>     SetHandler balancer-manager     Order Deny,Allow     Deny from all     Allow from all</Location><Location /balancer-manager>     SetHandler balancer-manager     Order Deny,Allow     Deny from all     Allow from all</Location>

Some articles found on the Internet are correctly configured, but the services can be started and accessed at the end, but the Server Load balancer effect is not achieved, but only run on a single node.

I also encountered this problem, and finally found a long time before I found that the above configuration needs to be introduced.

So far, Apache configuration is complete, and tomcat configuration is carried out below.

3. tomcat configuration file

First, Tomcat only configures a file, namely server. xml. In addition, the ports do not need to be changed, because they are implemented in a real distributed environment. You only need to modify the engine node.

Add a jvmroute attribute to the previous engine node. The value is worker1 or worker2 we just mentioned. The specific configuration is as follows:

<Engine name="Catalina" defaultHost="localhost" jvmRoute="worker2">      <!--For clustering, please take a look at documentation at:          /docs/cluster-howto.html  (simple how to)          /docs/config/cluster.html (reference documentation) -->            <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="192.168.1.152"                      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"/>          </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> 

The above configuration is the worker2 configuration we mentioned, which is configured on subnode 2. If it is on subnode 1, you only need to change it to worker1, in addition, you must change the receiver address to the IP address of the current machine.

Finally, put the project to be operated under the Tomcat webapp, and introduce the <distributable/> element in the project's web. xml file.

So far, tomcat configuration has been completed.

4. Start the test

The sequence of startup is varied on the Internet. For my own test, we need to start Apache and then start Tomcat subnodes in sequence.

Test URL: http: // 192.168.1.101: 80/test

The server Load balancer address http: // 192.168.1.101: 80/balancer-Manager

Test method: we can add a print at the end of the index. jsp file of the project, for example:

<%      system.out.println("==============");%>

In this case, we start the two Tomcat consoles to observe. If the consoles of the two nodes are printed alternately after the web address is accessed through Apache, the configuration is successful.

The above is my personal summary. I have configured this cluster for the first time. If there is something immature, please leave a message below.

Related Article

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.