配置glassfish cluster的session复制

 

源文件修改

web.xml

 

<!---------------------web.xml--------------------->
...
 <distributable id="sessionDistribute"/>
...
<!---------------------web.xml end------------------>
 

 

必须指明应用的session是distribute的,否则即使glassfish启用了session复制功能也不会生效。

sun-web.xml

 

<!-------------------sun-web.xml------------------>
...
<session-config>
        <session-manager persistence-type="replicated">
            <manager-properties>
                <property name="persistenceFrequency" value="time-based"/>
                <property name="reapIntervalSeconds" value="30"/>
                <property name="relaxCacheVersionSemantics" value="true"/>
            </manager-properties>
            <store-properties>
                <property name="persistenceScope" value="session"/>
            </store-properties>
        </session-manager>
</session-config>
...
<!-------------------sun-web.xml end-------------->
 

 

persistenceFrequency和reapIntervalSeconds设定session的同步频率为30

relaxCacheVersionSemantics忽略session版本号,解决多个请求同步时的session异常。

applicationContext-security.xml

 

<!----------applicationContext-security.xml--------->
...
<http>
...
<session-management>
<concurrency-control max-sessions="2" error-if-maximum-exceeded="false" />
</session-management>
...
</http>
...
<!---------applicationContext-security.xml end------>
 

 

设置spring-security允许同一个用户多次登录。否则启用session复制后,会导致不能正常登录。

 

Glassfish设置

Web Container->Manager Properties

修改Reap Interval30,与sun-web.xml中的配置一致。

 

Additional Properties下增加新的属性

relaxCacheVersionSemantics=true

persistenceFrequency=time-based

 

升级步骤

1、deploy新的application版本,如:webapp-demo:1.0.1

去掉StatusEnabled复选框,并将AvailabilityEnabled复选框选中,targets中选则设置好的cluster

2、使用命令升级当前离线的实例instance-2

asadmin enable --target instance-2  webapp-demo:1.0.1

3、等待30秒以上(超过session的复制间隔)

4、修改nginx配置,将线上实例instance-1替换成已升级完的实例instance-2

5、使用命令升级当前离线的实例instance-1

asadmin enable --target instance-1  webapp-demo:1.0.1

6、重复步骤34

 

配置过程中遇到的问题:

1、session中保存的attribute对象的class都必须实现java.io.Serializable接口,且对象的所有属性的class也必须实现java.io.Serializable接口,否则session复制的时候会出错。

2、session复制是通过GMS组播实现的,iptables要么关闭,要么允许GMS组播的ip。

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值