LVS-Real Server腳本
01
#!/bin/bash
02
03
#Parameters
04
VIP=192.168.22.5
05
06
case "$1" in
07
start)
08
echo "Starting LVS Real Server ..."
09
10
#Bind Virtual IP Address
11
/sbin/ifconfig lo:0 $VIP netmask 255.255.255.255 broadcast $VIP up
12
/sbin/route add -host $VIP dev lo:0
13
14
#Forbid ARP Request
15
echo "1" >/proc/sys/net/ipv4/conf/lo/arp_ignore
16
echo "2" >/proc/sys/net/ipv4/conf/lo/arp_announce
17
echo "1" >/proc/sys/net/ipv4/conf/all/arp_ignore
18
echo "2" >/proc/sys/net/ipv4/conf/all/arp_announce
19
sysctl -p > /dev/null 2>&1
20
21
echo "OK"
22
;;
23
stop)
24
echo "Stopping LVS Real Server ..."
25
26
/sbin/ifconfig lo:0 down
27
echo "0" >/proc/sys/net/ipv4/conf/lo/arp_ignore
28
echo "0" >/proc/sys/net/ipv4/conf/lo/arp_announce
29
echo "0" >/proc/sys/net/ipv4/conf/all/arp_ignore
30
echo "0" >/proc/sys/net/ipv4/conf/all/arp_announce
31
32
echo "LVS Real Server Stopped ."
33
;;
34
restart)
35
$0 stop
36
$0 start
37
*)
38
echo "Usage:$0 { start | stop | restart }"
39
exit 1
40
esac
41
exit 0