7.12.4.4. Example HAProxy Configuration File

Here is an example haproxy.cfg file:

global
  log         127.0.0.1 local2

  chroot      /var/lib/haproxy
  pidfile     /var/run/haproxy.pid
  maxconn     4000
  user        haproxy
  group       haproxy
  daemon

  # turn on stats unix socket
  # echo "show stat" | nc -U /var/lib/haproxy/stats
  stats socket /var/lib/haproxy/stats

defaults
  mode                    tcp
  option                  tcpka
  option                  dontlognull
  option                  redispatch
  retries                 3
  timeout queue           1m
  timeout connect         10s
  timeout client          1m
  timeout server          1m
  timeout check           10s

frontend connector *:3306
    default_backend cluster

backend connector
    balance roundrobin
    option tcplog
    #default-server port 9200
    server  conn1 db1:3306 check inter 5s rise 1 fall 1 weight 6 maxconn 5000
    server  conn2 db2:3306 check inter 5s rise 1 fall 1 weight 6 maxconn 5000
    server  conn3 db3:3306 check inter 5s rise 1 fall 1 weight 6 maxconn 5000

This example has the Connectors installed on the three database nodes.

Uncomment the default-server port 9200 line to use the external check script.