【发布时间】:2014-06-21 11:54:17
【问题描述】:
我已经为 EC2 服务器设置了 HAProxy,我在端口 3005 和 3006 上运行我的 nodejs 两个服务器。我们已经为我们的多人游戏设置了这个。我们使用 socket.io 在客户端和服务器端进行实时事件更新。 HAProxy 与“平衡源”正常工作(我添加了我的 HAProxy 配置的工作副本),源平衡器问题是它每次都在同一台服务器上发生所有事件。所以我的网络中有 40 台计算机设置,所以所有 40 台计算机事件都转到 3005 端口。第二天我来的时候它不会改变港口。我想在 haproxy 中使用 TCP 模式设置 TCP 连接粘性。平衡循环有什么办法吗?我在这里添加了我当前的设置文件。我们也尝试使用 cookie,但它在我们的案例中不起作用,因为我们使用了模式作为 tcp。
我们还有用于从端口 3843 加载 flash 策略的 flash 游戏。
这里添加了我的 haproxy 配置。
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
【问题讨论】:
标签: node.js sockets tcp amazon-ec2 haproxy