lvs 虚IP 轮训配置

脚本内容

[root@hadoop ~]$ cat lvs-rs.sh 
#!/bin/bash
VIP=10.230.96.204
subnet_name=204
case "$1" in
start)
       ifconfig lo:${subnet_name} $VIP netmask 255.255.255.255 broadcast $VIP
       /sbin/route add -host $VIP dev lo:${subnet_name}
       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
       sysctl -p >/dev/null 2>&1
       echo "RealServer Start OK"
       ;;
stop)
       ifconfig lo:${subnet_name} down
       route del $VIP >/dev/null 2>&1
       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
       echo "RealServer Stoped"
       ;;
status)
        # Status of LVS-DR real server.
        islothere=`/sbin/ifconfig lo:0 | grep $VIP`
        isrothere=`netstat -rn | grep "lo:0" | grep $VIP`
        if [ ! "$islothere" -o ! "isrothere" ];then
            # Either the route or the lo:0 device
            # not found.
            echo "LVS-DR real server Stopped."
        else
            echo "LVS-DR Running."
        fi
;;
*)
        # Invalid entry.
        echo "$0: Usage: $0 {start|status|stop}"
        exit 1
;;
esac
exit 0

执行命令

sh lvs-rs.sh start

查看IP绑定情况

ip a

inet 192.168.10.100/32 brd 192.168.10.100 scope global lo:0
posted @ 2021-08-17 18:03  whiteY  阅读(75)  评论(0编辑  收藏  举报