HAProxy Enterprise Documentation 2.0r1

TCP

HAProxy Enterprise can operate as a TCP proxy, in which TCP streams are relayed through the load balancer to a pool of backend servers. The TCP stream may carry any higher-level protocol (e.g. HTTP, FTP, SMTP). Often this mode is used when clients need to communicate with applications using a specific protocol meant only for that application, such as Redis (Redis Serialization Protocol) or MySQL database servers.

There are fewer fetch methods available to inspect raw TCP streams, but also less processing overhead.

Set TCP mode

Set the mode directive to tcp in both the frontend and backend sections to load balancer TCP connections.

In the following example, we load balance MySQL servers. Typically, it's best to set the load balancing algorithm to least connections when the servers may hold the connection for a variable amount of time. That algorithm sends the next client to the server with the fewest active connections.

frontend mysql
   mode tcp
   bind :3306
   default_backend mysql_servers

backend mysql_servers
   mode tcp
   balance leastconn
   server s1 192.168.0.10:3306
   server s2 192.168.0.11:3306

Next up

WebSocket