Skip to content

configure load balancer

Daniele Fontani edited this page Sep 2, 2017 · 4 revisions

this configuration allow to navigate a remote site through the balancer. In this configuration traffic is routed to a set of nodes, chosing using one alghoritm (round robin, faster server, total request count).

To implement this for an host, we just need few configurations steps. Assume "balancer.local" is the url that clients will surf. The node are node1.balanced.remote and node2.balanced.remote

/conf/vhosts/conf.json

this file contains the settings about main configuration. Here we have to tell:

  • there is a new host to list: proxy.local, telling on what port server will get requests
  • what module are needed. This sample show only the ones required. Other module can be left (modules are activated only basing on vhost settings) So for this part you can basically left all untouched.
  • what configuration use for this site. *SettingsName:..."
{
  "BalancerSettings": {
    "Mappings": [
      
      {
        "Host": "balancer.local:52231",
        "SettingsName": "balancer_sample"
      }
    ],
    "Plugins": [
      {
        "Name": "Init",
        "Impl": "NetLoadBalancer.Code.Middleware.InitMiddleware"
      },
      {
        "Name": "RequestFilter",
        "Impl": "NetLoadBalancer.Code.Middleware.RequestFilterMiddleware"
      },
      {
        "Name": "Balancer",
        "Impl": "NetLoadBalancer.Code.Middleware.BalancerMiddleware"
      },
      {
        "Name": "Proxy",
        "Impl": "NetLoadBalancer.Code.Middleware.ProxyMiddleware"
      }
    ]

      
    
  }
}

/conf/vhosts/balancer_sample.conf

To keep settings clean such settings are on dedicated files under vhost folder. The name of the file must be the same of the one specified into conf.json file. In this case is "balancer_sample" but you can put here whatever you want.

Note in this sample I added the request filter module to exclude favicon. This because browser ask for it and it causes multiple requests and this is worrying for testing purposes.

This file basically state that:

  • We need the modules: "RequestFilter","Balancer", "Proxy"
  • we listen the source and serve resources from destination nodes, using an algorithm to define the righe one
{
  "balancer_sample": {
    "Host": "balancer.local",
    "Port": 52231,
    "Scheme": "http",
    "Filters": [ "RequestFilter","Balancer", "Proxy" ],
    "Settings": {     
      "RequestFilter": {
        "rules": [
          {
            "path": "^/favicon.ico$",
            "duration": "10s"
          },
          {
            "path": "^/(.*)\\.ico$",
            "duration": "10s"
          }
        ]
      },
      "Balancer": {
        "Nodes": [
          {
            "Host": "node1.balanced.remote",
            "Port": 80,
            "Scheme": "http"
          },
          {
            "Host": "node2.balanced.remote",
            "Port": 80,
            "Scheme": "http"
          }
        ],
        "Policy": "RoundRobin"
      },
      "Proxy": {
        "DefaultDestination": {
          "Host": "addreess.not.used.com",
          "Port": 443,
          "Scheme": "https"
        }
      }

    }
  }
  }