Apache+tomcat +mod_proxy Cluster load Balancing and session

Source: Internet
Author: User
Tags server port

Preface:

When playing Apache+tomcat +mod_jk cluster load Balancing and session, there is also a way to achieve, that is, online you Daniel said the mod_proxy reverse proxy.

Really get my knowledge cell Yangyang. After practice, make a report to yourself.

Environment Description :

Operating system: Win7 64-bit

javajdk:1.7
Apache:httpd-2.2.25-win32-x86-no_ssl.msi (Local installation path: D:\Program Files (x86) \apache2.2\)
tomcat:7.0.42 (http://tomcat.apache.org/download-70.cgi), if simulated on the same machine, download the zip version. 2 nodes are shown in the example
Mod_jk:mod_jk1.2.30_x64: (http://tomcat.apache.org/download-connectors.cgi)

Installation steps:

1. Installing the JDK
2. Install Apache2.2, use the default settings, and do not space in the installation path.
3. Unzip Tomcat

Configuration steps

To modify the Apache configuration:

About the files involved in the modification httpd.conf

(1)

Will

LoadModule Proxy_module modules/mod_proxy.so

LoadModule Negotiation_module modules/mod_negotiation.so
LoadModule Proxy_ajp_module modules/mod_proxy_ajp.so
LoadModule Proxy_balancer_module modules/mod_proxy_balancer.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

The comments in front of this section of code are released.

2. Simultaneously release the comment at the same time.


# Virtual Hostsinclude conf/extra/httpd-vhosts.conf

(3) Add code at the end of the file

 proxyrequests Off  <  proxy  balancer://cluster  >  Span style= "color: #000000;"  > Balancermember ajp://127.0.0.1:9988  loadfactor=1 route=TOMCAT1  balancermember ajp://127.0.0.1:9999  loadfactor=1 Route=TOMCAT2   </ proxy  " Span style= "color: #0000ff;" >>  
9999,  corresponding to   the Tomcat Server.xml
<connector port= "9988" protocol= "ajp/1.3" redirectport= "8443"/>
jvmroute= "TOMCAT1">
Meaning: Tell the Apache server to use the mod_proxy reverse proxy .

(4). Add code in CONF/EXTRA/HTTPD-VHOSTS.CONF
<VirtualHost*:80>// corresponds to httpd.conf  Server port number ServerAdmin [email protected] //corresponding httpd.conf Ser Veradmin  ServerName 127.0.0.1 serveralias localhost proxypass/balancer://cluster /Stickysession=jsessionid Nofailover=on //proxypass specifies the dispatcher. and session copy Proxypassreverse/balancer://cluster/errorlog "Logs/proxytest-error.log" //day Log information Customlog "Logs/lbtest-access.log" Common  </VirtualHost> 

Instance test

Start the Apache server first and test the server for normal startup. Start Tomcat again to test if it starts normally. See error log resolution If errors are encountered.

1. In the Web. xml file, add

<distributable/>

2. Writing test JSP code
<%@ Page Language="Java"Import="Java.util.*"Pageencoding="UTF-8"%><%@ Page Import="Java.text.SimpleDateFormat"%><!DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en"><Html><Head><Title>tomcat Cluster Testing</Title></Head><Body>Server information:<%StringDtm=NewSimpleDateFormat ("YYYY-MM-DD Hh:mm:ss"). Format (NewDate()); System.out.println ("["+REQUEST.GETLOCALADDR ()+":"+Request.getlocalport ()+"]"+DTM); Out.println ("<br>["+REQUEST.GETLOCALADDR ()+":"+Request.getlocalport ()+"]"+Dtm+"<br>");%>Session Distribution:<%Session.setattribute ("Name","Dennisit"); System.out.println ( "[session distribute" session ID:  "+session.getid ()); Out.println ( " "+ Session.getid () +< Span style= "color: #800000;" > "<br>" ); %> </body></html> 
/span>


Real-column effects

(2) Access http://localhost/tomcat_apche/Refresh 3 times effect See session ID same

and access to different Tomcat servers. indicates. Achieve load balancing and session sharing.

Done!!!

Apache+tomcat +mod_proxy Cluster load Balancing and session

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.