Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TCP Load Balancing en masse #4

Open
jhunt opened this issue Sep 24, 2019 · 0 comments
Open

TCP Load Balancing en masse #4

jhunt opened this issue Sep 24, 2019 · 0 comments

Comments

@jhunt
Copy link
Contributor

jhunt commented Sep 24, 2019

I would like to be able to load-balance lots of TCP ports to lots of backend hosts (where each host can respond in kind to any of the port range, without needing to be persistent beyond the established connection lifetime).

I think we can do this with a combination of haproxy and iptables, where a 3rd process watches the stats socket for haproxy (like hatop does) and when the set of healthy backend servers changes, re-configures iptables.

Here's an example iptables ruleset, for three backing hosts and a 1000 port range:

iptables -A PREROUTING -t nat -p tcp -m multiport -d 192.168.1.1 --dports 8192:9191 \
         -m statistic --mode random --probability 0.33            \
         -j DNAT --to-destination 10.20.30.1
iptables -A PREROUTING -t nat -p tcp -m multiport -d 192.168.1.1 --dports 8192:9191 \
         -m statistic --mode random --probability 0.5            \
         -j DNAT --to-destination 10.20.30.2
iptables -A PREROUTING -t nat -p tcp -m multiport -d 192.168.1.1 --dports 8192:9191 \
         -j DNAT --to-destination 10.20.30.3

if we assume that 192.168.1.1 is our VIP (thanks keepalived!) and we need 1/3 of the new (SYN sent) connections to go to 10.20.30.1, 1/3 (1/2 of the remaining 2/3) to go to 10.20.30.2, and 1/3 (all of the remaining 1/3) to go to 10.20.30.3.

The probabilities will have to be reconfigured whenever the number of healthy IPs in the pool (determined by haproxy or something like it) changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant