Use the httpd reverse load Balancer backend Tomcat,tomcat to implement the session cluster using the own cluster service;
Implementing the Environment:
node1:172.18.11.111 Tomcata
node2:172.18.11.112 TOMCATB
node3:172.18.11.113 anti-generational scheduler httpd
650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M00/82/B5/wKiom1deydWhuhoMAABcpOSvHto380.png "title=" 5.png " alt= "Wkiom1deydwhuhomaabcposvhto380.png"/>
Install Tomcat on Node1 and Node2, respectively:
]# vim/etc/profile.d/java.sh
Export JAVA_HOME=/USR
]# . /etc/profile.d/java.sh
]# Yum install tomcat tomcat-lib Tomcat-webapps tomcat-admin-webapps-y
]# cd/var/lib/tomcat/webapps/
]# mkdir TestApp
]# CD testapp/
]# mkdir classes Lib Web-inf meta-inf
]# vim/var/lib/tomcat/webapps/testapp/test.jsp
<%@ page language= "java"%>
<body>
<table align= "centre" border= "1" >
<tr>
<td>session id</td>
<% Session.setattribute ("magedu.com", "magedu.com"); %>
<td><%= Session.getid ()%></td>
</tr>
<tr>
<td>created on</td>
<td><%= session.getcreationtime ()%></td>
</tr>
</table>
</body>
]# Scp-r/var/lib/tomcat/webapps/testapp/node2:/var/lib/tomcat/webapps/
]# Vim/etc/tomcat/server.xml
Add in the Host configuration section:
<context path= "/test" docbase= "TestApp"/>
In Node2:
]# vim/var/lib/tomcat/webapps/testapp/test.jsp
<%@ page language= "java"%>
<body>
<table align= "centre" border= "1" >
<tr>
<td>session id</td>
<% Session.setattribute ("magedu.com", "magedu.com"); %>
<td><%= Session.getid ()%></td>
</tr>
<tr>
<td>created on</td>
<td><%= session.getcreationtime ()%></td>
</tr>
</table>
</body>
Start Tomcat on Node1 and Node2, respectively:
]# systemctl Start Tomcat.service
]# SS-TNL Monitor on port 8080;
(1) Configure Tomcat to enable the cluster:
In Node1:
]# Vim/etc/tomcat/server.xml
650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M01/82/B4/wKioL1de0ODTH0nXAADjUD8rZog374.png "title=" 8.png " Width= "734" height= "573" border= "0" hspace= "0" vspace= "0" style= "width:734px;height:573px;" alt= " Wkiol1de0odth0nxaadjud8rzog374.png "/>
In Node2:
]# Vim/etc/tomcat/server.xml
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/82/B4/wKioL1de0RnQw4RxAADlfl1Dcb8032.png "title=" 7.png " Width= "734" height= "587" border= "0" hspace= "0" vspace= "0" style= "WIDTH:734PX;HEIGHT:587PX;" alt= " Wkiol1de0rnqw4rxaadlfl1dcb8032.png "/>
(2) Add <distributable/> directive:
In Node1:
]# cp/etc/tomcat/web.xml/var/lib/tomcat/webapps/testapp/web-inf/
]# Vim/var/lib/tomcat/webapps/testapp/web-inf/web.xml
Add:<distributable/>
Copy the configuration file to Node2:
]# Scp/var/lib/tomcat/webapps/testapp/web-inf/web.xml node2:/var/lib/tomcat/webapps/testapp/web-inf/
Start Tomcat separately in Node1 and Node2:
]# systemctl Start Tomcat.service
On the NODE3:
Using the httpd mod_proxy module, MOD_PROXY_AJP module, mod_proxy_balancer module:
httpd using the AJP module means that Tomcat can only use the AJP linker.
Install httpd:
]# yum-y Install httpd
]# vim/etc/httpd/conf.d/mod_proxy_ajp.conf
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/82/B5/wKiom1dezbTRiSuwAABf2xYv8Gg835.png "title=" 6.png " alt= "Wkiom1dezbtrisuwaabf2xyv8gg835.png"/>
]# httpd-t
]# systemctl Start Httpd.service
In the browser input: http://172.18.11.113/test/test.jsp
Different hosts based on the backend of the scheduler, but the session remains the same;
650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M01/82/B6/wKiom1de0bvy5uJ4AABXnHun03k176.png "style=" float: none; "title=" 26.png "alt=" Wkiom1de0bvy5uj4aabxnhun03k176.png "/>
650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M01/82/B4/wKioL1de0szC5ZEdAABbc6Gkj34474.png "style=" float: none; "title=" 27.png "alt=" Wkiol1de0szc5zedaabbc6gkj34474.png "/>
The above is based on the Tomcat session cluster approach to achieve session retention.
Tomcat Session Cluster