HAProxy how to "stick-table" ip connection to same backend?
16,287
You're just missing the stick on and stick match parts. My config would look like this:
global
maxconn 300000
defaults
mode http
log global
option httplog
option http-server-close
option dontlognull
option redispatch
option contstats
retries 3
backlog 10000
timeout client 5s
timeout connect 5s
timeout server 5s
timeout tunnel 120s
timeout http-keep-alive 5s
timeout http-request 15s
default-server inter 3s rise 2 fall 3
option forwardfor
frontend ft_web
bind *:8000 name http
maxconn 300000
stick-table type ip size 5000k expire 5m store conn_cur
stick on src table bk_web
tcp-request connection reject if { src_conn_cur ge 3 }
tcp-request connection track-sc1 src
default_backend bk_web
backend bk_web
balance roundrobin
stick match src table bk_web
server s8001 127.0.0.1:8001 maxconn 500 weight 10 cookie s8001 check
server s8002 127.0.0.1:8002 maxconn 500 weight 10 cookie s8002 check
server s8003 127.0.0.1:8003 maxconn 500 weight 10 cookie s8003 check
server s8004 127.0.0.1:8004 maxconn 500 weight 10 cookie s8004 check
Author by
kivlara
Updated on September 02, 2022Comments
-
kivlara over 1 year
My HAProxy config:
global maxconn 300000 defaults mode http log global option httplog option http-server-close option dontlognull option redispatch option contstats retries 3 backlog 10000 timeout client 5s timeout connect 5s timeout server 5s timeout tunnel 120s timeout http-keep-alive 5s timeout http-request 15s default-server inter 3s rise 2 fall 3 option forwardfor frontend ft_web bind *:8000 name http maxconn 300000 stick-table type ip size 5000k expire 5m store conn_cur tcp-request connection reject if { src_conn_cur ge 3 } tcp-request connection track-sc1 src default_backend bk_web backend bk_web balance roundrobin server s8001 127.0.0.1:8001 maxconn 500 weight 10 cookie s8001 check server s8002 127.0.0.1:8002 maxconn 500 weight 10 cookie s8002 check server s8003 127.0.0.1:8003 maxconn 500 weight 10 cookie s8003 check server s8004 127.0.0.1:8004 maxconn 500 weight 10 cookie s8004 check
Currently if someone is openning more then 3 connections, all other are droped, but I need to stick IP to backend so every time someone with same IP access frontend he goes to same backend node ...
thanks