vip=$(host vip.company.tld | awk '/has address/ { print $NF }'); for i in {01..2}; do server="server$i.company.tld"; echo -n "$server : "; ssh -q "$server" "ip a | grep -Eq \"^ +inet $vip
\" && echo 'has VIP' || echo 'no VIP'"; done
server01.company.tld : no VIP server02.company.tld : has VIP
vip.company.tld is an alias for foo.bar.baz. foo.bar.baz has address 12.34.56.78
vip='12.34.56.78'; for i in {01..2}; do server="server$i.company.tld"; echo -n "$server : "; ssh -q "$server" "ip a | grep -Eq \"^ +inet $vip
\" && echo 'has VIP' || echo 'no VIP'"; done
server01.company.tld : no VIP server02.company.tld : has VIP
^ +inet $vip
\"ssh -t ha02-prp "sudo systemctl stop keepalived && sleep 1 && sudo systemctl start keepalived"
+------------------+ +------------------+ | host A | | host B | | | negotiation | | | +----------+ | <=================> | +----------+ | | |keepalived| | | |keepalived| | | +----------+ | | +----------+ | +------------------+ +------------------+
keepalived --version Keepalived v1.2.13 (05/28,2014) keepalived.conf.SYNOPSIS https://github.com/acassen/keepalived/blob/master/doc/keepalived.conf.SYNOPSIS
global_defs { vrrp_check_unicast_src } vrrp_script check_things { script "path/to/script.sh" interval 2 weight 2 } vrrp_instance cluster { interface eth0 virtual_router_id 1, unicast_src_ip 10.201.36.9 my IP unicast_peer { 10.201.36.8 my peer's IP } priority 102 nopreempt virtual_ipaddress_excluded { 10.201.36.14 the VIP we're sharing (details) } track_script { check_things } notify "/usr/local/sbin/keepalived_state.sh" notify_stop "/usr/local/sbin/keepalived_state.sh unknown_type unknown_name STOPPED" }
Flag | Usage |
---|---|
notify path/to/script | scripts that keepalived invokes after changing state (sources : 1, 2) |
notify_stop path/to/script [user group ... ] | script to be called on VRRP service stop (source) |
track_script | List of scripts (referred to via the name of their corresponding vrrp_script entry) monitoring the state of other daemons. (source) :
Looks like
track_script { check_things }automagically translates into : vrrp_script check_things {
script "/usr/local/etc/keepalived_toggle.d/things"
}
|
virtual_ipaddress { } | a VIP definition block, up to 20 IP addresses |
virtual_ipaddress_excluded { } |
|
vrrp_script | Adds a script to be executed periodically (sources : 1, 2) |