Reference

add server

Available since

  • HAProxy 2.4
  • HAProxy Enterprise 2.4r1

Add a dynamic server to a backend.

Description Jump to heading

Instantiate a new server attached to an existing backend. Such a server may also be called a dynamic server. Dynamic servers refer to servers that do not have an explicit entry within your HAProxy configuration file.

The specified server name must not already be in use in the backend. The backend must be configured to use a dynamic load balancing algorithm for the balance directive: roundrobin, leastconn, first, or random.

A dynamic server is not restored after a load balancer reload operation. If you need the server definition to persist, add it to the load balancer’s configuration file.

Dynamic servers are statically initialized with the none init-addr method. In this method, the server starts in the down state without a valid IP address. After you add a dynamic server, you can enable it with the enable server command.

It may be possible to reach the fd (file descriptor) limit when using a large number of dynamic servers. See also fd-hard-limit and ulimit-n in the global keyword documentation.

The following keywords are supported for configuring the new server:

Keyword Note Available since version
agent-addr 2.5r1
agent-check Even when enabled by this keyword, agent check is still inactive until activated independently of the server with the enable agent command. Note that in this case the server may be activated via the agent depending on the status reported, without an explicit enable server command. This also means that extra care is required when removing a dynamic server with agent check. The agent should first be deactivated using disable agent to be able to put the server in the required maintenance mode before removal. 2.5r1
agent-inter 2.5r1
agent-port 2.5r1
agent-send 2.5r1
allow-0rtt 2.5r1
alpn 2.5r1
addr 2.5r1
backup 2.4r1
ca-file 2.5r1
check Even when enabled by this keyword, health check is still inactive until activated independently of the server with the enable health command. 2.5r1
check-alpn 2.5r1
check-proto 2.5r1
check-send-proxy 2.5r1
check-sni 2.5r1
check-ssl 2.5r1
check-via-socks4 2.5r1
ciphers 2.5r1
ciphersuites 2.5r1
cookie 3.0r1
crl-file 2.5r1
crt 2.5r1
disabled 2.4r1
downinter 2.5r1
error-limit 2.5r1
fall 2.5r1
fastinter 2.5r1
force-sslv3/tlsv10/tlsv11/tlsv12/tlsv13 2.5r1
id 2.4r1
inter 2.5r1
maxconn 2.4r1
maxqueue 2.4r1
minconn 2.4r1
no-ssl-reuse 2.5r1
no-sslv3/tlsv10/tlsv11/tlsv12/tlsv13 2.5r1
no-tls-tickets 2.5r1
npn 2.5r1
observe 2.5r1
on-error 2.5r1
on-marked-down 2.5r1
on-marked-up 2.5r1
pool-low-conn 2.4r1
pool-max-conn 2.4r1
pool-purge-delay 2.4r1
port 2.5r1
proto 2.4r1
proxy-v2-options 2.4r1
rise 2.5r1
send-proxy 2.4r1
send-proxy-v2 2.4r1
send-proxy-v2-ssl 2.5r1
send-proxy-v2-ssl-cn 2.5r1
slowstart 2.5r1
sni 2.5r1
source 2.4r1
ssl 2.5r1
ssl-max-ver 2.5r1
ssl-min-ver 2.5r1
tfo 2.4r1
tls-tickets 2.5r1
track A dynamic server may use this keyword to follow the check status of another server from the configuration. However, it is not possible to track another dynamic server. This restriction ensures that the tracking chain is kept consistent in the event a dynamic server is deleted. 2.5r1
usesrc 2.4r1
verify 2.5r1
verifyhost 2.5r1
weight 2.4r1
Ws 2.5r1

Settings from the default-server statement, if any, in the backend configuration are not applied to the new server.

Servers added with this command can be deleted using the del server command.

Examples Jump to heading

Tip

As of HAProxy version 3.0 and HAProxy Enterprise vresion 3.0, the enabled keyword is now rejected with an error for the add server command. If you receive an error message as follows: 'enabled' option is not accepted for dynamic server, remove enabled from your command and try again. In previous versions, the enabled keyword was silently ignored.

To add a server to an existing backend configured with a dynamic load balancing algorithm:

  1. Add the server using the add server command. Below, we add the server web2 to backend webservers:

    nix
    echo "add server webservers/web2 172.16.0.12:8080 check port 8080" | \
    sudo socat stdio tcp4-connect:127.0.0.1:9999
    nix
    echo "add server webservers/web2 172.16.0.12:8080 check port 8080" | \
    sudo socat stdio tcp4-connect:127.0.0.1:9999
    output
    text
    New server registered.
    output
    text
    New server registered.
  2. Enable the server using the enable server command. The server is in maintenance mode by default.

    nix
    echo "enable server webservers/web2" | sudo socat stdio tcp4-connect:127.0.0.1:9999
    nix
    echo "enable server webservers/web2" | sudo socat stdio tcp4-connect:127.0.0.1:9999

    There is no output for this command.

  3. Optional: enable health checks using the enable health command. Health checks are disabled by default. In the example above, we added check to our server definition which allows us to enable health checks using enable health:

    echo "enable health webservers/web2" | sudo socat stdio tcp4-connect:127.0.0.1:9999
    echo "enable health webservers/web2" | sudo socat stdio tcp4-connect:127.0.0.1:9999

    There is no output for this command.

Available since

  • HAProxy 3.0
  • HAProxy Enterprise 3.0r1

You can use static cookies for session persistence for dynamic servers. To add a dynamic server to your backend with a static cookie, issue the add server command, specifying the name of your cookie:

nix
echo "add server webservers/web2 172.16.0.12:8080 cookie app2" | \
socat stdio tcp4-connect:127.0.0.1:9999
nix
echo "add server webservers/web2 172.16.0.12:8080 cookie app2" | \
socat stdio tcp4-connect:127.0.0.1:9999
output
text
New server registered.
output
text
New server registered.

See also Jump to heading

Do you have any suggestions on how we can improve the content of this page?