3

我的 HAProxy 配置:

global
maxconn 300000

defaults
  mode http
  log global
  option httplog
  option  http-server-close
  option  dontlognull
  option  redispatch
  option  contstats
  retries 3
  backlog 10000
  timeout client            5s
  timeout connect           5s
  timeout server            5s
  timeout tunnel            120s
  timeout http-keep-alive   5s
  timeout http-request      15s
  default-server inter 3s rise 2 fall 3
  option forwardfor

frontend ft_web
  bind *:8000 name http
  maxconn 300000
  stick-table type ip size 5000k expire 5m store conn_cur
  tcp-request connection reject if { src_conn_cur ge 3 }
  tcp-request connection track-sc1 src   
  default_backend bk_web

backend bk_web
   balance roundrobin

server s8001 127.0.0.1:8001 maxconn 500 weight 10 cookie s8001 check
server s8002 127.0.0.1:8002 maxconn 500 weight 10 cookie s8002 check
server s8003 127.0.0.1:8003 maxconn 500 weight 10 cookie s8003 check
server s8004 127.0.0.1:8004 maxconn 500 weight 10 cookie s8004 check

目前,如果有人打开超过 3 个连接,则所有其他连接都将被丢弃,但我需要将 IP 粘贴到后端,所以每次具有相同 IP 访问前端的人都会去同一个后端节点...

谢谢

4

1 回答 1

3

你只是错过了坚持和坚持比赛部分。我的配置看起来像这样:

global
maxconn 300000

defaults
  mode http
  log global
  option httplog
  option  http-server-close
  option  dontlognull
  option  redispatch
  option  contstats
  retries 3
  backlog 10000
  timeout client            5s
  timeout connect           5s
  timeout server            5s
  timeout tunnel            120s
  timeout http-keep-alive   5s
  timeout http-request      15s
  default-server inter 3s rise 2 fall 3
  option forwardfor

frontend ft_web
  bind *:8000 name http
  maxconn 300000
  stick-table type ip size 5000k expire 5m store conn_cur
  stick on src table bk_web
  tcp-request connection reject if { src_conn_cur ge 3 }
  tcp-request connection track-sc1 src   
  default_backend bk_web

backend bk_web
   balance roundrobin

stick match src table bk_web
server s8001 127.0.0.1:8001 maxconn 500 weight 10 cookie s8001 check
server s8002 127.0.0.1:8002 maxconn 500 weight 10 cookie s8002 check
server s8003 127.0.0.1:8003 maxconn 500 weight 10 cookie s8003 check
server s8004 127.0.0.1:8004 maxconn 500 weight 10 cookie s8004 check
于 2014-02-20T15:51:37.603 回答