Skip to main content

Balanceador con HAProxy y Keepalived


apt-get install keepalived


nano /etc/keepalived/keepalived.conf


global_defs {
   notification_email {
     keepalived@ateinco.com.com
   }
   notification_email_from keepalived@ateinco.com
   smtp_server 127.0.0.1
   smtp_connect_timeout 30
   router_id TESTATEINCO_DEVEL
}
vrrp_script chk_haproxy {
    script "killall -0 haproxy"
    interval 1
    weight -2
}
vrrp_instance VI_1 {
    state MASTER
    interface eth0
    virtual_router_id 51
    mcast_src_ip 172.30.15.225
    priority 100
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 876543
    }
    virtual_ipaddress {
        172.30.15.224/24 dev eth0 label eth0:1
    }
    track_interface {
        eth0
    }
    track_script {
        chk_haproxy
    }
}


apt-get install haproxy


nano /etc/haproxy/haproxy.cfg


                                             
global
        log /dev/log    local0
        log /dev/log    local1 notice
        chroot /var/lib/haproxy
        stats socket /run/haproxy/admin.sock mode 660 level admin expose-fd listeners
        stats timeout 30s
        user haproxy
        group haproxy
        daemon

        # Default SSL material locations
        ca-base /etc/ssl/certs
        crt-base /etc/ssl/private

        # See: https://ssl-config.mozilla.org/#server=haproxy&server-version=2.0.3&config=intermediate
        ssl-default-bind-ciphers ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:E>
        ssl-default-bind-ciphersuites TLS_AES_128_GCM_SHA256:TLS_AES_256_GCM_SHA384:TLS_CHACHA20_POLY1305_SHA256
        ssl-default-bind-options ssl-min-ver TLSv1.2 no-tls-tickets

defaults
        log     global
        mode    http
        option  httplog
        option  dontlognull
        timeout connect 5000
        timeout client  50000
        timeout server  50000
        errorfile 400 /etc/haproxy/errors/400.http
        errorfile 403 /etc/haproxy/errors/403.http
        errorfile 408 /etc/haproxy/errors/408.http
        errorfile 500 /etc/haproxy/errors/500.http
        errorfile 502 /etc/haproxy/errors/502.http
        errorfile 503 /etc/haproxy/errors/503.http
        errorfile 504 /etc/haproxy/errors/504.http

listen  galera_cluster
    bind 0.0.0.0:3306
    mode tcp
    #option tcplog
    option tcpka
    option mysql-check user haproxy
    balance source
    server db1 172.30.15.221:3306 check
    server db2 172.30.15.222:3306 check
    server db3 172.30.15.223:3306 check

listen  http_cluster
    bind 0.0.0.0:80
    mode http
    stats enable
    #option tcplog
	option httpchk GET /index.php HTTP/1.0
    http-check expect rstatus (2|3)[0-9][0-9]|503
    cookie PHPSESSID prefix indirect nocache
    balance source
    server web1 172.30.15.121:80 check
    server web2 172.30.15.122:80 check
    server web3 172.30.15.123:80 check

listen stats
    bind 0.0.0.0:8080
    mode http
    option httplog
    stats enable
    stats uri /
    stats realm Strictly\ Private
    stats auth admin:admin