frontend: 定义前端 对外提供什么端口;
backend: 定义后端 集群资源池中具体有多少节点;
use_backend: 关联前端和后端的 类似于nginx中的proxy_pass 基于条件的方式来进行调度
default_backend: 关联前端和后端的,默认所有的请求都调度
listen:
示例场景1:
backend webservers
banlance roundrobin
server web01 172.16.1.7:80
server web02 172.16.1.8:80
frontend app *:80
default_backend webservers
实现haproxy负载均衡示例:
frontend web
bind *:80
default_backend webservers
backend webservers
balance roundrobin
server web01 172.16.1.7:8888 check
server web02 172.16.1.8:8888 check
官方示例配置
frontend main
bind *:5000
acl url_static path_beg -i /static /images /javascript /stylesheets
acl url_static path_end -i .jpg .gif .png .css .js
use_backend static if url_static
default_backend app
backend static
balance roundrobin
server static 127.0.0.1:4331 check
backend app
balance roundrobin
server app1 127.0.0.1:5001 check
server app2 127.0.0.1:5002 check
server app3 127.0.0.1:5003 check
server app4 127.0.0.1:5004 check
haproxy配置访问日志
global
log 127.0.0.1 local2 info
]# vim /etc/rsyslog.conf
# Provides UDP syslog reception
$ModLoad imudp
$UDPServerRun 514
local2.* /var/log/haproxy.log
]# systemctl restart rsyslog
]# systemctl restart haproxy