Skip to content

Instantly share code, notes, and snippets.

@lemajes
Last active February 27, 2023 13:05
[Keepalived 101] Keepalived 101 #keepalived #101

Keepalived 101

primaryhost

# vi /etc/keepalived/keepalived.conf

vrrp_script chk_maxscale {
    script "pidof maxscale"
    interval 2
}

vrrp_instance VI_1 {
    state MASTER
    interface bond0
    virtual_router_id 51
    priority 150
    advert_int 1
    authentication {
    auth_type PASS
       auth_pass mypass
    }
    virtual_ipaddress {
       192.168.177.222
    }
    track_script {
      chk_maxscale
    }

notify /etc/keepalived/notify_script.sh
}

backuphost

# vi /etc/keepalived/keepalived.conf

vrrp_script chk_maxscale {
    script "pidof maxscale"
    interval 2
}

vrrp_instance VI_1 {
    state MASTER
    interface bond0
    virtual_router_id 51
    priority 100
    advert_int 1
    authentication {
    auth_type PASS
       auth_pass mypass
    }
    virtual_ipaddress {
       192.168.177.222
    }
    track_script {
      chk_maxscale
    }

notify /etc/keepalived/notify_script.sh
}

script

#!/bin/bash
TYPE=$1
NAME=$2
STATE=$3
OUTFILE=/home/user/state.txt

case $STATE in
 "MASTER") echo "Setting this MaxScale node to active mode" > $OUTFILE
              maxctrl alter maxscale passive false
              exit 0
              ;;
 "BACKUP") echo "Setting this MaxScale node to passive mode" > $OUTFILE
              maxctrl alter maxscale passive true
              exit 0
              ;;
 "FAULT")  echo "MaxScale failed the status check." > $OUTFILE
              maxctrl alter maxscale passive true
              exit 0
              ;;
    *)     echo "Unknown state" > $OUTFILE
              exit 1
              ;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment