TransWikia.com

How can I TCP (layer 4) load balance with haproxy and still do roundrobin or leastconn balancing?

Server Fault Asked on November 12, 2021

I am trying to load balance with haproxy on VirtualBox just to see that things work as they should before I go on to set it up on Digital Ocean. I am able to decide how to balance requests when I choose mode http, but when I choose mode tcp, all requests from the same machine/client goes to the same server, and does not alternate. I would like it to alternate with either roundrobin or leastconn. I would like to set up the simplest configuration file that is possible to achieve this. This is what I have so far. But it is not working as I described.

global
    chroot      /var/lib/haproxy
    pidfile     /var/run/haproxy.pid
    maxconn     4096
    user        haproxy
    group       haproxy
    daemon

defaults
    mode tcp

frontend main *:80
    default_backend nodes

backend nodes
    balance roundrobin
    server goapp1 192.168.1.101:80 check
    server goapp2 192.168.1.102:80 check

How can I achieve this?

One Answer

Disable HTTP connection re-use on your web servers. In TCP mode, haproxy doesn't know that the HTTP transaction has logically concluded.

Answered by longneck on November 12, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP