3.5. Peers

It is possible to synchronize server entries in stick tables between several haproxy instances over TCP connections in a multi-master fashion. Each instance pushes its local updates and insertions to remote peers. Server IDs are used to identify servers remotely, so it is important that configurations look similar or at least that the same IDs are forced on each server on all participants.

Interrupted exchanges are automatically detected and recovered from the last known point. In addition, during a soft restart, the old process connects to the new one using such a TCP connection to push all its entries before the new process tries to connect to other peers. That ensures very fast replication
during a reload, it typically takes a fraction of a second even for large tables.

peers <peersect>
Creates a new peer list with name <peersect>. It is an independent section, which is referenced by one or more stick-tables.

peer <peername> <ip>:<port>
Defines a peer inside a peers section. If <peername> is set to the local peer name (by default hostname, or forced using “-L” command line option), haproxy will listen for incoming remote peer connection on <ip>:<port>. Otherwise, <ip>:<port> defines where to connect to to join the remote peer, and <peername> is used at the protocol level to identify and validate the remote peer on the server side.

During a soft restart, local peer <ip>:<port> is used by the old instance to connect the new one and initiate a complete replication (teaching process).

It is strongly recommended to have the exact same peers declaration on all peers and to only rely on the “-L” command line argument to change the local peer name. This makes it easier to maintain coherent configuration files across all peers.

Any part of the address string may reference any number of environment variables by preceding their name with a dollar sign (‘$’) and optionally enclosing them with braces (‘{}’), similarly to what is done in Bourne shell.


    peers mypeers
        peer haproxy1
        peer haproxy2
        peer haproxy3

    backend mybackend
        mode tcp
        balance roundrobin
        stick-table type ip size 20k peers mypeers
        stick on src

        server srv1
        server srv2
Share Button

One thought on “3.5. Peers

  1. Berniece

    It was difficult to find your blog in google search results.

    I found it on 21 position, you have to spread your articles to social sites , it will help you to increase traffic.
    You can do it on autopilot, i know how to help you, just search in google – k2 seo tips and tricks

Leave a Reply