HAProxy Balance Source – Alternative Options

haproxy

I have haproxy listening on several ports and pointed at several backend servers.

Ideally, I would like it so that repeated communications to the same port get pointed at the same backend.

"balance source" isn't workable because often requests come from the same source.

Is this doable?

I'm also open to non-haproxy solutions. The protocol being used isn't important but is definitely not http. Just assume its ssh and you shouldn't go wrong.

EDIT: To clarify, imagine I have 10 'backend servers' and 5 'clients'. Each backend server can only ever cope with one connection at a time. I have more servers than required incase some become unavailable. I will manually point each client to the haproxy port(s). I want to ensure each client always gets to a backend server (which is simple) but preferably to the same one each time as long as it is available.

Best Answer

Here's how I solved my problem.

frontend name_of_frontend
    bind *:20000-20010
    default_backend     servers

backend servers
    balance roundrobin
    stick-table type integer size 1k expire 3h
    stick on dst_port
    server name ip-address check maxconn 1
    ...
    server name ip-address check maxconn 1

Willy warned in a previous answer's comment that it "will not guarantee that each client will go to a different port".

In my specific case, I have complete control over my 'clients'. The only reason I am pointing them at different ports on the proxy server is so that I can identify them as different clients. This is most definitely not a 'public' system.

Related Topic