Tuesday, February 28, 2012

How to Load Balance across Cluster (setup WSO2 Load Balancer)

How to setup WSO2 Load Balancer

Load balancing is a key concern in a Platform-as-a-Service (PaaS) or a middleware platform deployed on the Cloud. An Elastic Load Balancer (ELB), in addition to carrying out its functionality in load balancing, is also responsible for monitoring the load & starting up new worker nodes or terminating existing worker nodes, depending on the load. An ideal use case of the Load Balancer is WSO2 StratosLive, where the service instances are fronted with the load balancers and the system scales automatically as the service gets more web service calls.  Here in this article we will see how to configure WSO2 Load Balancer Balance to use with Application server cluster

You can download WSO2 Application server from here http://wso2.com/products/application-server/
You can download WSO2 Load Balancer from here https://wso2.org/projects/load-balancer


1.Configure Application Server Cluster
Edit  mgt-transports.xml file as follows
Uncomment the HTTP proxy port in this file. The HTTP proxy port has to be set to port 80.

  
  1. <transport name="http" class="org.wso2.carbon.server.transports.http.HttpTransport">
  2.         <parameter name="protocol">HTTP_11_NIO</parameter>
  3.         <parameter name="port">${Ports.ServletTransports.HTTP}</parameter>
  4.         <parameter name="proxyPort">80</parameter>
  5.         <parameter name="maxHttpHeaderSize">8192</parameter>
  6.         <parameter name="acceptorThreadCount">2</parameter>
  7.         <parameter name="maxThreads">250</parameter>
  8.         <parameter name="minSpareThreads">50</parameter>
  9.         <parameter name="disableUploadTimeout">false</parameter>
  10.         <parameter name="connectionUploadTimeout">120000</parameter>
  11.         <parameter name="maxKeepAliveRequests">200</parameter>
  12.         <parameter name="acceptCount">200</parameter>
  13.         <parameter name="server">WSO2 Carbon Server</parameter>
  14.         <parameter name="compression">on</parameter>
  15.         <parameter name="compressionMinSize">2048</parameter>
  16.         <parameter name="noCompressionUserAgents">gozilla, traviata</parameter>
  17.         <parameter name="compressableMimeType">
  18.             text/html,text/javascript,application/x-javascript,application/javascript,
    application/xml,text/css,application/xslt+xml,text/xsl,image/gif,image/jpg,image/jpeg
  19.         </parameter>
  20.     </transport>
  21.     <transport name="https" class="org.wso2.carbon.server.transports.http.HttpTransport">
  22.         <parameter name="protocol">HTTPS_11_NIO</parameter>
  23.         <parameter name="port">${Ports.ServletTransports.HTTPS}</parameter>
  24.        <parameter name="proxyPort">443</parameter>
  25.         <parameter name="sslProtocol">TLS</parameter>
  26.         <parameter name="maxHttpHeaderSize">8192</parameter>
  27.         <parameter name="acceptorThreadCount">2</parameter>
  28.         <parameter name="maxThreads">250</parameter>
  29.         <parameter name="minSpareThreads">50</parameter>
  30.         <parameter name="enableLookups">false</parameter>
  31.         <parameter name="disableUploadTimeout">false</parameter>
  32.         <parameter name="connectionUploadTimeout">120000</parameter>
  33.         <parameter name="maxKeepAliveRequests">200</parameter>
  34.         <parameter name="acceptCount">200</parameter>
  35.         <parameter name="server">WSO2 Carbon Server</parameter>
  36.         <parameter name="clientAuth">false</parameter>
  37.         <parameter name="compression">on</parameter>
  38.         <parameter name="compressionMinSize">2048</parameter>
  39.         <parameter name="noCompressionUserAgents">gozilla, traviata</parameter>
  40.         <parameter name="compressableMimeType">
  41.             text/html,text/javascript,application/x-javascript,application/javascript,
     application/xml,text/css,application/xslt+xml,text/xsl,image/gif,image/jpg,image/jpeg
  42.         </parameter>
  43.         <parameter name="keystoreFile">
  44.             ${carbon.home}/repository/resources/security/wso2carbon.jks
  45.         </parameter>
  46.         <parameter name="keystorePass">wso2carbon</parameter>
  47.     </transport>


Edit carbon.xml In this file, we have to specify the Host of the App Server
   
<HostName>appserver.cloud-test.wso2.com</HostName>


Edit axis2.xml
In the axis2.xml file, you have to enable the clustering.
   
  1. <clustering class="org.apache.axis2.clustering.tribes.TribesClusteringAgent" enable="true">
  2.         <parameter name="AvoidInitiation">true</parameter>
  3.         <parameter name="membershipScheme">wka</parameter>
  4.         <parameter name="domain">wso2.as.domain</parameter>
  5.         <parameter name="synchronizeAll">true</parameter>
  6.         <parameter name="maxRetries">10</parameter>
  7.         <parameter name="mcastAddress">228.0.0.4</parameter>
  8.         <parameter name="mcastPort">45564</parameter>
  9.         <parameter name="mcastFrequency">500</parameter>
  10.         <parameter name="memberDropTime">3000</parameter>
  11.         <parameter name="localMemberPort">4100</parameter>
  12.         <parameter name="preserveMessageOrder">true</parameter>
  13.         <parameter name="atmostOnceMessageSemantics">true</parameter>
  14.         <parameter name="properties">
  15.             <property name="backendServerURL" value="https://${hostName}:${httpsPort}/services/"/>
  16.             <property name="mgtConsoleURL" value="https://${hostName}:${httpsPort}/"/>
  17.         </parameter>
  18.         <members>
  19.             <member>
  20.                 <hostName>appserver.cloud-test.wso2.com</hostName>
  21.                 <port>4000</port>
  22.             </member>
  23.         </members>

Keep rest of this xml file as it is.


2.Configure Load Balancer
Configuring the Load Balancer Cluster

locate the transportReceiver entries for the HTTP & HTTPS ports and change them to port 80 & 443 respectively. The relevant XML segments are shown below.
  
  1. <transportReceiver name="http" class="org.apache.synapse.transport.nhttp.HttpCoreNIOListener">
  2.         <parameter name="port" locked="false">80</parameter>
  3.         <parameter name="non-blocking" locked="false">true</parameter>
  4.         <!--parameter name="bind-address" locked="false">hostname or IP address</parameter-->
  5.         <!--parameter name="WSDLEPRPrefix" locked="false">https://apachehost:port/somepath</parameter-->
  6.         <parameter name="httpGetProcessor" locked="false">org.wso2.carbon.transport.nhttp.api.NHttpGetProcessor</parameter>
  7.     </transportReceiver>
  8.     <!-- the non blocking https transport based on HttpCore + SSL-NIO extensions -->
  9.     <transportReceiver name="https" class="org.apache.synapse.transport.nhttp.HttpCoreNIOSSLListener">
  10.         <parameter name="port" locked="false">443</parameter>
  11.         <parameter name="non-blocking" locked="false">true</parameter>
  12.         <!--parameter name="bind-address" locked="false">hostname or IP address</parameter-->
  13.         <!--parameter name="WSDLEPRPrefix" locked="false">https://apachehost:port/somepath</parameter-->
  14.         <parameter name="httpGetProcessor" locked="false">org.wso2.carbon.transport.nhttp.api.NHttpGetProcessor</parameter>
  15.         <parameter name="keystore" locked="false">
  16.             <KeyStore>
  17.                 <Location>repository/resources/security/wso2carbon.jks</Location>
  18.                 <Type>JKS</Type>
  19.                 <Password>wso2carbon</Password>
  20.                 <KeyPassword>wso2carbon</KeyPassword>
  21.             </KeyStore>
  22.         </parameter>
  23.         <parameter name="truststore" locked="false">
  24.             <TrustStore>
  25.                 <Location>repository/resources/security/client-truststore.jks</Location>
  26.                 <Type>JKS</Type>
  27.                 <Password>wso2carbon</Password>
  28.             </TrustStore>
  29.         </parameter>
  30.         <!--<parameter name="SSLVerifyClient">require</parameter>
  31.             supports optional|require or defaults to none -->
  32.     </transportReceiver>



Edit loadbalancer.xml to map the HTTP host to the clustering domain.Add following segment to services section
  
  1. <services>
  2.         <defaults>
  3.             <property name="availabilityZone" value="us-east-1c"/>
  4.             <property name="securityGroups" value="default-2011-02-23"/>
  5.             <property name="instanceType" value="m1.large"/>
  6.             <property name="minAppInstances" value="1"/>
  7.             <property name="maxAppInstances" value="5"/>
  8.             <property name="queueLengthPerNode" value="400"/>
  9.             <property name="roundsToAverage" value="10"/>
  10.             <property name="instancesPerScaleUp" value="1"/>
  11.             <property name="messageExpiryTime" value="60000"/>
  12.         </defaults>
  13.         <service>
  14.             <hosts>
  15.                 <host>appserver.cloud-test.wso2.com</host>
  16.             </hosts>
  17.             <domain>wso2.as.domain</domain>
  18.         </service>
  19.     </services>


Please note that appserver.cloud-test.wso2.com is mapped to 127.0.0.1 in my machine by changing /etc/hosts entries.Also change carbon.xml file located in appserver repository/conf by adding following entry.
   
<HostName>appserver.cloud-test.wso2.com</HostName>




Now you have to up and run load balancer product first then run appserver product. You will see following message in loadbalancer log when appserver joins to the load balance cluster.
[2012-02-23 17:34:12,048]  INFO - RpcMembershipRequestHandler Received JOIN message from 10.200.2.85:4100(wso2.as.domain)
[2012-02-23 17:34:12,052]  INFO - MembershipManager Application member 10.200.2.85:4100(wso2.as.domain) joined group wso2.as.domain
[2012-02-23 17:34:23,062]  INFO - DefaultGroupManagementAgent Application member Host:10.200.2.85, Port: 4100, HTTP:9763, HTTPS:9443, ACTIVE:true joined application cluster

Now you can invoke Application server by typing https://appserver.cloud-test.wso2.com:443/carbon/ URL in browser. So you will see the logs related to the requested page in loadbalancer logs.
To remove autoscale you have to remove autoscaler.xml file from wso2lb-1.0.2/repository/deployment/server/synapse-configs/default/tasks folder. Also remove autoscalein and autoscaleout configurations from main.sequence(from main.xml file located in wso2lb-1.0.2/repository/deployment/server/synapse-configs/default/sequences).

No comments:

Post a Comment