NFS - ha with keepalived and shared storage

From Skytech
Jump to: navigation, search


NFS - HA with keepalived and shared storage

# Install keepalived - sample config below #
vrrp_script chk_nfsd {           # Requires keepalived-1.1.13
        script "killall -0 nfsd"     # cheaper than pidof
        interval 2                      # check every 2 seconds
#        weight 2                        # add 2 points of prio if OK
}
vrrp_instance VI7 {
        interface bond0
        state BACKUP
        nopreempt
        virtual_router_id 222
        priority 100                    # 101 on master, 100 on backup
        virtual_ipaddress {
                10.45.8.191
        }
        track_script {
                chk_nfsd
        }
        notify /usr/local/bin/nfs_statechange.sh
}

## Content of script: /usr/local/bin/nfs_statechange.sh
#!/bin/bash

TYPE=$1
NAME=$2
STATE=$3

case $STATE in
        "MASTER") /etc/init.d/nfs-kernel-server start
                  exit 0
                  ;;
        "BACKUP") /etc/init.d/nfs-kernel-server status
                  exit 0
                  ;;
        "FAULT")  /etc/init.d/nfs-kernel-server restart
                  exit 0
                  ;;
        *)        echo "unknown state"
                  exit 1
                  ;;
esac

## Add fsid to the nfs export or you will get 'Stale NFS handle' ##
/share/esxi    10.0.0.0/8(rw,no_root_squash,insecure,async,no_subtree_check,fsid=42)