haproxy的frontend/backend和listen区别

listen是frontend和backend相结合的。一个listen本身有一个隐式的backend,但是frontend的前端逻辑可以使用其他后端,它的backend可以被其他frontend使用。从根本上说,它只是让配置对于简单的规则来说更加紧凑,但在其他方面,它几乎等同于在保持配置在一起的同时,声明一个单独的同名frontend和backend。

frontend/backend配置

global
daemon
maxconn 256
defaults
mode http
timeout connect 5000ms
timeout client 50000ms
timeout server 50000ms
frontend http-in
bind *:80
default_backend servers
backend servers
server server1 127.0.0.1:8000 maxconn 32

listen配置

# The same configuration defined with a single listen block. Shorter but
# less expressive, especially in HTTP mode.
global
daemon
maxconn 256
defaults
mode http
timeout connect 5000ms
timeout client 50000ms
timeout server 50000ms
listen http-in
bind *:80
server server1 127.0.0.1:8000 maxconn 32

listen对TCP特别有用,因为这样的配置通常比HTTP简单。但是frontend/backend可以用于任何应用程序。

开源优秀项目推荐202003期
MySQL - CHAR vs VARCHAR区别
ajax-loader