<%@ page language= "Java" %>
Client testing, because did the session sticky, will always be dispatched to the back end of a server, such as mine has been tomcata
Turn off the Tomcata and you will be dispatched to the TOMCATB.
2. Programme II: MOD_PROXY_AJP
Using MOD_PROXY_AJP, only need to change the mod_proxy_http http to AJP, port 8080 to 8009, you need to note that the front end with a AJP, you can put the back end of the Tomcat 8080 port comment out, do not let it listen, This allows for higher security.
Vim/etc/httpd/conf.d/lb_tomcat.conf
header add set-cookie "routeid=.%{balancer_worker_route}e; path=/" env=BALANCER_ROUTE _changed<proxy balancer://tcsrvs> balancermember ajp://172.16.1.10:8009/testapp route=tomcata loadfactor=1 balancermember ajp://172.16.1.3:8009/testapp route= Tomcatb loadfactor=2 proxyset lbmethod=byrequests ProxySet stickysession=ROUTEID</Proxy>< virtualhost *:80> servername lb.qhdlink.com ProxyVia On proxyrequests off <proxy *> require all granted </proxy> proxypass / balancer://tcsrvs/ <location / > require all granted </Location></VirtualHost>
Close session sticky, client view
3. Programme three: MOD_JK
This scenario requires the MOD_JK module
Need to install this file tomcat-connectors-version.tar.gz
Configuration file:
Vim/etc/httpd/conf.d/mod_jk_lb.conf
LoadModule Jk_module Modules/mod_jk.sojkworkersfile/etc/httpd/conf.d/workers.propertiesjklogfile Logs/mod_ Jk.logjkloglevel debugjkmount/* Tcsrvsjkmount/jk-status Stat
Vim/etc/httpd/conf.d/workers.properties
Worker.list=tcsrvs,statworker.tomcata.host=172.16.1.10worker. Tomcata.port=8009worker. Tomcata.type=ajp13worker. Tomcata.lbfactor=1worker. Tomcatb.host=172.16.1.3worker. Tomcatb.port=8009worker. Tomcatb.type=ajp13worker. Tomcatb.lbfactor=2worker.tcsrvs.type=lbworker.tcsrvs.balance_workers=tomcata,tomcatbworker.tcsrvs.sticky_ Session=1worker. Stat.type=status
4.tomcat Session Cluster
Enable clustering on two Tomcat server.xml configurations
Add the following configuration and comment out port 8080
Note that the address= "auto" is changed to the IP address of the host in the following content
<cluster classname= "Org.apache.catalina.ha.tcp.SimpleTcpCluster"
channelsendoptions= "8" >
<manager classname= "Org.apache.catalina.ha.session.DeltaManager"
Expiresessionsonshutdown= "false"
Notifylistenersonreplication= "true"/>
<channel classname= "Org.apache.catalina.tribes.group.GroupChannel" >
<membership classname= "Org.apache.catalina.tribes.membership.McastService"
Address= "228.100.0.4"
Port= "45564"
Frequency= "500"
Droptime= "/>"
<receiver classname= "Org.apache.catalina.tribes.transport.nio.NioReceiver"
address= "Auto"
port= "4000"
autobind= "100"
selectortimeout= "5000"
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"/>
</Channel>
<valve classname= "Org.apache.catalina.ha.tcp.ReplicationValve"
Filter= ""/>
<valve classname= "Org.apache.catalina.ha.session.JvmRouteBinderValve"/>
<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.JvmRouteSessionIDBinderListener"/>
<clusterlistener classname= "Org.apache.catalina.ha.session.ClusterSessionListener"/>
</Cluster>
and add a context component to host
Unpackwars= "true" autodeploy= "true" >
<context path= "/test" docbase= "/myapps/webapps" reloadable= "true"/>
Create a Directory
[[email protected] tomcat]# Mkdir-pv/myapps/webapps/{classes,lib,web-inf}
Create a test page
Create ab two different pages like the one above
[Email protected] tomcat]# vim/myapps/webapps/index.jsp
Copy Web. XML to the specified directory
[email protected] tomcat]# CP web.xml/myapps/webapps/web-inf/
Edit Web-inf/web.xml
Add <distributable/> to any non-paragraph
[Email protected] tomcat]# Vim/myapps/webapps/web-inf/web.xml
Anti-generational server configuration
[Email protected] conf.d]# vim mod_jk_proxy.conf
LoadModule Jk_module Modules/mod_jk.sojkworkersfile/etc/httpd/conf.d/workers.propertiesjklogfile Logs/mod_ Jk.logjkloglevel debugjkmount/* Tcsrvsjkmount/jk-status Stat
[Email protected] conf.d]# vim workers.properties
Worker.list=tcsrvs,statworker.tomcata.host=172.16.1.10worker. Tomcata.port=8009worker. Tomcata.type=ajp13worker. Tomcata.lbfactor=1worker. Tomcatb.host=172.16.1.3worker. Tomcatb.port=8009worker. Tomcatb.type=ajp13worker. Tomcatb.lbfactor=2worker.tcsrvs.type=lbworker.tcsrvs.balance_workers=tomcata,tomcatbworker.tcsrvs.sticky_ Session=0worker. Stat.type=status
HTTPD Services and Tomcat services for three hosts respectively
Client Testing
You can see that the reverse server polls the back-end two tomcat servers in the order of ABB, but the ID is not changed to achieve session cluster.
5.tomcat Session Server (MSM)
Then the configuration of the environment, the principle of this scheme is to put all the sessions on the same back-end Tomcat server, when the back end of this tomcat server down, the entire building will not be able to provide services, so also to the Tomcat server to be highly available.
This build scenario requires memcached as a side-hanging cache server, so you need to download and start the memcached service in advance.
Stop two Tomcat services and restore the Server.xml configuration file
Comment out port 8080 and add jvmroute to the engine, as follows
<engine name= "Catalina" defaulthost= "localhost" jvmroute= "Tomcata" >
Or
<engine name= "Catalina" defaulthost= "localhost" jvmroute= "TOMCATB" >
Adding configuration content to the host segment
<context path= "/test" docbase= "/myapps/webapps" reloadable= "true" >
<manager classname= "De.javakaffee.web.msm.MemcachedBackupSessionManager"
Memcachednodes= "n1:172.16.1.10:11211,n2:172.16.1.3:11211"
failovernodes= "N1"
Requesturiignorepattern= ". *\. (ico|png|gif|jpg|css|js|html|htm) $ "
Transcoderfactoryclass= "De.javakaffee.web.msm.serializer.javolution.JavolutionTranscoderFactory"
/>
</Context>
Importing class files
Memcached-session-manager Project Address, http://code.google.com/p/memcached-session-manager/
Download the following jar file to the Lib directory in the Tomcat installation directory of each tomcat node, where ${version} is replaced with the version number you need, tc${6,7,8} to be the same version number as the Tomcat version.
Memcached-session-manager-${version}.jar
Memcached-session-manager-tc${6,7,8}-${version}.jar
Spymemcached-${version}.jar
Msm-javolution-serializer-${version}.jar
Javolution-${version}.jar
Place all classes in the/usr/share/java/tomcat directory.
Start the Tomcat service to see that the reverse server polls the back-end two tomcat servers in AB order, but the session ID does not change.
Apache implements Tomcat proxy, load balancing, and session binding based on three different scenarios