HAProxy如何将“stick-table”ip连接到同一个后端?

时间:2013-10-01 11:27:45

标签: frontend backend haproxy

我的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访问权限的人都会前往相同的后端节点...

感谢

1 个答案:

答案 0 :(得分:1)

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

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
相关问题