Objective
The two days were exposed to terracotta when learning ehcache distributed caching schemes. A few years ago just do development work want to use terracotta cluster Springbeans, at that time the online data, try for a long time did not succeed did not go on.
So I also collected some information on the Internet, found that this thing has been very mature, there are many in-depth applications of products, distributed caching, scheduling and so on. Refer to the description on the Web:
Terracotta is a well-known open source Java cluster platform developed by the American Terracotta Company. It implements a cluster-specific abstraction layer between the JVM and Java applications, with its unique incremental detection, intelligent directional transfer,
distributed collaboration, server mirroring, fragmentation and other technologies, Allows the user to implement the seamless migration of a stand-alone Java application to a clustered application without changing the existing system code. Enables users to focus on business logic development, with
terracotta responsible for high-performance, high-availability, and stable enterprise-class Java clusters
Operating Environment JDK1.6.22 + Tomcat6 + Apache2.2.19 + Terracotta Open Source 3.5.2 + zlib1.2.3 (install Apache required) simulate dual-machine environment: Native window 7 operating system (cloth tomcat,t erracotta,ip:192.168.1.51) + VMware virtual machine Linux system (apache,tomcat,ip:192.168.1.207).
In the Terracotta + Apache + Tomcat load Balancing framework, Terracotta plays the role of Session server, and the session cache and replication between real-time and multiple machines (JVM field level, higher efficiency than TOMCAT).
implementation of the cloth in the sudden
Win7 system
1. Install terracotta (download address: http://www.terracotta.org/dl/oss-download-catalog)
After downloading directly clicks installs, after completes the attention installs the sessions directory, inside has its jetty server's example and the dependent jar. The Cart.war was used by me as a test project for the cluster.
2. Install the Tomcat JDK and so on omitted (on-line search material).
LinUX system
1. Install the Tomcat JDK and so on omitted (on-line search material)
2. Install zlib-1.2.3.tar.gz (download address: http://ishare.iask.sina.com.cn/f/14331439.html?from=like), Apache server installation without this library will be an error.
Copy zlib-1.2.3.tar.gz to/usr/directory
# TAR-ZXVF Zlib-1.2.3.tar.gz
# CD zlib-1.2.3
#./configure
# make
# make Install
3. Install Apache server (download address: http://httpd.apache.org/download.cgi)
Copy the httpd-2.2.19.tar.gz to the/usr/directory
# TAR-ZXVF Httpd-2.2.19.tar.gz
# cd/usr/httpd-2.2.19/
#./configure--prefix=/usr/local/apache--enable-modules=so--enable-mods-shared=all--enable-proxy-- Enable-proxy-connect--enable-proxy-ftp--enable-proxy-http--ENABLE-PROXY-AJP--enable-proxy-balancer-- Enable-rewrite
# make
# make Install
4.apache has been installed to/usr/local/apache
Step two, configure the cluster
Configure Tomcat (same as Tomcat for two machines)
1. Copy ${Terracotta_home}/sessions/terracotta-session-1.1.2.jar and ${terracotta_home}/common/ Terracotta-toolkit-1.3-runtime-3.2.0.jar to the Lib directory of the Tomcat installation directory.
2. Modify the Conf/context.xml file
<Context>
<!--Default set of monitored resources-->
<WatchedResource>WEB-INF/web.xml< /watchedresource>
<!--plus this sentence, Terracotta agent httpservletsession-->
<valve classname= " Org.terracotta.session.TerracottaTomcat60xSessionValve "tcconfigurl=" 192.168.1.51:9510 "/>
</context >
3. Modify the Conf/server.xml file
A. Guaranteed <connector port= "8009" protocol= "ajp/1.3" redirectport= "8443"/> is not commented, the AJP protocol is the binary communication protocol with the back-end host when the Apache load is balanced.
B. If you configure a sticky session, you need to configure the server pathname Jvmroute.
<!--sticky session configuration
<engine name= "Standalone" defaulthost= "localhost" jvmroute= "jvm1" >
-->
<engine name= "Standalone" defaulthost= "localhost" >
Configuring the Apache Server
1.Proxy configuration, create the file and edit the following, and save it as/usr/local/apache/conf/extra/httpd-modproxy.conf
<Location/server-status>
sethandler server-status order
Deny,allow Deny to all
Allow from All
</Location>
# Monitor the load host activity status, respond to connection and traffic, etc., the production environment suggestion take off.
<Location/balancer-manager>
SetHandler Balancer-manager Order Deny,allow Deny to all Allow to all
</Location>
Proxyrequests off
Proxypass/cart Balancer://tomcatcluster Nofailover=on
# Sticky Session Use the following configuration
# Proxypass/cart Balancer://tomcatcluster Stickysession=jsessionid|jsessionid Nofailover=on
# reverse proxy, content-location of response header information
Proxypassreverse/cart Balancer://tomcatcluster
<proxy balancer://tomcatcluster>
# Sticky Session Configuration
# Balancermember Ajp://192.168.1.51:8009/cart loadfactor=1 route=jvm1
# Balancermember Ajp://192.168.1.207:8009/cart loadfactor=1 route=jvm2
Balancermember Ajp://192.168.1.51:8009/cart
Balancermember Ajp://192.168.1.207:8009/cart
# status=+h for configuration hot standby, when all machines are over, will not request the machine.
# Balancermember http://192.168.1.51:8009 status=+h
# by weight
# Proxyset Lbmethod=bytraffic
# by load, that is, less load distribution requests
# Proxyset Lbmethod=bybusyness
# By the number of requests
Proxyset lbmethod=byrequests
</Proxy> Note:
1.ProxyPass is a mapping strategy, and Stickysession=jsessionid|jsessionid is necessary when the sticky session strategy is used.
2.BalancerMember is configured with the address of the child machine.
3.ProxySet configuration is the load balancing strategy bytraffic, bybusyness, byrequests, I configure here is the number of requests.
4. When the right to use heavy load policy balancermember can add loadfactor weight attribute.
5. When a sticky session is required, the Balancermember should add the route route attribute, corresponding to the configuration in Tomcat's context.xml.
2. Modify the conf/httpd.conf file
A. Ensure that the following points are not commented
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
LoadModule status_module modules/mod_status.so
B. Add the following to import the proxy configuration file:
# proxypass Config
Include conf/extra/httpd-modproxy.conf
so far, the configuration is done .
Step three, start the service
1. Start the terracotta server first, or Tomcat will warn because terracotta is not found.
${terracotta_home}/bin/start-tc-server.bat
2. Start tomcat of two machines,
${tomcat_home}/bin/startup.bat or startup.sh (Linux system), if the connection with the terracotta successful, you can see the following screen.
3. Start Apache Server
#/usr/local/apache/bin/apachectl Start (stop service is Apachectl stop).
Step Fourth, test results
The Cart.war sample is provided earlier, and I have placed it in advance under Tomcat WebApp.
Open Browser Input: Http://192.168.1.207/cart, display map success:
Refresh the page after several times to view Http://192.168.1.207/balancer-manager,
The elected is evenly distributed and the load balance works.
Shut down a tomcat in the base and refresh the page again without any problems. The user completely does not feel the host failure. This is the legendary failover bar. Oh, in the company has no chance to practice can only get their own play.
Then open the terracotta console to see, session is cached on the host. There are two sessions because I opened two browsers, in fact, the load-balanced two Tomcat is shared session, of course, can also be designed to Web applications without user status, it does not need terracotta.