Differences
This shows you the differences between two versions of the page.
linux_wiki:dns_load_balancing [2019/05/25 23:50] |
linux_wiki:dns_load_balancing [2019/05/25 23:50] (current) |
||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== DNS Load Balancing ====== | ||
+ | |||
+ | **General Information** | ||
+ | |||
+ | DNS load balancing with Nginx streams. | ||
+ | |||
+ | **Checklist** | ||
+ | * Install Nginx | ||
+ | |||
+ | ---- | ||
+ | |||
+ | ====== Main Config File ====== | ||
+ | |||
+ | Replace the entire main config (/ | ||
+ | <code bash> | ||
+ | ## NGINX - Main Configuration ## | ||
+ | |||
+ | # Context: Main - General Server Configuration | ||
+ | |||
+ | # User that worker processes run as | ||
+ | user nginx; | ||
+ | |||
+ | # Number of worker processes (auto = set to number of CPUs) | ||
+ | worker_processes | ||
+ | |||
+ | # Error logging and PID of main process | ||
+ | error_log | ||
+ | pid / | ||
+ | |||
+ | # Load dynamic modules. See / | ||
+ | include / | ||
+ | |||
+ | # Include enabled configurations | ||
+ | include / | ||
+ | |||
+ | # Context: Events - Connection Processing | ||
+ | events { | ||
+ | # Max number of connections per worker process | ||
+ | worker_connections | ||
+ | } | ||
+ | |||
+ | # No http contexts because we are doing stream processing with the included drop in files | ||
+ | </ | ||
+ | |||
+ | ---- | ||
+ | |||
+ | ====== Nginx DNS Load Balance Stream Config ====== | ||
+ | |||
+ | Stream config drop in file. | ||
+ | |||
+ | / | ||
+ | <code bash> | ||
+ | stream { | ||
+ | |||
+ | # Stream Logging Setup | ||
+ | log_format proxy '" | ||
+ | '" | ||
+ | '" | ||
+ | '" | ||
+ | |||
+ | # Log Location | ||
+ | access_log | ||
+ | |||
+ | # Backend DNS Servers | ||
+ | upstream dns_servers { | ||
+ | # Balancing Type: Least Connections | ||
+ | least_conn; | ||
+ | # Passive Health Checks (defaults): fail_timeout=10, | ||
+ | # (server marked down if 1 failure in 10 second period and stays down for 10 seconds) | ||
+ | # weight=5 : use these dns servers 5 times more than others with no weight | ||
+ | server 192.168.1.1: | ||
+ | server 192.168.1.2: | ||
+ | server 192.168.1.3: | ||
+ | } | ||
+ | |||
+ | # Frontend listener | ||
+ | server { | ||
+ | listen | ||
+ | proxy_pass dns_servers; | ||
+ | # Bind response to interface request was received on | ||
+ | proxy_bind $server_addr; | ||
+ | proxy_timeout 1s; | ||
+ | proxy_responses 1; | ||
+ | error_log / | ||
+ | } | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | ---- | ||