WAS集群与Nginx
was(IBM WebSphere Application Server)集群搭建完成后,此时往往需要一个负载均衡来承担请求分发的工作,这个工作大部分由IBM提供的webserver IHS(IBM HTTP Server)配合IBM提供的插件Plugin来实现。同样Nginx可以实现这个工作,但是为了保证来自同一客户的请求能够分发到相同的服务器上,避免因为转发到不同的服务器上导致的登录失效问题,所以需要实现用户请求粘连的功能。
IHS与PLG的分发原理
WAS会在HTTP的response中的set-cookie中的JSESSIONID中的末尾添加:CloneID
,而was的集群结构中,该集群的每个Server的CloneID均是不同的。PLG正是利用这一点实现实现对WAS的请求的负载分发同时实现用户请求粘连的功能。
同样利用原始版本的Nginx不需要装额外的任何插件也能实现PLG+IHS实现的功能。
配置
首先抓取到集群下所有server的CloneID。
<ServerCluster CloneSeparatorChange="false" GetDWLMTable="false" IgnoreAffinityRequests="false" LoadBalance="Round Robin" Name="Cl1" PostBufferSize="0" PostSizeLimit="-1" RemoveSpecialHeaders="true" RetryInterval="60" ServerIOTimeoutRetry="-1">
<Server CloneID="1dd073u9f" ConnectTimeout="5" ExtendedHandshake="false" LoadBalanceWeight="2" MaxConnections="-1" Name="washost1Node01_sv1" ServerIOTimeout="900" WaitForContinue="false">
<Transport Hostname="washost1" Port="9080" Protocol="http"/>
<Transport Hostname="washost1" Port="9443" Protocol="https">
<Property Name="keyring" Value="/opt/IBM/WebSphere/Plugins/config/w1/plugin-key.kdb"/>
<Property Name="stashfile" Value="/opt/IBM/WebSphere/Plugins/config/w1/plugin-key.sth"/>
</Transport>
</Server>
<Server CloneID="1dd073va9" ConnectTimeout="5" ExtendedHandshake="false" LoadBalanceWeight="2" MaxConnections="-1" Name="washost1Node02_sv2" ServerIOTimeout="900" WaitForContinue="false">
<Transport Hostname="washost1" Port="9081" Protocol="http"/>
<Transport Hostname="washost1" Port="9444" Protocol="https">
<Property Name="keyring" Value="/opt/IBM/WebSphere/Plugins/config/w1/plugin-key.kdb"/>
<Property Name="stashfile" Value="/opt/IBM/WebSphere/Plugins/config/w1/plugin-key.sth"/>
</Transport>
</Server>
<PrimaryServers>
<Server Name="washost1Node01_sv1"/>
<Server Name="washost1Node02_sv2"/>
</PrimaryServers>
</ServerCluster>
上述内容可以在WAS生成的plugin-cfg.xml中找到。
编辑Nginx的配置文件,加入一下代码
upstream wasservers{
server 192.168.12.158:9080;
server 192.168.12.158:9081;
}
server {
......
location / {
if ( $http_cookie ~* (:1dd073u9f)$ ) {
proxy_pass http://192.168.12.158:9080;
}
if ( $http_cookie ~* (:1dd073va9)$ ) {
proxy_pass http://192.168.12.158:9081;
}
proxy_pass http://wasservers;
}
......
}
即可实现IHS + PLG实现的功能