Tomcata:# vim /web/webapps/index.jsp<%@ page language= "Java" %>Restart the Tomcat service deployment:
# Service Tomcat stop# service Tomcat start
The access tests are as follows:
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/88/70/wKiom1f3cOzTF69NAAC-rAEnpUg512.png "style=" float: none; "title=" Tomsamlee1.png "alt=" Wkiom1f3coztf69naac-raenpug512.png "/>
650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M00/88/6C/wKioL1f3cO_jPD00AADBjw-xilA024.png "style=" float: none; "title=" Tomsamlee2.png "alt=" Wkiol1f3co_jpd00aadbjw-xila024.png "/>
Configure HTTPD to implement load balancing reverse proxy tomcat
The configuration file looks like this:
# vim/etc/httpd/conf.d/proxy.conf<proxy balancer://lbcluster> Balancermember ajp://192.168.56.11:8009 Loadfactor=1 route=tomcata balancermember ajp://192.168.56.12:8009 loadfactor=1 route=TomcatB</Proxy>< VirtualHost *:80> ServerName www.samlee.com Proxyvia on proxyrequests off proxypassreverse/balancer://lbcluster/ Proxypass/balancer://lbcluster/</virtualhost>
Restart the HTTPD service access test as follows:
# Service httpd Restart
The test is as follows:
650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M02/88/74/wKiom1f4abmQh3DxAAE-RqgzfK8266.gif "title=" Tomcathttp1.gif "alt=" Wkiom1f4abmqh3dxaae-rqgzfk8266.gif "/>
Above we can see that the reverse proxy and load balancer are already in effect.
configuring HTTPD to implement session sticky sessions binding
If Tomcat is running a dynamic site, then the above byrequest load balancing scheduling algorithm has a lot of problems, may just login to the site and then refresh back to no login status, so we will implement session sticky, in fact session Sticky is our previous LVS of the SH algorithm, and nginx Ip_hash implementation of the effect
The configuration file looks like this:
# Vim/etc/httpd/conf.d/proxy.confheader Add Set-cookie "routeid=.%{balancer_worker_route}e; path=/"Env=balancer_route_changed<proxy balancer://lbcluster> balancermember ajp://192.168.56.11:8009 Loadfactor=1 route=tomcata balancermember ajp://192.168.56.12:8009 loadfactor=1 Route=TomcatB ProxySet stickysession= Routeid</proxy><virtualhost *:80> ServerName www.samlee.com Proxyvia on proxyrequests off Proxypassreverse /balancer://lbcluster/proxypass/balancer://lbcluster/</virtualhost>
Restart the HTTPD service access test as follows:
# Service httpd Restart
The test is as follows:
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/88/71/wKioL1f4dBihp0dFAADDS9gYluY866.gif "title=" Tomcathttp2.gif "alt=" Wkiol1f4dbihp0dfaadds9gyluy866.gif "/>
As shown, the display has successfully bound the session sessions to the Tomcata host.
Configuring the Tomcat implementation session cluster sessions information sharing replication:
* Using session sticky will have a lot of problems, if a host is down, then the user's session is lost, so we can also save user session through session cluster.
* * What is session Cluster?? Under normal circumstances, the session information is stored in the user's access to the server, the server down, the user's session is lost, but we can use the session cluster way to achieve the user's session information is stored on the backend all the servers, so that, The session is not lost regardless of which server the user is accessing.
Four common session Manager
**standardmanager**persistentmanager: Session information can be saved in persistent storage **deltamanager: Sharing session information to other nodes via multicast * * Backupmanager: Sharing session information to a specific node
Before you configure Tomcat, the session sticky of the httpd configuration is canceled:
To build the Deltamanager cluster steps:
1. Add the contents of the engine or host container in the server.xml of each node; Note Modify the multicast address address= "228.0.0.4" in the membership component, It is suggested that the address in receiver should be modified to deliver the heartbeat information.
2, in each node to use the multicast address to add multicast routing, format:
Route add-net $MCAST _address netmask 255.255.255.255 Dev eth0
3. Add <distributable\>; in the corresponding application's Web. xml
The edit configuration Tomcat configuration file is as follows (two Tomcat hosts to configure):
The following content is placed in the <Host /> <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.0.1.7" &Nbsp; port= "45564" frequency= " " droptime= "/> <" Receiver classname= "Org.apache.catalina.tribes.transport.nio.NioReceiver" address= "192.168.56.12" --here to modify the native IP address port= "4000" autobind= " " selectortimeout= " " 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 " &Nbsp; 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&nbSp;classname= "Org.apache.catalina.ha.session.ClusterSessionListener"/> </cluster >
The Web. xml file in configuration Web-inf is as follows:
# cp/usr/local/tomcat/webapps/root/web-inf/web.xml/web/webapps/web-inf/# Vim/web/webapps/web-inf/web.xml #添加下面这一行 , in </web-app> <distributable/>--copy configuration file Web. xml to tomcata host # scp/web/webapps/web-inf/web.xml [email protected]:/web/webapps/web-inf/--Copy the configuration file Server.xml to Tomcata host and modify the IP address and the virtual host jvmroute# as required scp/usr/local/tomcat/ conf/server.xml [Email protected]:/usr/local/tomcat/conf/
Add multicast routing addresses for each Tomcat node (two Tomcat hosts to configure):
Route add-net 228.0.1.7 netmask 255.255.255.255 Dev eth0
Restart the Tomcat service
# Service Tomcat stop# service Tomcat start
The access tests are as follows:
650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M00/88/75/wKiom1f4gY7jT5pZAAEW7R4l5fo298.gif "title=" Tomcathttp3.gif "alt=" Wkiom1f4gy7jt5pzaaew7r4l5fo298.gif "/>
We see that the session ID has not been accessed since then, proving that the session sharing has been configured successfully.
This article is from the "Opensamlee" blog, make sure to keep this source http://gzsamlee.blog.51cto.com/9976612/1860175
HTTPD load balancer for high performance Web services Tomcat implementation session sticky and session Cluster