Nginx实现请求粘连的负载均衡

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实现的功能

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值