Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add server dynamically in HA proxy backend?

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?

like image 586
Bhoomi Zalavadiya Avatar asked Dec 19 '16 07:12

Bhoomi Zalavadiya


People also ask

Can HAProxy have multiple frontends?

When HAProxy Enterprise is used as a reverse proxy in front of your backend servers, a frontend section defines the IP addresses and ports that clients can connect to. You may add as many frontend sections as needed to expose various websites or applications to the internet.

What is mode HTTP in HAProxy?

HAProxy can run in two different modes: TCP or HTTP. When operating in TCP mode, we say that it acts as a layer 4 proxy. In HTTP mode, we say that it acts as a layer 7 proxy.

What is backend in HAProxy?

HAProxy Enterprise frontend sections accept incoming connections that can then be forwarded to a pool of servers. The backend section is where those pools of servers that will service requests are defined. You may add as many backend sections as needed.

Is HAProxy an API gateway?

HAProxy, the world's fastest and most widely used software load balancer, fills the role as an API gateway extremely well. In addition to routing API calls to the proper backend servers, it also handles load balancing, security, rate limiting, caching, monitoring, and other cross-cutting concerns.


1 Answers

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/
like image 189
CᴴᴀZ Avatar answered Sep 20 '22 17:09

CᴴᴀZ