脚本内容如下
#!/bin/bash
set -o xtrace
PGCANDIDATES=(192.168.0.92 192.168.0.93 192.168.0.94 192.168.0.95)
# HOSTNAME=`hostname -i`
VIP=192.168.0.110
GW=192.168.1.1
DEVICE=enp0s3
STEP1="Remove the VIP on all nodes"
STEP2="Check if vip still online"
STEP3="Promte primary DB"
STEP4="Add vip on new primary DB"
STEP5="Clear ARP Cache"
###step1. Remove the VIP on all nodes
for candidate in "${PGCANDIDATES[@]}"; do
echo $candidate
ssh -p '22' postgres@$candidate -tt "
ip addr del $VIP/24 dev $DEVICE
exit
"
done
####clear arp cache
/usr/bin/sudo /sbin/arping -I $DEVICE -b -c 5 $GW
#/usr/bin/sudo /sbin/arping -I $DEVICE -s $VIP -b -c 5 $GW
#/usr/bin/sudo /sbin/arping -I enp0s3 -s 192.168.0.92 -b -c 5 192.168.1.1
#/usr/bin/sudo /sbin/arping -I enp0s3 -b -c 5 192.168.1.1
###step2.Check if vip still online
/usr/bin/sudo /usr/bin/ping -c1 -w1 -t5 ${VIP}
if [ $? -eq 0 ]; then
echo repmgr_promote_command.sh: ${STEP2} : ${VIP} failed !!!
exit 1
fi
###step4.Add vip on new primary DB
/usr/bin/sudo /sbin/ip addr add $VIP/24 dev $DEVICE
if [ $? -ne 0 ]; then
echo repmgr_promote_command.sh: ${STEP4} on ${HOSTNAME} failed !!!
exit 1
fi
####step5.Clear arp cache
/usr/bin/sudo /sbin/arping -I $DEVICE -s $VIP -b -c 3 $GW
if [ $? -ne 0 ]; then
echo repmgr_promote_command.sh: ${STEP5} on ${HOSTNAME} failed !!!
exit 1
fi
标签:bin,IP,sudo,192.168,VIP,usr,linux,DEVICE
From: https://www.cnblogs.com/ives/p/18183764