2015-08-02 20 views
5

Sto usando Haproxy 1.5.14 in una VirtualBox VM (Boot2docker) in cui le risorse caricate in modo intermittente mostrano 503 senza alcuna rima o ragione, questo è particolarmente vero all'avvio del cluster.Haproxy e intermittenti 503 problemi

Il cluster è simile a questo, 1 front-end con porta 80 e 443 a 2 back-end che servono rispettivamente risorse statiche e roba websocket.

HAProxy

  • FE (front-end, per le risorse statiche)
  • BE (back-end, per i collegamenti WebSocket)

Per esempio l'attività statica servita dal front-end potrebbe essere

https://local.dev.myproject.com/assets/images/back.png

Nonostante il fro nt end server in corso, e nulla è cambiato, premendo refresh e guardando il debugger di chrome vedrò numerosi status 503 o OK 200 304, ma non è deterministico. Può andare da 503 a OK per tornare a 503, su qualsiasi risorsa. Quando si è collegati direttamente al server web, gli asset restituiscono bene quindi sembra qualcosa con haproxy.

Il meglio che posso capire è che il controllo dello stato non funziona correttamente e il server FE/BE viene rimosso temporaneamente dall'elenco interno di haproxy, ma non ha senso controllare ogni mezzo secondo e posso vedere le chiamate haproxy vengono inviate restituite dalla finestra di output del terminale FE/BE ok, ogni mezzo secondo come previsto.

Se guardo il rapporto delle statistiche haproxy, posso vedere i server periodicamente andare e venire, sfarfallando, nonostante nella finestra del terminale haproxy sta ancora chiamando i controlli di integrità senza lacune ei server li stanno restituendo come previsto.

In allegato è l'attuale configurazione di haproxy che sto utilizzando, qualsiasi aiuto è apprezzato.

#--------------------------------------------------------------------- 
# Example configuration for a possible web application. See the 
# full configuration options online. 
# 
# http://haproxy.1wt.eu/download/1.4/doc/configuration.txt 
# 
#--------------------------------------------------------------------- 

#--------------------------------------------------------------------- 
# Global settings 
#--------------------------------------------------------------------- 
global 
    # to have these messages end up in /var/log/haproxy.log you will 
    # need to: 
    # 
    # 1) configure syslog to accept network log events. This is done 
    # by adding the '-r' option to the SYSLOGD_OPTIONS in 
    # /etc/sysconfig/syslog 
    # 
    # 2) configure local2 events to go to the /var/log/haproxy.log 
    # file. A line like the following can be added to 
    # /etc/sysconfig/syslog 
    # 
    # local2.*      /var/log/haproxy.log 
    # 
    #log   127.0.0.1 local2 
    # log /lnl_zoom_shared/log local0 
    # log /lnl_zoom_shared/log local1 notice 

    chroot  /var/lib/haproxy 
    pidfile  /var/run/haproxy.pid 
    maxconn  4000 
    user  haproxy 
    group  haproxy 
    daemon 
    # SSL 
    #ca-base /etc/ssl 
    #crt-base /etc/ssl 
    ca-base /myproject_shared/SECURITY/local.dev.myproject.com/ 
    crt-base /myproject_shared/SECURITY/local.dev.myproject.com/ 
    tune.ssl.default-dh-param 1024 

    # turn on stats unix socket 
    #stats socket /var/lib/haproxy/stats 

    # Exposes the stat socket so we can manage the proxy through node.js 
    stats socket /tmp/haproxy.sock level admin 

#--------------------------------------------------------------------- 
# common defaults that all the 'listen' and 'backend' sections will 
# use if not designated in their block 
#--------------------------------------------------------------------- 
defaults 
    mode     http 
    log      global 
    option     httplog 
    option     http-server-close 
    option     http-pretend-keepalive 
    option     dontlognull 
    option     redispatch 
    option     contstats 
    option forwardfor  except 127.0.0.0/8 


    retries     3 
    backlog     10000 
    timeout client   25s 
    timeout connect   10s 
    timeout server   25s 
    #long timeoutfor websocket connections 
    timeout tunnel   3600s 
    timeout http-keep-alive 1s 
    timeout http-request 15s 
    timeout queue   30s 
    timeout tarpit   60s 
    default-server inter 3s rise 2 fall 3 
    #timeout check   10s 

    maxconn     256 

#--------------------------------------------------------------------- 
# Haproxy's internal stats on the servers below: password protected 
#--------------------------------------------------------------------- 
stats enable 
    stats auth admin:myadminpassword 
    stats uri /haproxy 
    stats refresh 5s 


#--------------------------------------------------------------------- 
# 
#--------------------------------------------------------------------- 
frontend public 
    # HTTP 
    bind *:80 

    # Redirect all HTTP traffic to HTTPS 
     redirect scheme https if !{ ssl_fc } 

     # HTTPS 
     # Example with CA certificate bundle 
     # bind :443 ssl crt cert.pem ca-file bundle.crt 
     # Example without CA certification bunch 
     bind *:443 ssl crt /myproject_shared/SECURITY/local.dev.myproject.com/local.dev.myproject.com.pem 


     acl url_static_BE path_beg -i /BE /primus 
     use_backend BE   if url_static_BE 

     # FRONT END (aka FE) STATIC ASSETS SERVER 
     # if path is a static asset, assume the front end server to handle it 
     acl url_static path_beg -i /static /images /javascript /stylesheets 
     acl url_static path_end -i .jpg .gif .png .css .js .html .ico 
     use_backend FE   if url_static 



     # GIT HOOKS for UPDATE on the git repo changes 
     acl url_githook  path_beg  -i /gitupdate 
     use_backend HACNTL   if url_githook 

     #BACK END (aka BE) 



    default_backend BE 




#--------------------------------------------------------------------- 
# controller for haproxy 
#--------------------------------------------------------------------- 
backend HACNTL 
    # Tell the backend that this is a secure connection, 
    # even though it's getting plain HTTP. 
    option forwardfor 
    http-request add-header X-Forwarded-Proto https if { ssl_fc } 

    server  SELF 127.0.0.1:3300 

#--------------------------------------------------------------------- 
# static backend for serving up images, stylesheets and such 
#--------------------------------------------------------------------- 
backend FE 
    # Tell the backend that this is a secure connection, 
    # even though it's getting plain HTTP. 
    option forwardfor 
    http-request add-header X-Forwarded-Proto https if { ssl_fc } 
    option httpchk GET /haproxy/getstatus 
    option httpchk HEAD/
    balance  roundrobin 

    #server  FE1 11.22.33.44:8000 maxconn 256 
    server FE_172.17.0.2 172.17.0.2:8000 maxconn 256 check inter 500ms 

#--------------------------------------------------------------------- 
# round robin balancing between the various backends 
#--------------------------------------------------------------------- 
backend BE 
    # Tell the backend that this is a secure connection, 
    # even though it's getting plain HTTP. 
    option forwardfor 
    http-request add-header X-Forwarded-Proto https if { ssl_fc } 
    #http-request set-header X-Custom-Header %[url] 
    #http-request set-header Connection upgrade 
    #http-request set-header Upgrade websocket 
    option httpchk GET /haproxy/getstatus 
    cookie SRVNAME insert nocache 
    balance  roundrobin 


    server BE_172.17.0.3 172.17.0.3:8888 maxconn 256 cookie  BE_172.17.0.3 check inter 500ms 

risposta

0

mentre non una correzione assoluta, consentendo a ciascun server di avviarsi uno alla volta ha risolto il problema per ora. fondamentalmente aggiungendo un sonno tra il comando run docker

+0

Ho la stessa situazione, haproxy-> docker nginx con app uwsgi e molto spesso ho ottenuto il 503 quando la pagina è stata aggiornata. Potresti elaborare la tua soluzione, cosa intendi per "consentire ad ogni server di avviarsi uno alla volta"? – ksopyla

+0

@ksirg ci sono un paio di 503 problemi diversi, lo stesso errore che proviene da fonti diverse. La mia applicazione ha diversi contenitori docker per il servizio web (ad es. 1) database, 2) server front-end 3) haproxy per loadbalance) che quando li ho avviati tutti in una volta, si sarebbero verificati immediatamente errori 503 all'avvio. Iniziarli uno alla volta con un ritardo di un paio di secondi tra di loro ha ridotto il 503 all'avvio, ma durante l'aggiornamento, in altri casi vengono ancora visualizzati per motivi che non capisco. Ma penso che sia collegato in rete. – TroyWorks

Problemi correlati