TCP Load Balancing
Use the the embedded HAProxy to load balancing TCP traffic at layer 4. In this scenario, responses from servers flow through the HAProxy ALOHA (i.e. not Direct Server Return).
HAProxy ALOHA 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, SMTP, Redis, MySQL). Because it does not read application-level metadata such as HTTP headers, proxying involves less overhead and can be faster.
The client connects to your application at the configured public IP address. The HAProxy ALOHA listens at that address and receives the packets.
HAProxy ALOHA makes a separate connection to one of the backend servers and relays the packets over that connection. In other words, the client's original connection is not routed to a backend server directly. Instead, the client communicates with the HAProxy ALOHA only.
The backend server sends its response back to HAProxy ALOHA and then HAProxy ALOHA relays it back to the client over the frontend connection.
Set TCP mode
In the web UI's LB Layer 7 tab (note: not the Layer 4 tab), set the
modedirective to tcp in both the
backendsections of your configuration to load balance TCP connections.
In the following example, we load balance MySQL servers. Typically, it is 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