配置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-------------->
 

persistenceFrequencyreapIntervalSeconds设定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。

 

猜你喜欢

转载自darktemplar-h.iteye.com/blog/1574477