Configure a Load Balancer
- how-to
This topic describes how to place a load balancer or reverse proxy in front of an Operational Insights cluster, using NGINX as an example. For a conceptual overview of load-balancing topologies, see Connectivity & Topology Management.
Why Use a Reverse Proxy
-
A reverse proxy can hide the existence of individual Operational Insights nodes. This helps secure your cluster when it’s exposed to the internet.
-
A reverse proxy can provide application firewall features that protect against common web-based attacks.
-
A reverse proxy can offload TLS termination from the Operational Insights nodes, which can be significant overhead when supporting large numbers of clients.
-
A reverse proxy can distribute incoming requests across several Operational Insights nodes.
-
A reverse proxy may rewrite the URL of each incoming request to match the relevant internal location of the requested resource. For Operational Insights, the reverse proxy typically maps an internet-facing port, such as 443, to the Analytics Service REST API port (8095, or 18095 for TLS). See Operational Insights Ports.
Connection Timeouts
Operational Insights queries can run for an extended period, and the Request REST API supports asynchronous execution of long-running requests. Any intervening load balancer or proxy must be configured with keep-alive and read timeouts long enough to accommodate these connections, rather than the short defaults many load balancers use for typical web traffic.
NGINX Configuration
This section demonstrates how to configure NGINX as a reverse proxy in front of Operational Insights.
-
Connect to a server that can reach your Operational Insights cluster and install NGINX:
sudo apt-get install nginx -
Once the installation completes, confirm you can access the NGINX welcome page from your browser:
http://127.0.0.1/ (1)1 Replace 127.0.0.1with the IP address of your server.
Basic NGINX Configuration
If you installed NGINX using the instructions above, create your Operational Insights configuration file in /etc/nginx/sites-available.
-
Create a file in that directory called
operational-insightswith the content shown in Example 1:Example 1. NGINX configuration sampleupstream operational_insights { (1) server 127.0.0.1:8095; } # HTTP server # server { listen 80; (2) server_name oi-cluster.example.com; (3) location / { (4) proxy_pass http://operational_insights; (5) proxy_http_version 1.1; (6) keepalive_requests 1000; (7) keepalive_timeout 360s; proxy_read_timeout 360s; (8) } }1 The upstreamblock specifies the server and port NGINX forwards traffic to. In this example, it’s an Operational Insights node running on the same server as NGINX and listening on the default Analytics Service REST API port, 8095. Change these values to match your cluster’s nodes.2 The listendirective instructs NGINX to listen on port 80 for incoming traffic.3 The server_namedirective instructs NGINX to check that the HTTPHost:header value matchesoi-cluster.example.com(change this value to your domain).4 The locationblock specifies directives for all URL paths below the root path/.5 The proxy_passdirective instructs NGINX to forward all incoming traffic to the servers defined in theoperational_insightsupstream block.6 The proxy_http_versiondirective enables keep-alive connections to the upstream servers.7 The keepalive_requestsdirective instructs NGINX to allow up to a thousand requests on the same connection.8 The keepalive_timeoutandproxy_read_timeoutdirectives instruct NGINX to keep connections open long enough to accommodate long-running Operational Insights queries. See Connection Timeouts. -
Enable the
operational-insightssite. In thesites-enableddirectory, make a symbolic link to the file you just created:ln -s /etc/nginx/sites-available/operational-insights /etc/nginx/sites-enabled/operational-insights -
Restart NGINX:
sudo service nginx restart -
Verify that requests are proxied through to Operational Insights. Use your browser, or a command-line tool such as
curl, specifying the virtual host name you configured above:curl http://oi-cluster.example.com/You should receive a response from the Analytics Service REST API, confirming traffic is reaching your cluster over port 80.
Load Balancing Multiple Operational Insights Nodes
Add the IP address of each additional node to the upstream block, as shown in Example 2.
NGINX distributes incoming traffic across all listed nodes.
upstream operational_insights {
server 192.168.1.10:8095;
server 192.168.1.11:8095;
server 192.168.1.12:8095;
}
Transport Layer Security (HTTPS, SSL)
To secure the connection between clients and Operational Insights in production, use Transport Layer Security (TLS, also known as HTTPS or SSL). This encrypts data in transit, including credentials, and protects against Man-in-the-Middle attacks by verifying to the client that it’s connecting to the real cluster, not an impostor.
Certificates
To enable TLS, you need an X.509 certificate.
For production, get a certificate from a reputable Certificate Authority (CA), so clients can verify your certificate is trustworthy. You’ll end up with two files, both of which must be stored on a filesystem accessible to the NGINX process:
-
A private key. Treat this file as highly confidential, since anyone with the key can impersonate your site in a Man-in-the-Middle attack. Limit read access to the NGINX process and no others.
-
A public certificate.
For testing, you can create a self-signed certificate using the openssl command-line tool, as shown in Example 3.
sudo mkdir -p /etc/nginx/ssl
sudo openssl req -x509 -nodes -days 1095 -newkey rsa:2048 -keyout /etc/nginx/ssl/nginx.key -out /etc/nginx/ssl/nginx.crt
Using the Certificate and Key
Whichever way you generated the certificate, you should now have two files: a certificate and a private key. The following steps assume they’re at /etc/nginx/ssl/nginx.crt and /etc/nginx/ssl/nginx.key.
-
Add a new server section to the NGINX configuration file to support TLS termination, as shown in Example 4:
Example 4. Configure for TLS terminationserver { listen 443 ssl; server_name oi-cluster.example.com; ssl_certificate /etc/nginx/ssl/nginx.crt; ssl_certificate_key /etc/nginx/ssl/nginx.key; ssl_session_cache shared:SSL:10m; ssl_session_timeout 10m; location / { proxy_pass http://operational_insights; proxy_http_version 1.1; keepalive_requests 1000; keepalive_timeout 360s; proxy_read_timeout 360s; } } -
Restart NGINX to enable the new server:
sudo service nginx restart -
Test using
curl:curl -k https://oi-cluster.example.com/If you’re using a self-signed certificate, add the -kflag to accept an untrusted certificate. Without this flag, the command fails because your certificate isn’t signed by a trusted CA.
AWS Elastic Load Balancer (ELB)
Operational Insights queries and streaming ingestion can involve long-running connections. Set the Idle Timeout setting of the ELB to the maximum value of 3600 seconds (1 hour) to avoid the load balancer closing connections prematurely.
See the ELB documentation for more information on how to change this setting.