Apache+tomcat Cluster under Session replication

Source: Internet
Author: User
Tags server port

Because of the need for work, I need to do an Apache load-balanced HTTP request on this machine, to the Tomcat cluster processing, and the session will be replicated on different Tomcat demo. The process is posted as follows:

Http://wenku.baidu.com/link?url=1Wy1oeJDLaBxnSTPLH0NPyYy0EGP1JokrYQfQhFj_ Uot4dhyh8kg-q3n1tzhemu8otihuk5jprtopxhaau9fd1q9swft-mhmm73n3uez9ko--Good article, focus on recommendation

Http://www.open-open.com/lib/view/open1375282916217.html--with JK plug-in Apache load Balancing

http://nanquan.iteye.com/blog/1533906

http://jackandroid.iteye.com/blog/627147

Http://www.cnblogs.com/peter9/archive/2011/12/18/2362138.html


One: Preparation work

LoadModule proxy_module modules/mod_proxy.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 /mod_proxy_http.so
LoadModule proxy_scgi_module modules/mod_proxy_scgi.so
#LoadModule reqtimeout_module modules/mod_reqtimeout.so
#LoadModule rewrite_module modules/mod_rewrite.so
LoadModule setenvif_module Modules/mod_setenvif.so

Basic knowledge: Apache is the HTTP server, according to a certain configuration, using a reverse proxy, processing HTTP requests and forwarding to the corresponding Tomcat for processing. There are two ways to copy a session. 1.1. Sticky session. Requests from the same window are handed to the same tomcat, avoiding the session jumping between different tomcat. The disadvantage is that this tomcat hangs out and the session is empty. You need to configure the following in the Workers.properties file:
Worker.lbcontroller.sticky_session=true
1.2.session CopyReplication of sessions between Tomcat in the form of broadcasts has an impact on server performance and needs to be configured in Web.xml as follows:
<distributable/>  

1.3.apache Configuration 1.3.1.httpd.conf Configuration

Httpd-vhosts.conf
Access to httpd.conf directory files:

LoadModule proxy_module modules/mod_proxy.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 /mod_proxy_http.so
LoadModule proxy_scgi_module modules/mod_proxy_scgi.so
Remove the comments from these seven lines before opening the modules.
Include conf/extra/httpd-vhosts.conf
Find the line of code, remove the comment
Enter the lowest line to the httpd.conf file and add the following:
#分配请求
proxyrequests off   
<proxy balancer://cluster>    
	balancermember ajp://127.0.0.1:9009 Loadfactor=1 route=tomcat1 
	balancermember ajp://127.0.0.1:10009 loadfactor=1 route=tomcat2
Here 127.0.0.1 represents a local test environment, similar to localhost, to note that the parameters 9009 and route, here that Apache will be based on certain rules to distribute the request to the local 9009 port, called TOMCAT1 Tomcat and local 10009 port, Called Tomcat2, on Tomcat.

1.3.1.httpd-vhosts.conf ConfigurationGo to httpd-vhosts.conf, the last line add the following code, virtual site:
<virtualhost *:80>            
	ServerAdmin webmaster@dummy-host2.localhost           
	ServerName 127.0.0.1          
	localhost            
	proxypass/balancer://cluster/stickysession=jsessionid nofailover=on           
	proxypassreverse/ balancer://cluster/           
	ErrorLog "Logs/lbtest-error.log"           
	customlog "Logs/lbtest-access.log" Common       
</VirtualHost>


Three: Tomcat configurationI have two Tomcat, as pictured:

Under Popular Science: I am testing on this machine, so different tomcat related ports are not repeatable. Tomcat has three types of ports, admin port (default 8005), HTTP port (default 8080), AJP port (default 8009). First modify the TOMCAT1 related port configuration, in the Server.xml


TOMCAT1: 3.1. Modify server port to 9005


3.2. Modify connection port to 9080


3.3. Modify Jvmroute and related AJP ports
Note that the configuration matches here and in Apache before: the following:

3.4.TOMCAT Configuration to open session replicationLocate the following code:
<cluster classname= "Org.apache.catalina.ha.tcp.SimpleTcpCluster"  channelsendoptions= "8" > </span>
Add the following statement below it:


Similar configuration on TOMCAT2.
Four: Application configuration The application directory is established on 4.1.TOMCAT1:



4.2.tomcat1 on test.jsp:
  <%@ page contenttype= "text/html; Charset=utf-8 "%> <%@ page import=" java.util.* "%>  

4.3.tomcat1 on Web.xml:
<?xml version= "1.0" encoding= "UTF-8"?> <web-app xmlns= "HTTP://JAVA.SUN.COM/XML/NS/J2EE" 
Http://www.w3.org/2001/XMLSchema-instance "xsi:schemalocation=" http://java.sun.com/xml/ns/j2ee http:// Java.sun.com/xml/ns/j2ee/web-app_2_4.xsd "version=" 2.4 "> 
  <display-name>test</display-name> 
   <distributable/> 
The point is:

V: TestingThe input Url,apache will be forwarded

Refresh to TOMCAT1:

Refresh to TOMCAT2:

Keep refreshing, different tomcat to get the same sessionid, and the same value in the session, completed session copy





































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.