original https://github.com/hashicorp/serf/tree/master/demo/web-load-balancer
refs https://github.com/kentaro/serf-hosts
install command.
export SERF_ROLE=lb
sh ./setup_load_balancer.sh
sh ./setup_serf.sh
stop agent command.
stop serf
start agent command.
start serf
require apache or nginx.
install command.
export SERF_ROLE=web
export LB_IP="xxx.xxx.xxx.xxx"
sh ./setup_serf.sh
As a result,
web
is now also a member of cluster.member-join
event is occurred.web
is added into/etc/haproxy/haproxy.cfg
onlb
node.
[root@lb001 ~]# cat /etc/haproxy/haproxy.cfg
global
daemon
maxconn 256
defaults
mode http
timeout connect 5000ms
timeout client 50000ms
timeout server 50000ms
listen stats
bind *:9999
mode http
stats enable
stats uri /
stats refresh 2s
listen http-in
bind *:80
balance roundrobin
option http-server-close
server web001.foo.com 192.168.xxx.xxx check
server web002.foo.com 192.168.xxx.xxx check
stop agent and leave command.
sudo stop serf
start agent and join command.
sudo start serf
sudo start serf-join
see the members of the Serf cluster
serf members
stop web
. Then member-leave
event is propagated to lb
and the handler script is fired.
sudo stop serf
see the members of the Serf cluster
serf members
As a result,
web
is now not a member of cluster.member-leave
event is occurred.web
is removed from/etc/haproxy/haproxy.cfg
onlb
node.
- CentOS 6.x x86_64
- Scientific Linux 6.x x84_64