1.集群搭建
登录控制台在服务器中创建受管理节点,并与计算机、集群关联。
在domains\cluster_domain\bin 中创建启动受管理节点脚本如下:
@ECHO OFF
@REM 启动受管理服务器ManagedServer_3
start .\startManagedWebLogic ManagedServer_3 http://localhost:7001
运行脚本则可在domains\cluster_domain\servers下看到创建的受管理节点目录
修改startManagedWebLogic.cmd ,输入用户名、密码 在启动节点时跳过用户名、密码输入。
set WLS_USER=
set WLS_PW=
2.apache2.4 代理访问
下载httpd-2.4.10-win64-VC11.zip 并解压,需要安装 vcredist_x64.exe
下载 mod_wl_24.so,并将此文件复制至 Apache24\modules 目录下。
修改 apache http.conf 文件:
1) 修改文件中所有 Apache24 目录位置,与解压环境一致
2)修改监听端口 Listen 8085,以及
ServerAdmin 127.0.0.1:8085
ServerName www.example.com:80
3)修改用户,及用户组
#User daemon
#Group daemon
User nobody
Group nobody
4)添加模块
#weblogic 11g 连接模块
LoadModule weblogic_module modules/mod_wl_24.so
5)添加负载地址
<IfModule mod_weblogic.c>
WebLogicCluster 127.0.0.1:8003,127.0.0.1:8004,127.0.0.1:8005
MatchExpression *.jsp
MatchExpression *.*
MatchExpression *
</IfModule>
3.集群回话共享
在项目web-inf 下添加 weblogic.xml 文件如下:
<?xml version="1.0" encoding="UTF-8"?>
<weblogic-web-app xmlns="http://xmlns.oracle.com/weblogic/weblogic-web-app"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.oracle.com/weblogic/weblogic-web-app
http://xmlns.oracle.com/weblogic/weblogic-web-app/1.0/weblogic-web-app.xsd">
<session-descriptor>
<debug-enabled>true</debug-enabled>
<persistent-store-type>replicated</persistent-store-type>
<sharing-enabled>true</sharing-enabled>
<!--<persistent-store-type>memory</persistent-store-type> -->
<timeout-secs>60</timeout-secs>
</session-descriptor>
</weblogic-web-app>
4. 资料:
1)apache 安装服务自动启动 使用如下命令将Apache安装为Windows NT服务:
httpd -k install
如果你想指定服务的名称,可以使用下面的命令。当你在同一机器上安装多个Apache服务时,你必须为它们指定不同的名字。
httpd -k install -n "服务名"
如果你想为不同名称的服务使用不同的配置文件,则安装时需要指定配置文件:
httpd -k install -n "服务名" -f "c:\files\my.conf"
如果你使用的是第一个命令,也就是除 -k install 外没有其它命令行参数,那么被安装的服务名称将是:Apache2.2 ,配置文件将使用conf\httpd.conf 。
要移除一个Apache服务很简单:
httpd -k uninstall
或者使用下述命令移除特定名称的Apache服务:
httpd -k uninstall -n "服务名"
通常,启动、重启、关闭Apache服务的方法是使用Apache Service Monitor工具,另外也可以使用控制台命令:NET START Apache2.2 和 NET STOP Apache2.2 或者通过Windows服务控制面板。在启动Apache服务之前,你应当使用下面的命令检查一下配置文件的正确性:
httpd -n "服务名" -t
你可以通过命令行开关来控制Apache服务。要启动一个已经安装的Apache服务,可以使用:
httpd -k start
要停止一个已经安装的Apache服务,可以使用:
httpd -k stop
或
httpd -k shutdown
要重启一个运行中的Apache服务,强制它重新读取配置文件,可以使用:
httpd -k restart
默认情况下,Apache服务将被注册为以本地系统用户(LocalSystem帐号)身份运行。LocalSystem帐号没有网络权限,不能通过任何Windows安全机制访问网络,包括文件系统、命名管道、DCOM或secure RPC ,但是它对于本地资源却拥有广泛的特权。
2)weblogic session共享说明
在Weblogic中,HttpSession Replication的方式是通过在weblogic.xml中的session- descriptor的定义persistent-store-type来实现的. persistent-store-type可选的属性包括memory, replicated, replicated_if_clustered, async-replicated, async-replicated-if-clustered, file, async-jdbc, jdbc, cookie, coherence-web.
· memory—Disables persistent session storage.
· replicated—Same as memory, but session data is replicated across the clustered servers.
· replicated_if_clustered—If the Web application is deployed on a clustered server, the in-effect persistent-store-type will be replicated. Otherwise, memory is the default.
· async-replicated—Enables asynchronous session replication in an application or Web application. See"Asynchronous HTTP Session Replication" in Performance and Tuning for Oracle WebLogic Server.
· async-replicated-if-clustered—Enables asynchronous session replication in an application or Web application when deployed to a cluster environment. If deployed to a single server environment, then the session persistence/replication defaults to in-memory. This allows testing on a single server without deployment errors.
· file—Uses file-based persistence (See also session-descriptor).
· async-jdbc—Enables asynchronous JDBC persistence for HTTP sessions in an application or Web application. SeeConfiguring Session Persistence.
· jdbc—Uses a database to store persistent sessions. (see also session-descriptor).
· cookie—All session data is stored in a cookie in the user's browser.
· Coherence*-web For more information, see User's Guide for Oracle Coherence*Web.
Replicated,async-replicated只用部置集群在集群上,而replicated_if_clustered,async-replicated-if-clustered也可以部署在独立实例上。都不能只部署在集群的部分实例中上。
参考:http://docs.oracle.com/cd/E23943_01/web.1111/e13712/weblogic_xml.htm#i1071981
1. Load Blanace和Session Affinity
由于这里的机制是主从备份, 所以集群中只有两个实例会有同一HTTP Session的数据. 当集群里的实例多于2个以上时,为了确保后续的HTTP请求能访问到Session数据, 必须要求前置分发请求的load balancer支持session affinity(sticky session/seamless session). Session Affinity就是能够把特定Session的所有请求都路由到第一次创建Session的同一物理机器上;否则后续的请求就有可能不能够访问 Session数据了.
如果设置成非Replication方式即memory模式, 生成的JSESSIONID类似:
gGMWQy2LcSTHTSyLdyLpqYGskYpXPpRJkc2VB618mSKSQC9rgsCv!-1274119771!1353236040031
可以看出这个session被二个!分隔成三部分。第一部分应该是真正的sessionid, -1274119771是实例标识。而1353236040031为session创建时间。
一旦配置成Replicated模式,Weblogic会生成的SessionID类似:
sHkLQyQTnJQQ217Js7SmQL2x9hBb0JQ5hFm7n4QpNkZL7wMnLbPn!-9326295!959096067!1353236595093
这里出现三个!,第二,三部分为主备实例的标识。
SessionID格式的: sessionid!primary_server_id[!secondary_server_id]!creationTime
2.配置weblogic Load Blanace
配置方式参考: http://guojuanjun.blog.51cto.com/277646/748768
1) 通过http://localhost/Cluster/cluster.jsp访问,页面显示:
session Id:
KSW2QyJFzVcnFxQTWpSLJLhJTTQsCzLGqlM1ShnCvSyKm2r4k29h!-1458785082!2113129367!1353238917906
session CreateTime :1353238917906
current instance :Server1
可以看到该session的primary_server_id为-1458785082,即Server1。(每个server的id是启动时生成的,所以也是变化,所以你的测试可能与我不一样。) secondary_server_id为2113129367,即server3. 即server3是Server1的备点。
2) 停止Server1,再次访问, 页面显示:
session Id:
KSW2QyJFzVcnFxQTWpSLJLhJTTQsCzLGqlM1ShnCvSyKm2r4k29h!2113129367!-481865348!1353238917906
session CreateTime :1353238917906
current instance :Server3
可以看到sessionId没有变化,而该session的primary_server_id为2113129367, 即Server3。secondary_server_id为-481865348,即server0.即Server0是Server3的备点。
3) 停止Server3,再次访问, 页面显示:
session Id:
KSW2QyJFzVcnFxQTWpSLJLhJTTQsCzLGqlM1ShnCvSyKm2r4k29h!-481865348!NONE!1353238917906
session CreateTime :1353238917906
current instance :Server0
可以看到sessionId没有变化,该session的primary_server_id为-481865348, 即Server0。secondary_server_id为NONE,即该session没有备点.
通过测试我们大致可以猜出weblogic session复制的基本思路:
1) 每个实例都有两份Session数据。主数据和备份数据。
2) 当请求的sessionId的primary_server_id为当前实例时,从主数据里获取session响应请求,否则进行3).
3) 当请求的sessionId的secondary_server_id为当前实例时,从备份数据里取session响应请求。并修正该session的primary_server_id/secondary_server_id为自已及其的备点。
3. Weblogic支持的负载均衡
Weblogic支持两种机制的负载均衡
1) Proxy plug-ins
Weblogic内置插件,即http://guojuanjun.blog.51cto.com/277646/748768中提到的mod_wl.
如果一个实例失败,plug-in会定位该session的secondary_server,将请求发给它。
2) Hardware load balancers
Hardware load balancers,比如F5. 这些第三方产品并不能按weblogic的意愿,定位session的secondary_server。他会随机选机选择一个可用实例发给他。然后该实例通过session id里的secondary_server_id,像secondary_server获取数据。
虽然weblogic允许这种请求的随机转发,但并不建议使用会话不亲和方式,因为这将带来数据并发和一致性问题。
参考文献:
1. http://blog.csdn.net/mobicents/article/details/7067957
2. http://docs.oracle.com/cd/E23943_01/wls.htm
3. http://stackoverflow.com/questions/6429990/weblogic-jsessionid
待继续,apache 代理记录客户端访问IP, 在系统中通过代理后是否能正确的记录客户端访问IP,而不是代理服务器的IP.