WSO2Con 2013 CFP Banner

How to setup WSO2 Load Balancer

Discuss this article on Stack Overflow
By Sanjeewa Malalgoda
  • 21 May, 2012
  • Level:  Intermediate
  • Reads: 4462

In this article, we will look at how to configure loadbalancer with two service lusters in static way without autoscaling. Here we will use two WSO2 products (Application Server and Data Services Server) and load balancer. This demonstrates how to setup load balancer with two 2 service clusters for above mentioned services.

Sanjeewa Malalgoda
Senior Software Engineer
WSO2 Inc.

Introduction

Load balancing is a key concern in a Platform-as-a-Service (PaaS) or a middleware platform deployed on the Cloud. The primary functionality of a load balancer is to distribute the load of the incoming traffic amongst a set of backend worker nodes. This set of worker nodes can be either statically configured or can be dynamically discovered. Traditionally, load balancers are configured with a set of static nodes. In this article, we will look at how to configure loadbalancer with two service lusters in static way without autoscaling.

Applies To

WSO2 Load Balancer 1.0.2
WSO2 Application Server 4.1.0
WSO2 Data Services Server 2.6.0

Archtecture

In this exmple we will use Appserver Cluster, Data Services Cluster and Load Balancer Cluster. The client sees the public IP address mapped to Load Balancer, and needs to send the HTTP 1.1 Host header. This Host header will be used by Load Balancer to determine the destination Service cluster.When the LB receives a request, it will get the incoming port, and before dispatching the request to a member, it will try to get the mapped real port from the member, and route the request to the appropriately mapped port (as advertised by the member). Now we will see the configuration.

Configure Appserver cluster

For simplicity we will setup cluster with one worker node. If you need to setup clusters with many nodes and manage cluster using WSO2 Cluster management feature you can find more information from here.Here we have to edit 3 configuration files basically.

01. Carbon.xml

We have to add HostName entry to carbon.xml file(Otherwise it will pickup default host name for that host) as follows.

 appserver.cloud-test.wso2.com 

02. Axis2.xml

We have to change axis2.xml file to enable clustering configure clustering parameters. Change the following sections

    
        true
        wka
        wso2.as.domain
        true
        10
        228.0.0.4
        45564
        500
        3000
        4500
        true
        true
        
            
            
        
        
            
                127.0.0.1
                4000
            
        

03. mgt-transports.xml

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.HTTPS proxy port has to be set to port 443

Configure Data Services Cluster

For This cluster also we will setup cluster with one worker node. Here also we have to edit 2 configuration files basically.

01. Carbon.xml

We have to add HostName entry to carbon.xml file(Otherwise it will pickup default value for that host) as follows.

 dss.cloud-test.wso2.com 

02. Axis2.xml

We have to change axis2.xml file to enable clustering configure clustering parameters. Change the following sections


        true
        wka
        wso2.dss.domain
        false
        10
        228.0.0.4
        45564      
        500       
        3000              
	127.0.0.1
        5000
        true
        true
        
            
            
	    
             
        
              
            127.0.0.1  
            4000  
            
        

03. mgt-transports.xml

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.HTTPS proxy port has to be set to port 443

Configure Load Balancer Cluster

For This cluster also we will setup cluster with one worker node. Here also we have to edit 3 configuration files basically.

01. Axis2.xml

We have to change axis2.xml file to enable clustering configure clustering parameters. Change the following sections


        true
        wka
        wso2.lb.domain
        false
        10
        228.0.0.4
        45564      
        500       
        3000              
	127.0.0.1
        4000
        true
        true  

02. loadbalancer.xml

Edit loadbalancer.xml file to add service clusters to load balancer

In load balancer.xml file we have to specify the service cluster related information. Then only load balancer will know which host header maps to which cluster domain. Here in this example we defined two host headers(Application server and Data Services Server) and 2 clustering domains (wso2.as.domain and wso2.dss.domain). We will add Load Balancer configuration to balancer.xml file as follows. We don't have to worry rest of the configuration just keep them as it is.

  
      
          
              
                appserver.cloud-test.wso2.com  
              
            wso2.as.domain  
          
          
              
                data.cloud-test.wso2.com  
              
            wso2.dss.domain  
          
      
  

Next we have to disable Auto scaling. Now WSO2 Elastic Load Balancer only supports auto scaling on Amazon EC2 & compatible infra structure as a service. But we are now implementing Java Virtual Machine(JVM) based elastic auto scaling. It will available with future release of load balancer. So, you will see error messages if you try to run this setup on a local network. So you will have to disable auto scaling. You have to do the following to disable auto scaling. Delete repository/deployment/server/synapse-configs/tasks/autoscaler.xml Remove the autoscaleIn & autoscaleOut mediators repository/deployment/server/synapse-configs/sequences/main.xml by removing following tags.

autoscaleIn configuration="$system:loadbalancer.xml"

autoscaleOut

Now we have completed setting up the system now we have to up and run nodes. If everything is properly setup, you should see messages on the LB log file saying members from wso2.as.domain & wso2.dss.domain joined the cluster. see the following log.

[2012-03-25 18:54:48,151]  INFO - RpcMembershipRequestHandler Received JOIN message from 127.0.0.1:4200(wso2.as.domain)
[2012-03-25 18:54:48,158]  INFO - MembershipManager Application member 127.0.0.1:4200(wso2.as.domain) joined group wso2.as.domain
[2012-03-25 18:54:59,168]  INFO - DefaultGroupManagementAgent Application member Host:127.0.0.1, Port: 4200, HTTP:9768, HTTPS:9448, 
ACTIVE:true joined application cluster

To make sure that everything is working properly, in your client machine, map the appserver.cloud-test.wso2.com & data.cloud-test.wso2.com names to the relevant IP address of the Elastic load balancer & go to those URLs using your Web browser.

Conclusion

The WSO2 Load Balancer (LB) is a load balancer based on Apache Synapse & WSO2 Carbon. With WSO2 Elastic Load Balancer we will be able to load balance between multiple service domains with multiple clusters. Within each cluster load balancer will balance load between nodes in round robin fashion. This is the easiest way to balance the load between WSO2 Carbon based servers with less amount of configuration changes. In this article we haven't talk about auto scaling part but WSO2 Load Balancer supports auto scaling as well.

References

How to setup WSO2 Elastic Load Balancer

WSO2 Load Balancer - how it works

The role of a Load Balancer in a Platform-as-a-Servicer

How to Configure the WSO2 Load Balancer for Auto Scaling

How to install WSO2 Carbon cluster management feature

Author

Sanjeewa Malalgoda, Software Engineer, WSO2, sanjeewa AT wso2 DOT com