HA-Proxy für Plone via Buildout

Dieses Beispiel ist eigentlich für Plone, da nach dem "__ac"-Cookie geschaut wird. Für andere Cookies einfach die entsprechende Zeile ändern.

Vorbereitung

Voraussetzung:
- Python muss installiert sein
- Entwicklungswerkzeuge (gcc usw.)

 

Verzeichnis anlegen, rein da und bootstrap.py herunterladen

mkdir -p /opt/haproxy
cd /opt/haproxy
wget https://bootstrap.pypa.io/bootstrap-buildout.py

 

Jetzt die buildout.cfg mit folgendem Inhalt anlegen (user, group und bind ggf. anpassen):

[buildout]
parts =
haproxy-build
haproxy-conf

[haproxy-build]
recipe = plone.recipe.haproxy
url = http://www.haproxy.org/download/2.3/src/haproxy-2.3.7.tar.gz
target = generic


[haproxy-conf]
recipe = collective.recipe.template
input = ${buildout:directory}/haproxy.conf.in
output = ${buildout:directory}/etc/haproxy.conf
maxconn = 24000
user = nobody
group = nogroup
bind = 0.0.0.0:8180

 

Und eine haproxy.conf.in mit diesem Inhalt anlegen:

global
log 127.0.0.1 local6
maxconn  ${haproxy-conf:maxconn}
daemon
nbproc 1

defaults
mode http
option httpclose
# Remove requests from the queue if people press stop button
option abortonclose
# Try to connect this many times on failure
retries 3
# If a client is bound to a particular backend but it goes down,
# send them to a different one
option redispatch
monitor-uri /haproxy-ping

timeout connect 7s
timeout queue   300s
timeout client  300s
timeout server  300s

# Enable status page at this URL, on the port HAProxy is bound to
stats enable
stats uri /haproxy-status
stats refresh 5s
stats realm Haproxy statistics

frontend zopecluster
bind ${haproxy-conf:bind}
default_backend zope

# Load balancing over the zope instances
backend zope
# Use Zope's __ac cookie as a basis for session stickiness if present.
appsession __ac len 32 timeout 1d
# Otherwise add a cookie called "serverid" for maintaining session stickiness.
# This cookie lasts until the client's browser closes, and is invisible to Zope.
cookie serverid insert nocache indirect
# If no session found, use the roundrobin load-balancing algorithm to pick a backend.
balance roundrobin
# Use / (the default) for periodic backend health checks
option httpchk

# Server options:
# "cookie" sets the value of the serverid cookie to be used for the server
# "maxconn" is how many connections can be sent to the server at once
# "check" enables health checks
# "rise 1" means consider Zope up after 1 successful health check
server servername1 192.168.0.1:8080 cookie cookie1 check maxconn 2 rise 1
server servername2 192.168.0.2:8080 cookie cookie2 check maxconn 2 rise 1

 

Installation

Jetzt noch ein bootstrap.py aufrufen um die buildout-Umgebung zu generieren, dann ein buildout und der HA-Proxy kann gestartet werden

python bootstrap-buildout.py
bin/buildout

 

Starten

/opt/haproxy/bin/haproxy -D -f /opt/haproxy/etc/haproxy.conf -p /var/run/haproxy.pid
Neuen Kommentar hinzufügen

Sie können einen Kommentar abgeben, indem Sie das unten stehende Formular ausfüllen. Nur Text. Web- und E-Mail-Adressen werden in anklickbare Links umgewandelt.