本文共 1751 字,大约阅读时间需要 5 分钟。
[root@zyl lvs]# cat lvs_client.sh #!/bin/sh#--------------------------------------------#Author: Created by zhangyiling 2016-08#Mail:#Function: This scripts function is LVS_client#Version:4.1.2#---------------------------------------------. /etc/init.d/functions VIP=( 192.168.21.8 192.168.21.6)case "$1" in start) action "start LVS of REALServer IP" /bin/true echo "[" for ((i=0; i<`echo ${#VIP[*]}`;i++)) do interface="lo:`echo ${VIP[$i]}|awk -F . '{print $4}'`" /sbin/ifconfig $interface ${VIP[$i]} broadcast ${VIP[$i]} netmask 255.255.255.255 up route add -host ${VIP[$i]} dev $interface >/dev/null 2>&1 done echo "1" >/proc/sys/net/ipv4/conf/lo/arp_ignore echo "2" >/proc/sys/net/ipv4/conf/all/arp_announce echo "1" >/proc/sys/net/ipv4/conf/lo/arp_ignore echo "2" >/proc/sys/net/ipv4/conf/all/arp_announce ;; stop) for ((i=0; i<`echo ${#VIP[*]}`;i++)) do interface="lo:`echo ${VIP[$i]}|awk -F . '{print $4}'`" /sbin/ifconfig $interface ${VIP[$i]} broadcast ${VIP[$i]} netmask 255.255.255.255 down route del -host ${VIP[$i]} dev $interface >/dev/null 2>&1 done action "stop LVS of REALServer IP" /bin/true echo "["# echo "0" >/proc/sys/net/ipv4/conf/lo/arp_ignore# echo "0" >/proc/sys/net/ipv4/conf/all/arp_announce ;; *) echo "Usage:$0 {start|stop}"esac
转载于:https://blog.51cto.com/zhagyilig/1856445