1、分别在3台电脑(192.168.1.241,192.168.1.242,192.168.1.243)安装tomcat并启动(端口为8080);
2、启动nginx服务器(此处为单点,192.168.1.114),nginx端口为80;(配置见nginx启动配置说明)
3、浏览器访问192.168.1.114,能随机访问3台服务。
4、但是问题是,如果有登录(session),则在A服务器登录后,前往B服务器的请求会被拦截,提示没有登录;
5、随之需要解决session同步(复制)的功能。
6、赢单项目已经集成了ehcache缓存机制,利用ehcache的同步可以轻易实现session同步;
7、修改ehcache.xml,如下:
<!-- hostName需要配置真实的IP地址 @author G·Marshal GY -->
<cacheManagerPeerListenerFactory
class="net.sf.ehcache.distribution.RMICacheManagerPeerListenerFactory"
properties="hostName=localhost, port=40001, remoteObjectPort=40002, socketTimeoutMillis=2000" />
<!-- 配置自动发现方式 timeToLive的值如下: @author G·Marshal GY
0 is restricted to the same host
1 is restricted to the same subnet
32 is restricted to the same site
64 is restricted to the same region
128 is restricted to the same continent
255 is unrestricted
-->
<cacheManagerPeerProviderFactory
class="net.sf.ehcache.distribution.RMICacheManagerPeerProviderFactory"
properties="peerDiscovery=automatic, multicastGroupAddress=230.0.0.1,
multicastGroupPort=4446, timeToLive=1" />
<!-- 会话活动缓存 -->
<cache name="shiro-activeSessionCache"
maxElementsInMemory = "20000"
maxEntriesLocalHeap="2000"
eternal="false"
timeToIdleSeconds="0"
timeToLiveSeconds="0"
overflowToDisk="false"
statistics="true">
<!-- replicateAsynchronously=false 该属性默认是true,意思就是异步复制cache,把它设置为false是为了防止,这边后台session还没复制过去到B服务器呢,前台已经跳转到B服务器了 -->
<cacheEventListenerFactory
class="net.sf.ehcache.distribution.RMICacheReplicatorFactory"
properties="replicateAsynchronously=false" />
</cache>
8、再分别启动3台服务,访问192.168.1.114/R-yingdan,体验集群的乐趣。
创建人 | 高元_G·Marshal |
文档编辑权限 | 创建者私有 |
文档阅读权限 | 来自分类 |
分类阅读权限 | 所有人 |
分类编辑权限 | 所有人 |
分类审核权限 | 无 |
修改日期 | 修改人 | 备注 |
2017-08-03 11:17:27[当前版本] | 高元_G·Marshal | 添加内容 |
2017-08-03 11:10:29 | 高元_G·Marshal | CREAT |