global
maxconn 100000
log /dev/log local0
log /dev/log local1 notice
chroot /var/lib/haproxy
stats socket /run/haproxy/admin.sock mode 660 level admin expose-fd listeners
stats timeout 30s
user haproxy
group haproxy
daemon
defaults
mode tcp
log global
retries 2
timeout queue 5s
timeout connect 5s
timeout client 60m
timeout server 60m
timeout check 15s
listen stats
mode http
bind 10.172.0.20:7000
stats enable
stats uri /
listen master
bind 10.172.0.20:5000
maxconn 10000
option tcplog
option httpchk OPTIONS /primary
http-check expect status 200
default-server inter 3s fastinter 1s fall 3 rise 4 on-marked-down shutdown-sessions
server pgnode01 10.172.0.20:6432 check port 8008
server pgnode02 10.172.0.21:6432 check port 8008
server pgnode03 10.172.0.22:6432 check port 8008
listen replicas
bind 10.172.0.20:5001
maxconn 10000
option tcplog
option httpchk OPTIONS /replica?lag=100MB&tag_datacenter=dc1
balance roundrobin
http-check expect status 200
default-server inter 3s fastinter 1s fall 3 rise 2 on-marked-down shutdown-sessions
server pgnode01 10.172.0.20:6432 check port 8008
server pgnode02 10.172.0.21:6432 check port 8008
server pgnode03 10.172.0.22:6432 check port 8008
listen replicas_sync
bind 10.172.0.20:5002
maxconn 10000
option tcplog
option httpchk OPTIONS /sync?tag_datacenter=dc1
balance roundrobin
http-check expect status 200
default-server inter 3s fastinter 1s fall 3 rise 2 on-marked-down shutdown-sessions
server pgnode01 10.172.0.20:6432 check port 8008
server pgnode02 10.172.0.21:6432 check port 8008
server pgnode03 10.172.0.22:6432 check port 8008
listen replicas_async
bind 10.172.0.20:5003
maxconn 10000
option tcplog
option httpchk OPTIONS /async?lag=100MB&tag_datacenter=dc1
balance roundrobin
http-check expect status 200
default-server inter 3s fastinter 1s fall 3 rise 2 on-marked-down shutdown-sessions
server pgnode01 10.172.0.20:6432 check port 8008
server pgnode02 10.172.0.21:6432 check port 8008
server pgnode03 10.172.0.22:6432 check port 8008
To separate load balancers across different data centers
To separate load balancers across different data centers (each has its VIP), just create separate inventory files (e.q. cluster.hosts, balancers_dc1.hosts, balancers_dc2.hosts). See an example here
To separate the read-only traffic across different data centers, add the datacenter=<name> tag to the ‘patroni_tags’ and ‘balancer_tags’ variables in the inventory for the respective hosts. See an example here
Variable:
balancer_tags
Example (/etc/haproxy/haproxy.cfg ):
To separate load balancers across different data centers
cluster.hosts
,balancers_dc1.hosts
,balancers_dc2.hosts
). See an example heredatacenter=<name>
tag to the ‘patroni_tags’ and ‘balancer_tags’ variables in the inventory for the respective hosts. See an example here