Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Session sharing based on apache+tomcat

2025-01-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/03 Report--

apache+tomcat Previous article, implemented Load Balancer, now we implement session sharing

First, tomcat cluster configuration, session synchronization configuration:

tomcat1 configuration

A. Modify Engine node information:

B. Removed comments

C. Modify Cluster node information

tomcat2 configuration:

A. Modify Engine node information:

B. Removed comments

C. Modify Cluster node information

Modify the web.xml file under WEB-INF directory in web application and add tag

Just add it directly to the front

This step is required to do tomcat clustering, otherwise the user's session will not work properly.

Notes:

1. mcastAddr="224.0.0.1" This is the main broadcast address, so you need to turn on the network card multicast function.

route add -net 224.0.0.0 netmask 240.0.0.0 dev eth0

Run separately on each machine

2. Check port status: Netstat -antl| grep 4001 synchronous listening port (2 tomcat on different machines)

tocat1

tomcat2

3. Test broadcast:

java -cp tomcat-replication.jar MCaster 224.0.0.1 45564 Terminal1

java -cp tomcat-replication.jar MCaster 224.0.0.1 45564 Terminal2

tomcat-replication.jar Download:[url] http://cvs.apache.org/<$fhanik/tomcat-replication. jar [/url] If there are two machines, you can grab the package with tcpdump

II. Test cluster and session synchronization

Create a web.xml file under the WEB-INF directory under the new test directory under the webapps of the two tomct

TomcatDemo

Create print.jsptest.jsp under webapps

Print.jsp :

"); Enumeration e = session.getAttributeNames(); while (e.hasMoreElements()) { String name = (String)e.nextElement(); String value = session.getAttribute(name).toString(); out.println( name + " = " + value+"

"); System.out.println( name + " = " + value); }%> 3?

?:

Restart all services. Visit [url]http://192.168.19.199/test/print.jsp[/url] as shown in the figure, you can see that the tomcat cluster configuration has completed the viewing of Session replication: in the same window, enter the name and value, and you can see the logs with the same content in the two tomcat logs, indicating success.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report