2011年12月7日星期三

WLS_073:WebLogic Server高级管理之三:集群下的HTTP Session管理

运行环境:WebLogic Server 10.3.5 + Oracle Database 10g Express Edition 10.2.0.1。

WebLogic Server集群可以用来在多个Server之间复制HTTP Session,复制方式有内存复制和数据库持久化两种。
(1)内存复制方式

(2)数据库持久化方式


1. 内存复制方式
(1)在dizzy1-->上设置主备复制组:dizzyRepGroup1(主)、dizzyRepGroup2(备)。

(2)在dizzy1-->上设置主备复制组:dizzyRepGroup2(主)、dizzyRepGroup1(备)。

(3)修改应用中的weblogic.xml内容,增加如下内容:
<session-descriptor>
<persistent-store-type>replicated_if_clustered</persistent-store-type>
</session-descriptor>
(4)发布应用shoppingcart.war到Cluster上。
(5)访问http://localhost:7009/shoppingcart/

选中一些商品,放入到Session中

Shutdown接收请求的Server,比如dizzy2,然后刷新页面,发现Session信息依然存在,说明内存复制Session方式起作用了。

2. 数据库持久化方式
(1)配置和内存复制方式相同。
(2)配置和内存复制方式相同。
(3)创建数据库表:wl_servlet_sessions。
选择一个Schema,比如HR,创建表wl_servlet_sessions。
create table wl_servlet_sessions
( wl_id VARCHAR2(100) NOT NULL,
wl_context_path VARCHAR2(100) NOT NULL,
wl_is_new CHAR(1),
wl_create_time NUMBER(20),
wl_is_valid CHAR(1),
wl_session_values LONG RAW,
wl_access_time NUMBER(20),
wl_max_inactive_interval INTEGER,
PRIMARY KEY (wl_id, wl_context_path) );

(4)创建Data Source:SessionDS
注意要把SessionDS target到dizzyworldCluster上。

(5)修改应用中的weblogic.xml内容,增加如下内容:
<session-descriptor>
<persistent-store-type>jdbc</persistent-store-type>
<persistent-store-pool>SessionDS</persistent-store-pool>
<persistent-store-table>WL_SERVLET_SESSIONS</persistent-store-table>
</session-descriptor>

(6)重新发布应用shoppingcart.war到Cluster上。
(7)访问http://localhost:7009/shoppingcart/
选中一些商品,放入到Session中后,Shutdown所有Server,查看数据库表,发现有记录。
说明HTTP Session信息已经持久化到数据库表中了。

重新启动Server,访问应用,发现Session信息都还存在,说明数据库持久化Session方式起作用了。

Project下载:shoppingcart.war

没有评论: