0

I am trying to configure keepalived in such a way that if any application or service running on master node fails, keepalived should consider it as fault and backup node should act as master and take over the floating IP from master node.

I have written a script to check if service X on master server goes down, then it should transition to backup node.

My keepalived conf are:

global_defs {
enable_script_security
}
vrrp_script keepalived_check {
script "/root/new/check.sh"
interval 1
timeout 1
rise 2
fall 2
weight 0 reverse
}
vrrp_instance V1_11 {
state MASTER
interface ens3
virtual_router_id 51
priority 101
advert_int 1
unicast_src_ip 192.168.10.129
unicast_peer {
    192.168.10.130
}
authentication {
    auth_type PASS
    auth_pass 1122
}
virtual_ipaddress {
    192.168.10.231/24
}
track_script {
    keepalived_check
}
}

The Script that checks the service status:

#!/bin/bash
var="$(systemctl is-active myservice.service)"

if [ $var == "active" ]
then
    echo 0
else
    echo 5
fi

I manually stopped the "myservice" using

systemctl stop myservice.service

The output for script is "5" as expected. But with above mentioned configurations, master node remains as primary node and it doesn't shift ownership to backup node. Is there any particular config that I have missed then kindly help me find that?

0 Answers0