
Ich bin neu in diesem Lastausgleichsszenario und meine Aufgabe besteht darin, herauszufinden, wie dieser Lastausgleich funktioniert.
Meine Umgebung:
Centos 6.4 64 Bit
Webserver: Lighttpd
All running in ESXI
virtual IP: 192.168.1.6
LB1: 192.168.1.4
LB2: 192.168.1.5
Webserver 1: 192.168.1.12
Webserver 2: 192.168.1.13
Gateway: 192.168.1.1
Ich versuche, vor der Produktion einen Test im Labor mit HAproxy und Keepalived durchzuführen. Hier ist, was ich in meiner Keepalived-Einstellung habe:
! Konfigurationsdatei für Keepalived
global_defs {
notification_email {
[email protected]
}
notification_email_from [email protected]
smtp_server 192.168.1.4
smtp_connect_timeout 30
router_id 192.168.1.1
}
vrrp_script chk_haproxy {
script "killall -0 haproxy"
interval 1 # check every second
weight 2 # add 2 points of prio if OK
}
vrrp_instance VI_1 {
state MASTER
interface eth0
virtual_router_id 51
priority 101 #priority 101 for master
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.1.6
}
track_script {
chk_haproxy
}
}
und hier ist meine Einstellung für HAproxy
#---------------------------------------------------------------------
# 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
chroot /var/lib/haproxy
pidfile /var/run/haproxy.pid
maxconn 4000
user haproxy
group haproxy
daemon
# turn on stats unix socket
stats socket /var/lib/haproxy/stats
#---------------------------------------------------------------------
# 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 dontlognull
option http-server-close
option forwardfor except 127.0.0.0/8
option redispatch
retries 3
timeout http-request 10s
timeout queue 1m
timeout connect 10s
timeout client 1m
timeout server 1m
timeout http-keep-alive 10s
timeout check 10s
maxconn 3000
#---------------------------------------------------------------------
# main frontend which proxys to the backends
#---------------------------------------------------------------------
frontend main *:80
# acl url_static path_beg -i /static /images /javascript /stylesheets
# acl url_static path_end -i .jpg .gif .png .css .js
# use_backend static if url_static
# default_backend view
#---------------------------------------------------------------------
# static backend for serving up images, stylesheets and such
#---------------------------------------------------------------------
#backend static
# balance roundrobin
# server static 127.0.0.1:4331 check
#---------------------------------------------------------------------
# round robin balancing between the various backends
#---------------------------------------------------------------------
backend app
mode tcp
balance roundrobin
server server1 192.168.1.12:80 check inter 2000 rise 2 fall 5
server server2 192.168.1.13:80 check inter 2000 rise 2 fall 5
Als ich HAproxy gestartet habe, ist dieser Fehler aufgetreten und ich bin mir nicht ganz sicher, wo ich mit der Suche nach einer Lösung beginnen soll. Vielleicht kann mir jemand, der dies schon oft gemacht hat, helfen, Licht ins Dunkel zu bringen?
503 Service Unavailable No server is available to handle this request.
Die manuelle Verbindung zu Webserver1 und Webserver2 funktioniert jedoch problemlos.
Ich möchte lediglich eine einfache Lastverteilung für den Webserver, der hinter dem HAproxy sitzt. Jeder Rat oder Vorschlag ist herzlich willkommen. Bitte helfen Sie mir. Vielen Dank.
Antwort1
Ich habe HAproxy noch nie verwendet, aber eine kurze Suche lässt mich glauben, dass Sie default_backend app
direkt darunter Folgendes hinzufügen müssen frontend main *:80
. Ich sehe in dieser Konfiguration nirgendwo eine Verbindung zwischen Backend und Frontend.
Antwort2
Das Problem liegt in Ihrer HAProxy-Konfiguration. Wenn ich alle Kommentare aus Ihrer Konfiguration entferne, erhalte ich Folgendes:
global
log 127.0.0.1 local2
chroot /var/lib/haproxy
pidfile /var/run/haproxy.pid
maxconn 4000
user haproxy
group haproxy
daemon
stats socket /var/lib/haproxy/stats
defaults
mode http
log global
option httplog
option dontlognull
option http-server-close
option forwardfor except 127.0.0.0/8
option redispatch
retries 3
timeout http-request 10s
timeout queue 1m
timeout connect 10s
timeout client 1m
timeout server 1m
timeout http-keep-alive 10s
timeout check 10s
maxconn 3000
frontend main *:80
backend app
mode tcp
balance roundrobin
server server1 192.168.1.12:80 check inter 2000 rise 2 fall 5
server server2 192.168.1.13:80 check inter 2000 rise 2 fall 5
Und jetzt können Sie deutlich sehen, dass überhaupt keine Frontend-Konfiguration vorhanden ist. Anfragen kommen über HAProxy, frontend main
aber HAProxy weiß nicht, welche Server zuverlässig sind, um sie zu verarbeiten, und gibt daher 503 zurück.
Sie müssen das Backend mit default_backend
oder ohne ACL mit dem Frontend verknüpfen.
Sie sollten auch Statistiken verwenden, nicht nur mit Socket, sondern auch mit geschützter Weboberfläche. Ich kann Ihnen Informationen über Cluster hinter Haproxy anzeigen, welche Server offline sind, welche Probleme vorliegen, wie lange die Antwortzeiten sind und so weiter. Sehr nützlich zum Debuggen.
Antwort3
Antwort4
PFSense fügt automatisch (und einigermaßen unsichtbar) standardmäßig zusätzliche ACLs hinzu, wenn Sie ein TLS-Zertifikat verwenden. Ich habe im Abschnitt „Zusätzliche Zertifikate“ einen zweiten virtuellen Host und ein zweites Zertifikat hinzugefügt. Dadurch blieben die Standard-Zertifikat-ACLs bestehen.
Das Deaktivieren dieser ACLs und ein Neustart haben das Problem behoben.