今天有人問graylog的三個node怎麼做load balance
想到之前玩過haproxy
可是查了一下資料
haproxy不支援UDP的load balance
nginx目前已經有支援了
設定方法如下
udp loadbalance
# Load balance UDP‑based DNS traffic across two servers
stream {
upstream dns_upstreams {
server 192.168.1.1:53;
server 192.168.1.2:53;
}
server {
listen 53 udp;
proxy_pass dns_upstreams;
proxy_timeout 1s;
proxy_responses 1;
error_log logs/dns.log;
}
}
=============================================================
tcp load balance
upstream mytest {server 192.168.2.1 weight=3;server 192.168.2.2 weight=2;}server {listen 443 ssl;server_name my.test.tw;access_log /var/log/nginx/my.test.tw.access.log main;error_log /var/log/nginx/my.test.tw.error.log warn;ssl_certificate my.test.tw.crt;ssl_certificate_key my.test.tw.key;ssl_protocols TLSv1 TLSv1.1 TLSv1.2;location / {proxy_pass http://mytest;proxy_set_header Host $host;proxy_set_header X-Real-IP $remote_addr;proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;}}
https://blog.dtask.idv.tw/Nginx/2018-07-31/
https://www.nginx.com/blog/announcing-udp-load-balancing/