3

To my haproxy i redirect the traffic to single server in backend, i need set another server what work only in case of failure of first server, it's possible? I read the guide, but in balance algorithm don't have found any answer

stecog
  • 2,221
  • 10
  • 29
  • 39
  • haproxy is used for load balancing it assumes all backends will normally be operational. I think what you are trying to do is setup failover. – Aditya K Apr 10 '15 at 15:24
  • So it's not possible? – stecog Apr 10 '15 at 15:30
  • I dont know enough about haproxy to provide an authoritative answer, but I'm guessing not. You might want to look at Corosync / Pacemaker instead if you are sure you want a _failover_ cluster rather than a _load balanced_ cluster. – Aditya K Apr 10 '15 at 15:33
  • Use haproxy because in the future i plan to have more servers to balance, now i only need one – stecog Apr 10 '15 at 15:44

2 Answers2

4

Yes it's possible, i set a backup server adding backup after check like this:

backend test
 server 01 10.0.0.1:80 check
 server 02 10.0.0.2:80 check backup
stecog
  • 2,221
  • 10
  • 29
  • 39
0

There is an article in their blog about how to implement such setup. My config looks like this:

...
frontend http-1080
  mode http
  bind :1080

  # Enable http access logs
  no option dontlog-normal
  option log-separate-error

  default_backend http-80-app

backend http-80-app
  balance roundrobin
  mode http
  option forwardfor if-none
  option httpchk GET /site/health-check "HTTP/1.1\r\nHost: example.com\r\nAuthorization: Basic thebase64hash=="
  retry-on conn-failure empty-response 500 502 503 504
  http-reuse always
  option allbackups

  default-server inter 3s fall 2 rise 2

  server lb01-hel1-80 4.1.5.133:80 check
  server lb02-hel1-80 4.1.5.134:80 check
  server fe01-lim1-80 1.7.4.3:80 check backup
  server fe02-lim1-80 1.7.4.4:80 check backup

for HTTPS the server string looks like this:

  server lb01-hel1-443 4.1.5.133:443 check ssl sni str(example.com) verify none
  ...
  server fe01-lim1-443 1.7.4.3:443 check ssl sni str(example.com) verify none backup
  ...
  • While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. – Jeff Schaller May 16 '21 at 12:36
  • Actually @hellb0y77 in the message above had provided almost 80% of the setup. – Andrey Zentavr May 17 '21 at 13:12
  • Good! Is there anything else we can put in the other answer to make it better? Would it be improved with a link to this "Failover and Worst Case Management with HAProxy" article? Feel free to [suggest an edit](https://unix.stackexchange.com/posts/195511/edit) to that post with any improvements. Thank you! – Jeff Schaller May 17 '21 at 13:36
  • @JeffSchaller - we are implementing the very similar solution and i'll be back as soon as we roll out it to our production environment. – Andrey Zentavr May 18 '21 at 13:29