Keepalived, HAProxy and varnish: Difference between revisions

From Skytech
Jump to navigation Jump to search
(Created page with "= Setting up Keepalived, HAProxy and Varnish = == Install & setup Keepalived == == Install & setup HAProxy == == Install & setup Varnish ==")
 
No edit summary
Line 1: Line 1:
= Setting up Keepalived, HAProxy and Varnish =
= Setting up Keepalived, HAProxy and Varnish =
Assuming debian install, but packages should exists for popular distroes as well


== Install & setup Keepalived ==
== Install packages ==
<pre>
aptitude install keepalived varnish haproxy
</pre>


== Install & setup HAProxy ==


== Install & setup Varnish ==
== Setup keepalived ==
MASTER:
Edit

<code>/etc/keepalived/keepalived.conf</code>

<pre>
vrrp_script chk_haproxy { # Requires keepalived-1.1.13
script "killall -0 haproxy" # cheaper than pidof
interval 2 # check every 2 seconds
weight 2 # add 2 points of prio if OK
}

vrrp_script chk_nginx { # Requires keepalived-1.1.13
script "killall -0 nginx" # cheaper than pidof
interval 2 # check every 2 seconds
weight 2 # add 2 points of prio if OK
}

vrrp_instance VI_1 {
interface eth0
state MASTER
virtual_router_id 152
priority 101 # 101 on master, 100 on backup
virtual_ipaddress {
172.30.1.248
}
track_script {
chk_haproxy
}
}

vrrp_instance VI_2 {
interface eth0
state MASTER
virtual_router_id 162
priority 101 # 101 on master, 100 on backup
virtual_ipaddress {
172.30.1.247
}
track_script {
chk_nginx
}
}
</pre>


SLAVE:

== Setup HAProxy ==
MASTER:
<pre>
# this config needs haproxy-1.1.28 or haproxy-1.2.1

global
log 127.0.0.1 local0
log 127.0.0.1 local1 notice
maxconn 8196
user haproxy
group haproxy
daemon

defaults
log global
mode http
option httplog
option dontlognull
retries 3
option redispatch
maxconn 20000
contimeout 5000
clitimeout 50000
srvtimeout 50000

listen varnish_farm 172.30.1.248:80
mode http
cookie SERVERID insert indirect nocache
balance roundrobin
option http-server-close
option forwardfor
stats enable
stats auth admin:Toklon
server varnish1 172.30.1.23:80 cookie varnish11 check
server varnish2 172.30.1.75:80 cookie varnish12 check
</pre>

SLAVE:
== Setup Varnish ==
MASTER & SLAVE are equal on both servers.

Revision as of 15:27, 5 September 2012

Setting up Keepalived, HAProxy and Varnish

Assuming debian install, but packages should exists for popular distroes as well

Install packages

aptitude install keepalived varnish haproxy


Setup keepalived

MASTER: Edit

/etc/keepalived/keepalived.conf

vrrp_script chk_haproxy {           # Requires keepalived-1.1.13
        script "killall -0 haproxy"     # cheaper than pidof
        interval 2                      # check every 2 seconds
        weight 2                        # add 2 points of prio if OK
}

vrrp_script chk_nginx {           # Requires keepalived-1.1.13
        script "killall -0 nginx"     # cheaper than pidof
        interval 2                      # check every 2 seconds
        weight 2                        # add 2 points of prio if OK
}

vrrp_instance VI_1 {
        interface eth0
        state MASTER
        virtual_router_id 152
        priority 101                    # 101 on master, 100 on backup
        virtual_ipaddress {
            172.30.1.248
        }
        track_script {
            chk_haproxy
        }
}

vrrp_instance VI_2 {
        interface eth0
        state MASTER
        virtual_router_id 162
        priority 101                    # 101 on master, 100 on backup
        virtual_ipaddress {
            172.30.1.247
        }
        track_script {
            chk_nginx
        }
}


SLAVE:

Setup HAProxy

MASTER:

# this config needs haproxy-1.1.28 or haproxy-1.2.1

global
        log 127.0.0.1   local0
        log 127.0.0.1   local1 notice
        maxconn 8196
        user haproxy
        group haproxy
        daemon

defaults
        log     global
        mode    http
        option  httplog
        option  dontlognull
        retries 3
        option redispatch
        maxconn 20000
        contimeout      5000
        clitimeout      50000
        srvtimeout      50000

listen varnish_farm 172.30.1.248:80
        mode http
        cookie SERVERID insert indirect nocache
        balance roundrobin
        option http-server-close
        option forwardfor
        stats enable
        stats auth admin:Toklon
        server varnish1 172.30.1.23:80 cookie varnish11 check
        server varnish2 172.30.1.75:80 cookie varnish12 check

SLAVE:

Setup Varnish

MASTER & SLAVE are equal on both servers.