haproxy load balancing - ghdrako/doc_snipets GitHub Wiki

haproxy

/etc/haproxy/haproxy.cfg

global
  # global settings
defaults
 # defaults
frontend
   # a frontend that accepts request from client
backend
  # server that fulfill the requests

Example

global
     maxconn 100 # number of connection haproxy could manage
defaults
     mode    tcp
     retries 2
     timeout client  5m
     timeout server  5m
     timeout connect 5m
     timout check    5m
frontend    ft_postgres
     bind   *:5432
     default_backend bk_postgres
backend bk_postgres
        balance leastconn
        server replica-1 <ip>:5432 check
        server replica-2 <ip>:5432 check
```

```
sudo systemctl restart haproxy  # to reread config
```