
Estoy pensando en poner Varnish entre HAProxy y Apache. Eso está funcionando, sin embargo, con Varnish en el medio, HAProxy está monitoreando Varnish. Si Apache deja de funcionar, no conmutará por error al otro Apache.
¿Existe alguna configuración en HAProxy que solucione este problema?
Respuesta1
Si Varnish está entre HAproxy y Apache, puedes hacer que Varnish haga lo mismo.balanceo de carga, aunque no es tan sólido como las opciones proporcionadas por HAproxy.
Lo que podría ser mejor sería que HAproxy envíe contenido estático a Varnish y el resto directamente a los servidores backend.
Haproxy.com tiene un muy buen artículo sobre cómo hacerlo.aquí.
Si realmente desea que HAproxy verifique el estado de VarnishyApache al mismo tiempo (que están en el mismo host), tienes dos opciones:
Configure backends/servidores ficticios en HAProxy que verifiquen Apache y hagan que el servidor Varnish correspondiente rastree el ficticio:
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
Haga que Varnish devuelva un resultado de verificación de estado que coincida con el estado de Apache (OK si Apache está activo, FALLADO en caso contrario).
barniz.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