Proxy and loadbalancer example with HAProxy

We use HAProxy as a reverse proxy and loadbalancer as described in Topology for HA cluster.

The URI that can be redirected to the replica nodes are the queries that only retrieve data from the server (no absorption).

In this example, the following URI are redirected to the replica nodes:

  • pagelet execution queries: /rest/ui/dashboards/dashboard-.*/pagelets/pagelet-.*

  • parameters queries: /rest/ui/dashboards/dashboard-.*/pagelets/parameters-.*

Other queries are redirected to the active HA main node.

Configuration file

haproxy.conf
global
    maxconn 2000

defaults
    mode    http
    retries 3
    option redispatch
    timeout connect  5000
    timeout client  10000
    timeout server  10000

# Proxy URL to use for FLEX replicas configuration
listen flex_proxy
    bind 10.0.0.1:1443
    mode http
    balance roundrobin
    option httpclose
    option forwardfor
    server node1 10.0.0.12:8080 track queries/replica1
    server node2 10.0.0.13:8080 track queries/replica2
 
# Define a group of servers for the UI query requests
frontend front
    bind 10.0.0.1:443
    mode http
    # Redirect all parameters and pagelet queries to the Replica servers
    acl url_api path_reg ^\/hvp\\/rest\\/ui\/dashboards\/dashboard-.*/(parameters|pagelet-)
    use_backend queries if url_api
    # Other queries are redirected to primary group
    default_backend primary

# Accept Replica node if heartbeat declares it is SYNCHRONIZED
backend queries
    mode http
    option httpchk GET /hvp/heartbeat/synchronizationStatus/status HTTP/1.1\r\n10.0.0.1
    http-check expect string "SYNCHRONIZED"
    server replica1 10.0.0.12:8080 check
    server replica2 10.0.0.13:8080 check
    server ha1 10.0.0.10:8080 track primary/ha1
    server ha2 10.0.0.11:8080 track primary/ha2
 
# Accept HA node if heartbeat declares it is HA MAIN (HTTP reply 200)
backend primary
    mode http
    option httpchk GET /hvp/heartbeat/ha HTTP/1.1\r\nHost:10.0.0.1
    server ha1 10.0.0.10:8080 check
    server ha2 10.0.0.11:8080 check

Related Links