HAProxy configuration - how to make a TCP connection sticky (Node.js, socket.io, websocket, FlashSocket)

I have HAProxy installed for the EC2 server, where I run my nodejs two servers on ports 3005 and 3006. We installed this for our multi-player game. we used socket.io for our real-time event updates on the client side and server side. HAProxy works correctly with the "source of balance" (I added a working copy of my HAProxy configuration), the problem with the original balancer is that all events on the same server happen all the time. therefore, I have 40 computers on my network, so all 40 computer events go to port 3005. its not changing the port when I arrive the next day. I would like to configure the TCP connection sticky with TCP mode in haproxy. is there any way to balance rounding? Here I added my current settings files. we are also trying to use cookies,but it does not work in our case, because we used the mode as tcp.

We also have a flash game that was used to load flash policies from port 3843.

Here is my haproxy configuration added.

global
debug
log 127.0.0.1   local0         # Enable per-instance logging of events and traffic.
log 127.0.0.1   local1 notice  # only send important events
nbproc  1
maxconn 65536
pidfile /var/run/haproxy.pid

defaults
log global
srvtimeout 300s
timeout connect 5s
timeout queue   5s
timeout server 1h
timeout tunnel  1h

frontend flash_policy
bind 0.0.0.0:843
timeout client 5s
default_backend nodejs_flashpolicy

frontend wwws
bind 0.0.0.0:3000 ssl crt /home/certificate/final.crt
timeout client 1h
default_backend flashsocket_backend

tcp-request inspect-delay 500ms
tcp-request content accept if HTTP
use_backend flashsocket_backend if !HTTP

backend flashsocket_backend
mode tcp
option log-health-checks
balance source
cookie JSESSIONID insert indirect nocache
server 3006Game serverip:3006 cookie socket1 weight 1 maxconn 32536 check
server 3005Game serverip:3005 cookie socket2 weight 1 maxconn 32536 check

backend nodejs_flashpolicy
server flashpolicy serverip:3843 weight 1 maxconn 65536 check

# Configuration for HAProxy Stats
listen stats :1900
mode http
timeout client 1h
stats enable
stats hide-version
stats realm Haproxy\ Statistics
stats uri /
stats auth alpesh:alpesh
+4
source share
1 answer

You can use the following parameters in the backend:

stick-table type ip size 50k expire 10m
stick on src
0
source

Source: https://habr.com/ru/post/1539244/


All Articles