#!/usr/bin/env bash
# LVS 管理脚本[DR模式]

VIP=192.168.198.228/32

start(){
	# 设置虚拟 IP
	ip addr add $VIP dev lo
	# 修改内核参数
	echo "1" >/proc/sys/net/ipv4/conf/lo/arp_ignore
	echo "2" >/proc/sys/net/ipv4/conf/lo/arp_announce
	echo "1" >/proc/sys/net/ipv4/conf/all/arp_ignore
	echo "2" >/proc/sys/net/ipv4/conf/all/arp_announce
	echo "RealServer Start OK [lvs_dr]"
}

stop(){
	echo "0" >/proc/sys/net/ipv4/conf/lo/arp_ignore
	echo "0" >/proc/sys/net/ipv4/conf/lo/arp_announce
	echo "0" >/proc/sys/net/ipv4/conf/all/arp_ignore
	echo "0" >/proc/sys/net/ipv4/conf/all/arp_announce
	ip addr del $VIP dev lo
	echo "RealServer Stoped [lvs_dr]"
}

restart(){
	stop
	start
}

case $1 in

    start)
         start
          ;;
    stop)
         stop
          ;;
    restart)
         restart
          ;;
    status)
         ip addr show lo | grep ${VIP}
          ;;
    *)
       echo "Usage: $(basename $0 .sh) {start|stop|restart|status}"
       exit 1
esac
