How to add server dynamically in HA proxy backend?
Asked Answered
K

3

10

I am using HA proxy version 1.6.6 for load balancing rabbitmq server, and it works fine but i want to add server dynamically in ha proxy backend in ubuntu using script. can anyone please tell me how can i done it?

Knap answered 19/12, 2016 at 7:0 Comment(0)
P
12

HAProxy OSS v1.8 does not include add/remove commands in Runtime API, but you can achieve similar functionality by using ready/disabled state commands.

  • Add server(s) config in haproxy.cfg in disabled state: server-template websrv 1-100 192.168.122.1:8080 check disabled //This adds 100 servers (websrv1...websrv100) in disabled state
  • Enable server (similar to add feature): set server be_template/websrv1 state ready
  • Disable server (similar to remove feature): set server be_template/websrv1 state maint

Address and port can be changed using Runtime API as usual: set server be_template/websrv1 addr 192.168.50.112 port 8000

Reference(s):

  1. https://www.haproxy.com/blog/dynamic-configuration-haproxy-runtime-api/
  2. https://www.haproxy.com/blog/dynamic-scaling-for-microservices-with-runtime-api/
Punkie answered 14/11, 2018 at 6:14 Comment(3)
This does not work in haproxy 1.8: "Update for the current server address family is only supported through configuration file"Creatinine
Changing server addresses is working in HA-Proxy version 2.0.7 2019/09/27Eurasian
Unknown command: 'server-template', but maybe one of the following ones is a better match -- haproxy 2.8Temple
C
0

As far as I know haproxy api ( stats socket ) does not support dynamic adding/removing servers to backend. One of the solution to use consul, the cost - reload service after some change. https://www.hashicorp.com/blog/haproxy-with-consul.html

Cribbs answered 19/12, 2016 at 11:25 Comment(0)
P
0

I think there is not this kind of features with HAProxy Open Source.

If you use their ALOHA Load Balancer, there is an API to do this actions here :

https://www.haproxy.com/resources/documentation/

Parnassus answered 19/12, 2016 at 11:36 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.