Re: keepalived state BACKUP but keeps running?

Tom van Leeuwen <[email protected]>
Newsgroups gmane.linux.keepalived.devel
Message-ID <[email protected]>
You could write a check script that inspect the output of "ipvsadm -Ln".

Here's something I quickly created for you:
keepalived.conf:
global_defs {
   router_id MYROUTER
}

vrrp_script chk_myscript {
   script       "/etc/keepalived/check_real_servers.sh"
   interval 2   # check every 2 seconds
   fall 2       # require 2 failures for KO
   rise 2       # require 2 successes for OK
}

vrrp_instance vrrp_eth0 {
   state BACKUP
   interface eth0
   virtual_router_id 1
   priority 150
   preempt_delay 90

   authentication {
     auth_type PASS
     auth_pass secret
   }

   virtual_ipaddress {
     10.0.2.50/32
   }

   track_script {
     chk_myscript
   }
}

virtual_server 10.0.2.50 80 {
   delay_loop 5
   lb_algo sh
   lb_kind NAT
   protocol TCP
   persistence_granularity 255.255.255.255
   persistence_timeout 3600
   virtualhost localhost

   # local nginx default site to test with
   real_server 10.0.2.15 80 {
     weight 1
     HTTP_GET {
       url {
         path /
         status_code 200
       }

       connect_timeout 3
       nb_get_retry 3
       delay_before_retry 3
     }
   }
}

check_real_servers.sh:
#!/bin/bash

ipvsadm -Ln | grep -qP '^\s*-> \d+'
exit $?

Everything runs fine when I have nginx running on the keepalived server, 
but when I stop it it fails like you want. Please see this syslog output:
Jan 26 06:36:03 ubuntu-14 Keepalived[3181]: Starting Keepalived v1.2.7 
(08/14,2013)
Jan 26 06:36:03 ubuntu-14 Keepalived[3182]: Starting Healthcheck child 
process, pid=3183
Jan 26 06:36:03 ubuntu-14 Keepalived[3182]: Starting VRRP child process, 
pid=3185
Jan 26 06:36:03 ubuntu-14 Keepalived_healthcheckers[3183]: Initializing 
ipvs 2.6
Jan 26 06:36:03 ubuntu-14 Keepalived_vrrp[3185]: Interface queue is empty
Jan 26 06:36:03 ubuntu-14 Keepalived_vrrp[3185]: Registering Kernel 
netlink reflector
Jan 26 06:36:03 ubuntu-14 Keepalived_vrrp[3185]: Registering Kernel 
netlink command channel
Jan 26 06:36:03 ubuntu-14 Keepalived_vrrp[3185]: Registering gratuitous 
ARP shared channel
Jan 26 06:36:03 ubuntu-14 Keepalived_vrrp[3185]: Initializing ipvs 2.6
Jan 26 06:36:03 ubuntu-14 Keepalived_healthcheckers[3183]: Interface 
queue is empty
Jan 26 06:36:03 ubuntu-14 Keepalived_healthcheckers[3183]: Registering 
Kernel netlink reflector
Jan 26 06:36:03 ubuntu-14 Keepalived_healthcheckers[3183]: Registering 
Kernel netlink command channel
Jan 26 06:36:03 ubuntu-14 Keepalived_healthcheckers[3183]: Opening file 
'/etc/keepalived/keepalived.conf'.
Jan 26 06:36:03 ubuntu-14 Keepalived_vrrp[3185]: Opening file 
'/etc/keepalived/keepalived.conf'.
Jan 26 06:36:03 ubuntu-14 Keepalived_vrrp[3185]: Configuration is using 
: 64224 Bytes
Jan 26 06:36:03 ubuntu-14 Keepalived_healthcheckers[3183]: Configuration 
is using : 11417 Bytes
Jan 26 06:36:03 ubuntu-14 Keepalived_healthcheckers[3183]: Using 
LinkWatch kernel netlink reflector...
Jan 26 06:36:03 ubuntu-14 Keepalived_vrrp[3185]: Using LinkWatch kernel 
netlink reflector...
Jan 26 06:36:03 ubuntu-14 Keepalived_vrrp[3185]: 
VRRP_Instance(vrrp_eth0) Entering BACKUP STATE
Jan 26 06:36:03 ubuntu-14 Keepalived_healthcheckers[3183]: Activating 
healthchecker for service [10.0.2.15]:80
Jan 26 06:36:03 ubuntu-14 Keepalived_vrrp[3185]: 
VRRP_Script(chk_myscript) succeeded
Jan 26 06:36:07 ubuntu-14 Keepalived_vrrp[3185]: 
VRRP_Instance(vrrp_eth0) Transition to MASTER STATE
Jan 26 06:36:08 ubuntu-14 Keepalived_vrrp[3185]: 
VRRP_Instance(vrrp_eth0) Entering MASTER STATE

 >>>> STOPPING NGINX <<<

Jan 26 06:36:44 ubuntu-14 Keepalived_healthcheckers[3183]: Error 
connecting server [10.0.2.15]:80.
Jan 26 06:36:44 ubuntu-14 Keepalived_healthcheckers[3183]: Removing 
service [10.0.2.15]:80 from VS [10.0.2.50]:80
Jan 26 06:36:44 ubuntu-14 Keepalived_healthcheckers[3183]: Lost quorum 
1-0=1 > 0 for VS [10.0.2.50]:80
Jan 26 06:36:47 ubuntu-14 Keepalived_vrrp[3185]: 
VRRP_Script(chk_myscript) failed
Jan 26 06:36:48 ubuntu-14 Keepalived_vrrp[3185]: 
VRRP_Instance(vrrp_eth0) Entering FAULT STATE
Jan 26 06:36:48 ubuntu-14 Keepalived_vrrp[3185]: 
VRRP_Instance(vrrp_eth0) Now in FAULT state

Inspired by: 
https://tobrunet.ch/2013/07/keepalived-check-and-notify-scripts/

Kind regards,
Tom van Leeuwen

On 23-01-15 17:37, Stefan Kärst wrote:
> Hi,
>
> I know this is the devel-list but maybe some developer can quickly
> answer a simple question (or point to a good wiki/manual). Is there a
> user-mailing list??
>
> Is it possible to make keepalived go into BACKUP state if all real
> servers (on the local machine) are down?
>
> I've got some mysql nodes with keepalived running. keepalived checks
> health of real-ip:3306. If one mysqld stops working keepalived should
> become BACKUP so VIP moves to another node (of the mysql cluster). How
> do I set this up without ending keepalived!?
>
> Many Thanks!
> Best Regards
> Stefan K.
>
>
> ------------------------------------------------------------------------------
> New Year. New Location. New Benefits. New Data Center in Ashburn, VA.
> GigeNET is offering a free month of service with a new server in Ashburn.
> Choose from 2 high performing configs, both with 100TB of bandwidth.
> Higher redundancy.Lower latency.Increased capacity.Completely compliant.
> http://p.sf.net/sfu/gigenet
> _______________________________________________
> Keepalived-devel mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/keepalived-devel


------------------------------------------------------------------------------
Dive into the World of Parallel Programming. The Go Parallel Website,
sponsored by Intel and developed in partnership with Slashdot Media, is your
hub for all things parallel software development, from weekly thought
leadership blogs to news, videos, case studies, tutorials and more. Take a
look and join the conversation now. http://goparallel.sourceforge.net/
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.