LVS-Dr 脚本

#!/bin/bash
VIP=192.168.19.254
RS=(192.168.19.2 192.168.19.3)
DIP=192.168.19.1
lvsstart () {
if [ ! -e /sbin/ipvsadm ];then
   echo "ERROR!! please install ipvsadm tool"
else
    ifconfig eth0:1 $VIP netmask 255.255.255.0 broadcast $VIP up
    route add -host $VIP dev eth0:1
    echo 1 > /proc/sys/net/ipv4/ip_forward
    ipvsadm -A -t $VIP:80 -s rr
    ipvsadm -a -t $VIP:80 -r ${RS[0]} -g
    ipvsadm -a -t $VIP:80 -r ${RS[1]} -g
    echo "lvs already running......"
fi
}
lvsstop () {
    ipvsadm -C
    ifconfig eth0:1 down
    echo "lvs stop"
}
RS () {
   ifconfig lo:0 $VIP netmask 255.255.255.255 broadcast $VIP up
   route add -host $VIP dev lo:0
   echo 2 >/proc/sys/net/ipv4/conf/all/arp_announce
   echo 1 >/proc/sys/net/ipv4/conf/all/arp_ignore
}
router () {
   echo 1 > /proc/sys/net/ipv4/ip_forward
}
case $1 in
lvs-start) lvsstart;;
lvs-stop) lvsstop;;
rs) RS;;
router) router;;
*) echo "Usage sh lvs-DR lvs-start|lvs-stop|rs|router"
esac


你可能感兴趣的:(LVS,dr模式脚本)