Apache+tomcat Distributed cluster Building

Source: Internet
Author: User
Tags http redirect

Today, build Apche+tomcat distributed cluster, encountered many problems, found on the internet many are unsuccessful, and then with colleagues to study a bit, the final build success. Make a note to prepare for your future reference.

1, download Apache. When downloading Apache (version 2.4), download the full version, otherwise it will be missing a lot of things. Reference post: http://jingyan.baidu.com/article/29697b912f6539ab20de3cf8.html

Download mod_jk.so, Address: http://apache.opencas.org/tomcat/tomcat-8/v8.0.33/bin/

The address has a compressed package, download a corresponding to you, in the compressed package has mod_jk.so file, copy to Apache under the folder modules below. (Note that if you later prompt for mod_jk.so errors, you will need to change a mod_jk.so file).

Open the conf/httpd.conf inside to find

Define srvroot "\apache" ServerRoot "${srvroot}"

Change the path behind the srveoot to your own Apache installation path.

Create a property file Workers.properties in the httpd.conf sibling directory and add information to the file:

Worker.list=jetty_aworker.jetty_a.port=8009worker.jetty_a.host=127.0.0.1worker.jetty_a.type=ajp13worker.jetty_ a.lbfactor=2 worker.list=jetty_bworker.jetty_b.port=8010worker.jetty_b.host=127.0.0.1worker.jetty_b.type= Ajp13worker.jetty_b.lbfactor=1 worker.list=jettybalancerworker.jettybalancer.type= lbworker.jettybalancer.balance_workers= Jetty_a, Jetty_b
Worker.loadbalancer.sticky_seesion=false
Worker.loadbalancer.sticky_session_force=false

The above information is we will configure the Tomcat server information, the SJP port number is 8009/8010,ip to local so need to modify, if not the local two servers, then do not have to change. Note the above parameters, which focus on modifying the

Worker.jetty_a.port
Worker.jetty_a.host

The above tomcat parameters correspond to the following parameter items.

Add information at the bottom of the conf/httpd.conf file.

LoadModule jk_module modules/mod_jk.so<IfmoduleJk_module>jkworkersfile "${srvroot}/conf/workers.properties" Jklogfile "${srvroot}/logs/mod_jk.log" JkLogLevel warn</Ifmodule><VirtualHost*:80><ProxyBalancer://cluster>balancermember ajp://127.0.0.1:8009 route=tomcat_a balancermember ajp://127.0.0.1:8010 route=tomcat_b ProxyS ET lbmethod=bytraffic</Proxy>ServerAdmin ****** @qq. com# Specifies the e-mail address of the server administrator, and the server automatically reports the error to the address servername localhost# the hostname of the Web client search errorlog "${ Srvroot}/logs/app1_error.log "Customlog" ${srvroot}/logs/app1_access.log "commonproxypass/balancer://cluster/ stickysession=jsessionid# Balancer: How the session is copied, including Jsessionid or Phpsessionid Nofailover:on, indicates that the session will be interrupted when the worker is faulted or stopped. When the back-end server does not support session replication, set to On; # Lbmethod: Select the load scheduling algorithm, the default byrequests represents the polling schedule (that is, 1:1), bytraffic represents the weighted weight of the dispatch, the need to add loadfactor to specify the weight value. proxypassreverse/balancer://cluster/stickysession=jsessionid# this directive enables Apache to adjust the HTTP redirect response in location, Content-location, The URL of the URI header. This avoids the problem of bypassing the reverse proxy caused by HTTP redirection of the backend server when Apache is used as a reverse proxy. #The proxyrequests directive should usually is set off when using Proxypass.proxyrequests off# is not allowed as a forward proxy proxypreservehost on# when enabled, this option passes the "host:" Row of the incoming request to the proxied host instead of passing the host name specified in the Proxypass. </VirtualHost>

2, download Tomcat. There are not too many restrictions on tomcat usage and can be used on the line. Mine is 8.0.33.

3. Go to the bin under Apache installation path and open cmd.

Running the Httpd-k install installs Apache. In the run time, there will be a lot of problems, that is, in the Apache default environment, a lot of *.so files are annotated. So you'll get an error when you install it, and the wrong information will tell you where the error is, so it's good to identify. Now install the time only need to put the error *.so open comments on the line.

When the error is an error, the first installation error after the modification, and then run under the bin cmd:httpd-k Uninstall uninstall Apache, reinstall once, until no error.

After the installation is successful, go to the service to restart Apache. I still error, but this mistake will go to the log to check the error message, in fact, or open a *.so.

I've opened the following in total:

Mod_proxy, Mod_proxy_balancer, Lbmethod_****_module, Slotmem_shm_module, MOD_PROXY_AJP

This part of the operation is more, but summed up a sentence, you can open more, not less open, if you do not know which is, then open a few more.

4,apache is configured, now start configuring the Tomcat server.

Because we have two Tomcat server, generally know that the port can not conflict, so the port to modify, one of the ports modified on the line, the other one can not change, I am one of the Tomcat all ports are +1. Anyway, as long as the configured parameters are consistent. The details are as follows 3 places modified:

<ServerPort= "8006"shutdown= "SHUTDOWN">  <ConnectorPort= "8088"Protocol= "http/1.1"ConnectionTimeout= "20000"Redirectport= "8444" />   <ConnectorPort= "8010"Protocol= "ajp/1.3"Redirectport= "8444" />

After modifying the above ports, you also configure the cluster information. Add the following information below the annotated cluster tag in tomcat:

<ClusterClassName= "Org.apache.catalina.ha.tcp.SimpleTcpCluster"channelsendoptions= "8">        <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= "$"Droptime= " the"/>            <SenderClassName= "Org.apache.catalina.tribes.transport.ReplicationTransmitter">                <TransportClassName= "Org.apache.catalina.tribes.transport.nio.PooledParallelSender"/>            </Sender>            <ReceiverClassName= "Org.apache.catalina.tribes.transport.nio.NioReceiver"Address= "Auto"Port= "4000"Autobind= "+"Selectortimeout= "the"MaxThreads= "6"/>            <InterceptorClassName= "Org.apache.catalina.tribes.group.interceptors.TcpFailureDetector"/>            <InterceptorClassName= "Org.apache.catalina.tribes.group.interceptors.MessageDispatch15Interceptor"/>        </Channel>        <ValveClassName= "Org.apache.catalina.ha.tcp.ReplicationValve"Filter=""/>        <ValveClassName= "Org.apache.catalina.ha.session.JvmRouteBinderValve"/>        <!--<clusterlistener classname= "Org.apache.catalina.ha.session.JvmRouteSessionIDBinderListener"/> -        <ClusterlistenerClassName= "Org.apache.catalina.ha.session.ClusterSessionListener"/>    </Cluster>

After deploying the above, basically it is possible, server cluster. Then we declare the project cluster in the project that needs the cluster. Webapp/meta-inf/context.xml Add the following information:

<? XML version= "1.0" encoding= "UTF-8" ?> <  distributable= "true"  className= " Org.apache.catalina.ha.context.ReplicatedContext "/>

Here, the configuration of the server and the project is basically complete. We now put the project on the start of two newly configured servers and then access the project. Make a simple output in your project to see which server you are accessing, and you can see your own access logs in two Tomcat servers.

Apache+tomcat Distributed cluster Building

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.