2015年7月31日星期五

JDG_010:使用JDG外部缓存HTTP Session

环境:JBoss EAP 6.4.0 + JBoss Data Grid 6.5.0

JBoss Data Grid 6.5.0 有个新特性:可以把JDG 作为外部缓存来存储HTTP Session,这样做的好处是:
(1)减轻了应用服务器的内存压力以及集群节点间的 Session 复制。
(2)利用JDG的横向扩展能力,可以容纳更多的 Session 对象。
(3)利用JDG的数据冗余机制,可以保证 Session 对象不丢失。

本文介绍如何使用JDG外部缓存HTTP Session,其中
(1)使用两个JBoss EAP 6.4.0 组成Standalone Mode 集群
(2)使用一个JBoss Data Grid Server 作为外部缓存来存储HTTP Session(可以扩展成多个节点)

主要步骤:

1. 配置JBoss  EAP Standalone Mode 集群

1.1 安装与启动 JBoss EAP 6.4.0
(1)unzip jboss-eap-6.4.0.zip
(2)cd jboss-eap-6.4/bin
(3)./standalone.sh
(4)http://localhost:9990/,访问出错,提示创建用户
(5)./add-user.sh
(6)http://localhost:9990/,点击Try again,输入管理员账户口令
(7)停止 EAP

1.2 配置两个节点的JBoss EAP 集群
(1)mkdir node1
(2)cp -r ./jboss-eap-6.4/standalone/configuration ./jboss-eap-6.4/standalone/deployments ./jboss-eap-6.4/standalone/lib node1
(3)mkdir node2
(4)cp -r ./jboss-eap-6.4/standalone/configuration ./jboss-eap-6.4/standalone/deployments ./jboss-eap-6.4/standalone/lib node2
(5)./standalone.sh -Djboss.server.base.dir=/Users/maping/Redhat/eap/demo/node1 -c standalone-ha.xml -b 127.0.0.1 -bmanagement 127.0.0.1 -u 239.255.100.100 -Djboss.socket.binding.port-offset=100 -Djboss.node.name=node1
(6)./standalone.sh -Djboss.server.base.dir=/Users/maping/Redhat/eap/demo/node2 -c standalone-ha.xml -b 127.0.0.1 -bmanagement 127.0.0.1 -u 239.255.100.100 -Djboss.socket.binding.port-offset=200 -Djboss.node.name=node2
(7)http://localhost:10090/console/ 部署 cluster_test.war
(8)http://localhost:10190/console/ 部署 cluster_test.war
(9)http://localhost:8180/cluster_test/
(10)http://localhost:8280/cluster_test/ 
分别刷新 http://localhost:8180/cluster_test/页面和http://localhost:8280/cluster_test/ 页面,如果发现统计数字在两个页面中是持续增加的,就说明集群配置成功。

 2. 安装与启动 JBoss Data Grid 6.5.0
 (1)unzip jboss-datagrid-6.5.0-server.zip
 (2)cd jboss-datagrid-6.5.0-server/bin
 (3)./standalone.sh

 3. 配置JDG外部缓存HTTP Session

 3.1 修改node1下的standalone-ha.xml文件
 (1)把原来的cache-container name="web" 内容

<cache-container name="web" aliases="standard-session-cache" default-cache="repl" module="org.jboss.as.clustering.web.infinispan">
    <transport lock-timeout="60000"/>
    <replicated-cache name="repl" mode="ASYNC" batching="true">
        <file-store/>
    </replicated-cache>
    <replicated-cache name="sso" mode="SYNC" batching="true"/>
    <distributed-cache name="dist" mode="ASYNC" batching="true" l1-lifespan="0">
        <file-store/>
    </distributed-cache>
</cache-container>
替换为
<cache-container name="web" default-cache="default-cache" module="org.jboss.as.clustering.web.infinispan" statistics-enabled="true">
    <transport lock-timeout="60000"/>
    <replicated-cache name="default-cache" mode="SYNC" batching="true">
        <remote-store cache="default" socket-timeout="60000" preload="true" passivation="false" purge="false" shared="true">
            <remote-server outbound-socket-binding="remote-jdg-server1"/>
        </remote-store>
    </replicated-cache>
</cache-container>

(2)在socket-binding-group中增加如下内容:
<outbound-socket-binding name="remote-jdg-server1">
    <remote-destination host="localhost" port="11222"/>
</outbound-socket-binding>
 (3)重启 node1

 3.2 修改node2下的standalone-ha.xml文件
修改内容和 node1 完全一样。

4. 再次访问cluster_test应用,效果跟JBoss EAP 集群一样,但HTTP Session是存储在JBoss Data Grid Server上的。

参考文献:
1. 《Red_Hat_JBoss_Data_Grid-6.5-Administration_and_Configuration_Guide-en-US.pdf》

没有评论: