GénéralLinux

HAproxy 1.6 sur debian 8 avec keepalived

HAproxy is out !
Il est temps de documenter l’installation de HAproxy avec keepalived qui va gerer noter bascule de VIP.
Keepalived va s’occuper de la bascule de VIP via VRRP.

installation des paquets

Installons HAproxy 1.6 grace aux dépots de http://haproxy.debian.net/

$ apt install keepalived haproxy

Autorisons linux à utiliser une adresse non localement configurée

$ echo "net.ipv4.ip_nonlocal_bind=1" >> /etc/sysctl.conf
$ sysctl -p

keepalived configuration, /etc/keepalived/keepalived.conf
Le fichier de configuration est commenté avec les information de la manpage que je vous invite a lire.

Sur le noeud maître:

# global definitions
global_defs {
}

# healthcheck of HAproxy
vrrp_script check_haproxy {
        script "killall -0 haproxy" # killall is faster
        interval 2 # in sec
        weight 2   #
}

# vrrp instance definition
vrrp_instance vrrp_01 {
        state MASTER
        interface eth0
        virtual_router_id 10 # used to differentiate multiple instances of vrrpd running on the same NI
        priority 150         # to be MASTER, make 50 more than other machines. priority 100
        use_vmac             # Use VRRP Virtual MAC - will create a vrrp.10 iface
        # authentication to access vrrpd
        authentication {
                auth_type PASS
                auth_pass testpass
        }
        # vip on wich HAproxy run
        virtual_ipaddress {
                192.168.122.10
                192.168.122.9
        }
        # healthcheck to use
        track_script {
                check_haproxy
        }
}

Peu de différences pour la configuration du noeud esclave (slave state et priority):

 definitions
global_defs {
}

# healthcheck of HAproxy
vrrp_script check_haproxy {
    script "killall -0 haproxy" # killall is faster
    interval 2 # in sec
    weight 2   #
}

# vrrp instance definition
vrrp_instance vrrp_01 {
    state SLAVE
    interface eth0
    virtual_router_id 10 # used to differentiate multiple instances of vrrpd running on the same NI
    priority 50          # to be MASTER, make 50 more than other machines. priority 100
    use_vmac             # Use VRRP Virtual MAC - will create a vrrp.10 iface
    # authentication to access vrrpd
    authentication {
        auth_type PASS
        auth_pass testpass
    }
    # vip on wich HAproxy run
    virtual_ipaddress {
        192.168.122.10
        192.168.122.9
    }
    # healthcheck to use
    track_script {
        check_haproxy
    }
}

HAproxy configuration
Utiliser la même configuration sur tous vos noeuds est chaudement recommandé :-)

Je vous laisse découvrir HAproxy si vous ne connaissez pas déjà ce formidable logiciel !
Je décris ici une configuration simpliste pour tester notre configuration de keepalived:

frontend f_vrrp10_svc
 bind 192.168.122.10:80
 default_backend b_webfarm
 
backend b_webfarm
 server srv1 192.168.122.21:80 check
 server srv2 192.168.122.22:80 check
 server srv3 192.168.122.23:80 check

Ce post est inspiré par cet article.
http://dasunhegoda.com/how-to-setup-haproxy-with-keepalived/833/

Related Posts:

Leave a Reply