Load Balancing with Nginx

Contents:

Adding OverOps Collectors to Nginx

Connecting the Collector to the Load Balancer

Configuring Load Balancing in the Agent

 

This article describes how to configure Nginx, to serve as a load balancer for multiple OverOps Collectors. Nginx is a leading load balancer for HTTP or TCP traffic.

Note: Load balancing TCP traffic requires Nginx with 'Stream' module. This may require building from the source code.

Nginx supports three load balancing methods. By default, Nginx operates as round-robin. To change the load balancing method, add one of the alternative methods, as described below.

Adding OverOps Collectors to Nginx

To configure Nginx as a Load Balancer over the Collectors:

  1. In the nginx.conf file, add the upstream Collectors and configure the port on which to listen:
    ...
    stream {
    server {
    listen <LB_PORT_TO_LISTEN_ON>;
    proxy_pass collectors;
    }

    upstream collectors {
    <LB_METHOD>;
    server <HOSTNAME1:PORT1>;
    server <HOSTNAME2:PORT2>;
    ...
    server <HOSTNAMEn:PORTn>;
    }
    }
    ...

    Where:

    • LB_PORT_TO_LISTEN_ON is the port on which the Load Balancer listens to the Collectors
    • HOSTNAME is the hostname or IP address of the load balanced Collectors
    • LB_Method is the alternative load balancing method (empty: round-robin). Other options:
      • least_conn - least connected: next request is assigned to the server with the least number of active connection
      • ip_hash - a hash-function is used to determine which server should be selected for the next request (based on the client’s IP address).

Example:

...
stream {
server {
listen 7070;
proxy_pass collectors;
}

upstream collectors {
server host1:6060;
server host2:6060;
}
}

...

     2.  Restart Nginx load the new configuration:
      sudo service nginx stop; sudo service nginx start

Connecting the Collector to the Load Balancer 

To connect the Collector to the Load Balancer:

  1. From the Agent takipi.properties file, set the port on which the Agent listens to the Load Balancer:
    listenOnPort=<AGENT_PORT_TO_LISTEN_ON>

  2. Start the Collector.

Configuring Load Balancing in the Agent

Next, direct the Agent to the Nginx server as the load balancer.

To configure the load balancing in the Agent:

  1. From the Agent takipi.properties file, set the master Collector:
    masterEndpoints=nginx-server:7070

  2. Leave the following parameters empty: 
    listenOnPort=
    masterHost=
    masterPort=

  3. Run the Agent with the -agentlib:TakipiAgent JVM argument. 
  4. Stop the active Collector and verify that the Agent connects to the next Collector automatically. 

 

Have more questions? Submit a request