Como fazer failover se o Varnish estiver entre o HAProxy e o Apache

Como fazer failover se o Varnish estiver entre o HAProxy e o Apache

Estou pensando em colocar o Varnish entre o HAProxy e o Apache. Isso está funcionando, porém com o Varnish entre o HAProxy está monitorando o Varnish. Se o Apache falhar, ele não fará failover para o outro Apache.

Existe uma configuração no HAProxy que irá superar esse problema?

Responder1

Se o Varnish estiver entre o HAproxy e o Apache, você pode simplesmente fazer com que o Varnish faça obalanceamento de carga, embora não seja tão robusto quanto as opções fornecidas pelo HAproxy.

O que seria melhor seria fazer com que o HAproxy enviasse conteúdo estático para o Varnish e o restante diretamente para os servidores back-end.

Haproxy.com tem um artigo muito bom sobre como fazer issoaqui.

Se você realmente deseja que o HAproxy verifique o status do VarnisheApache ao mesmo tempo (que estão no mesmo host), você tem duas opções:

  1. Configure backends/servidores fictícios no HAProxy que verificam o Apache e fazem com que o servidor Varnish correspondente rastreie o fictício:

    frontend HTTP-IN
      mode http
      default_backend Varnishes
    
    # All traffic goes here
    backend Varnishes
      mode http
      balance roundrobin 
      server Varnish-1 1.1.1.1:80 track Apache-1/Apache-1
      server Varnish-2 2.2.2.2:80 track Apache-2/Apache-2
    
    # No traffic ever goes here
    # Just used for taking servers out of rotation in 'backend Varnishes'
    backend Apache-1
      server Apache-1 1.1.1.1:8080 check
    
    backend Apache-2
      server Apache-2 2.2.2.2:8080 check
    
  2. Faça com que o Varnish retorne um resultado de verificação de integridade que corresponda ao status do Apache (OK se o Apache estiver ativo, FAILED caso contrário).

    verniz.vcl

    backend default {
      .host = "127.0.0.1";
      .port = "8080";
    }
    
    # Health Check
    if (req.url == "/varnishcheck") {
      if (req.backend.healthy) {
        return(synth(751, "OK!"));
      } else {
        return(synth(752, "FAILED!"));
      }
    }
    
    sub vcl_synth {
      # Health Checks
      if (resp.status == 751) {
        set resp.status = 200;
        return (deliver);
      }
      if (resp.status == 752) {
        set resp.status = 503;
        return (deliver);
      }
    }
    

    haproxy.cfg

    frontend HTTP-IN
      mode http
      default_backend Varnishes
    
    backend Varnishes
      mode http
      balance roundrobin 
      option httpchk HEAD /varnishcheck
      http-check expect status 200
      server Varnish-1 1.1.1.1:80 check
      server Varnish-2 2.2.2.2:80 check
    

informação relacionada