单机配置tomcat 8 集群
如何能在集群中的多个节点之间保持数据的一致性,会话(Session)信息是这些数据中最重要的一块。本文当采用tomcat默认集群配置( 下载tomcat 8.0 到本地, 保存为tomcat1,复制tomcat1 为tomcat2,
修改tomcat2的端口设置,可以参考下面这个链接修改端口。
http://crunchify.com/how-to-run-multiple-tomcat-instances-on-one-server/
http://www.ahlinux.com/uploadfile/2015/0121/20150121090122355.png
在 examples 目录下创建一个session.jsp文件,用来测试Cluster中两个Tomcat使用的Session是同一个Session,并且当其中一个Tomcat修改Session中的值时,第二个Tomcat会同样得到更新;代码如下:
现测试一下不添加cluster配置, 是什么情况。
http://www.ahlinux.com/uploadfile/2015/0121/20150121090122887.bmp
session的值是不一样的。
http://www.ahlinux.com/uploadfile/2015/0121/20150121090123926.bmp
接着我们添加cluster配置。
修改tomcat1 和tomcat2 conf/server.xml文件,将其中
修改tomcat1 和tomcat2 的web.xml
修改其中的WEB-INF/web.xml文件,在其中Servlet and JSP Examples节点后添加表明此应用与集群服务器复制 Session;
Servlet and JSP Examples.
Servlet and JSP Examples
重启tomcat1, tomcat2
http://www.ahlinux.com/uploadfile/2015/0121/20150121090125225.bmp http://www.ahlinux.com/uploadfile/2015/0121/20150121090127672.bmp
可以看到session同步成功!
http://laravel.iteye.com
[*] 本文来自:Linux教程网
页:
[1]