Skip to content

游戏服务器负载均衡

HAProxy 可用于游戏服务器的负载均衡,支持 TCP 层的长连接和实时通信。

基础游戏代理配置

haproxy
frontend game_front
    bind *:25565 name minecraft
    bind *:27015 name csgo
    mode tcp
    option tcplog

    timeout client 86400s
    timeout server 86400s

    use_backend mc_cluster if { dst_port 25565 }
    use_backend csgo_cluster if { dst_port 27015 }

backend mc_cluster
    mode tcp
    balance source
    option tcpka
    server mc1 10.0.0.11:25565 maxconn 500 check inter 30s

游戏反作弊检测

haproxy
    stick-table type ip size 100k expire 5m store http_req_rate(1s)
    acl too_fast req.rate_limit(gt) 10
    http-request delay 1000ms if too_fast

游戏 DDoS 防护

haproxy
    http-request silent-drop if { req.rate_limit(gt) 20 }

玩家会话保持

haproxy
    balance source
    hash-type consistent
    timeout server 86400s
    option tcpka