"Java Web" Apache+tomcat Cluster for load balancing

Source: Internet
Author: User
Tags server error log 403 forbidden error server port

Steps to implement Apache load Balancer + tomcat cluster Step by step:


1. Introduction to the Environment


Operating system Environment: Windows XP SP3 (2 or more Tomcat services running on a single machine)
Java Environment: JDK1.6.0_13
Software: Apache_2.2.13-win32-x86-no_ssl.msi
Apache-tomcat-6.0.20.zip


Installation of 2.JDK
The installation process is omitted
Settings for Environment variables


3. Start the installation formally:
Installation of Apache:
Download Apache Package: Apache_2.2.13-win32-x86-no_ssl.msi

Personal habits, I build a webserver file under the C packing. Put Apache and Tomcat programs inside.
After installation, Apache is installed in C:\webserver\httpd.


Configure the Load Balancer server Apache.
Remove the comment from this module (conf/httpd.conf)
LoadModule Proxy_module modules/mod_proxy.so
LoadModule Proxy_connect_module modules/mod_proxy_connect.so
LoadModule Proxy_ftp_module modules/mod_proxy_ftp.so
LoadModule Proxy_http_module modules/mod_proxy_http.so
LoadModule Proxy_ajp_module modules/mod_proxy_ajp.so
LoadModule Proxy_balancer_module modules/mod_proxy_balancer.so


And then find <ifmodule dir_module></ifmodule> plus index.jsp modified into


<ifmodule dir_module>
DirectoryIndex index.html index.jsp
</IfModule>


At the end of the configuration file, add:
Proxyrequests OFF
Proxypass/balancer://mycluster Stickysession=jsessionid Nofailover=on
<proxy balancer://mycluster>
Balancermember http://127.0.0.1:9080
Balancermember http://127.0.0.1:10080
</Proxy>


<Location/balancer-manager>
SetHandler Balancer-manager
Order Deny,allow
Deny from all
Allow from all
</Location>


<Location/server-status>
SetHandler Server-status
Order Deny,allow
Deny from all
Allow from all
</Location>






Description
Proxypass/balancer://mycluster/stickysession=jsessionid Nofailover=on
<proxy balancer://mycluster>
Balancermember http://127.0.0.1:9080
Balancermember http://127.0.0.1:10080
</Proxy>


Proxypass is forwarded to the cluster for the proxy forwarding URL, requesting all Access/(here/referring to the home directory of the Apache default Htdoc) to the clusters Balancer://mycluster
Balancermember is a member of the cluster, cluster Server A or B, and the load balancing server forwards the request to balancermember according to the Equalization rules.


Note: If you want to connect to other sub-links in the index.jsp of your homepage, the connection should be this way.
Otherwise you will get an error when visiting the webpage
Internal Server Error
The server encountered an internal error or misconfiguration and is unable to complete your request.
Please contact the server administrator, [email protected] and inform them of the time the error occurred, and anything yo U might has done so may has caused the error.
More information on this error is available in the server error log.


Modification Method:
Proxypass/balancer://mycluster/stickysession=jsessionid Nofailover=on (Proxypass/balancer://mycluster back multiple slashes/)
<proxy balancer://mycluster>
Balancermember http://127.0.0.1:9080/
Balancermember http://127.0.0.1:10080/
</Proxy>


To start the Apache service:
Apache Boot success




Configuration of the Tomcat cluster:


1. Download the Tomcat package: Download the extracted version
Unzip the Tomcat to the C packing directory, rename it to TOMCAT1, and then copy Tomcat1 to TOMCAT2.


2. Configure the Cluster Server TOMCAT1 number server
Port planning:
Configuration parametersCluster Server A (TOMCAT1)Cluster Server B (TOMCAT2)


Server Port900510005


Connector908010080


Coyote AJP Connector 900910009


Cluster mcastaddr224.0.0.1224.0.0.1


Cluster Mcastport 4556445564


TcplistenaddressNative IP AddressNative IP Address


Cluster Tcplistenport 50015002




Modifying the Server.xml configuration file
Changes in the TOMCAT1 section:
1.<server port= "9005" shutdown= "Shutdown" >


2. <connector port= "9080" protocol= "http/1.1"
connectiontimeout= "20000"
redirectport= "8443"/>


3.<connector port= "9009" protocol= "ajp/1.3" redirectport= "8443"/>


4. Unpackwars= "true" autodeploy= "true"
Xmlvalidation= "false" Xmlnamespaceaware= "false" >


——————————— – Added part of ——————————— –


Add between <Host></Host>


<cluster classname= "Org.apache.catalina.ha.tcp.SimpleTcpCluster" channelsendoptions= "6" >
<manager classname= "Org.apache.catalina.ha.session.BackupManager"
Expiresessionsonshutdown= "false"
Notifylistenersonreplication= "true"
mapsendoptions= "6"/>
<channel classname= "Org.apache.catalina.tribes.group.GroupChannel" >
<membership classname= "Org.apache.catalina.tribes.membership.McastService"
Address= "224.0.0.1"
Port= "45564"
Frequency= "500"
Droptime= "/>"


<receiver classname= "Org.apache.catalina.tribes.transport.nio.NioReceiver"
address= "Auto"
Port= "5001"
selectortimeout= "100"
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"/>


<interceptor classname= "Org.apache.catalina.tribes.group.interceptors.ThroughputInterceptor"/>


</Channel>


<valve classname= "Org.apache.catalina.ha.tcp.ReplicationValve"
Filter= ". *\.gif;. *\.js;. *\.jpg;. *\.png;. *\.htm;. *\.html;. *\.css;. *\.txt; " />


<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.ClusterSessionListener"/>
</Cluster>
</Host>




Changes in the TOMCAT2 section:
1.<server port= "10005" shutdown= "Shutdown" >


2. <connector port= "10080" protocol= "http/1.1"
connectiontimeout= "20000"
redirectport= "8443"/>


3.<connector port= "10009" protocol= "ajp/1.3" redirectport= "8443"/>


4. Add between <Host></Host>
Unpackwars= "true" autodeploy= "true"
Xmlvalidation= "false" Xmlnamespaceaware= "false" >
<cluster classname= "Org.apache.catalina.ha.tcp.SimpleTcpCluster" channelsendoptions= "6" >
<manager classname= "Org.apache.catalina.ha.session.BackupManager"
Expiresessionsonshutdown= "false"
Notifylistenersonreplication= "true"
mapsendoptions= "6"/>


<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= "/>"


<receiver classname= "Org.apache.catalina.tribes.transport.nio.NioReceiver"
address= "Auto"
Port= "5002"
selectortimeout= "100"
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"/>


<interceptor classname= "Org.apache.catalina.tribes.group.interceptors.ThroughputInterceptor"/>
</Channel>


<valve classname= "Org.apache.catalina.ha.tcp.ReplicationValve"
Filter= ". *\.gif;. *\.js;. *\.jpg;. *\.png;. *\.htm;. *\.html;. *\.css;. *\.txt; " />


<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.ClusterSessionListener"/>


</Cluster>


</Host>


Cluster testing
WebApps Web Project A in the 2 tomcat directory
Start Tomcat1 and Tomcat2, and then start Apache
Visit: http://127.0.0.1/a/index.jsp
Click Refresh and the page will now jump to the second tomcat server


Note: If access to a webpage is denied,
Forbidden
You don't have permission to access/~web on this server.
Additionally, a 403 Forbidden error is encountered while trying to use an errordocument to handle the request.


It turns out that the permission access control settings in the httpd.conf file are not correct, specifically the following paragraph:
<directory/Location of your Web home directory >
Options FollowSymLinks
AllowOverride None
Order Deny,allow
Allow from all
</Directory>
The Deny from all should be set to allow from all, which is a setting for the root directory, because my custom directory is/myweb/.


*************************************************************************************************************** ***********
It can also be configured as follows:
Httpd/conf/httpd.conf modified as follows:
Proxypass/balancer://mycluster/stickysession=jsessionid Nofailover=on
<proxy balancer://mycluster>
Balancermember http://127.0.0.1:9080/a loadfactor=1 route=jvm1
Balancermember http://127.0.0.1:10080/a loadfactor=1 route=jvm2
</Proxy>


The Tomcat/conf/server.xml are modified as follows
<engine name= "Standalone" defaulthost= "localhost" jvmroute= "jvm1" >
<engine name= "Standalone" defaulthost= "localhost" jvmroute= "jvm2" >


Start Tomcat1 and Tomcat2, and then start Apache
Visit: http://127.0.0.1/index.jsp






C:\WINDOWS\system32\drivers\etc\hosts
In the test machine's host file, specify the www.test.com corresponding to 127.0.0.1, then access in the browser:/HTTP/www.test.com























































"Java Web" Apache+tomcat Cluster for load balancing

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.