ipvsadm

一、下载安装

wget http://www.linuxvirtualserver.org/software/kernel-2.6/ipvsadm-1.26.tar.gz

yum -y install  libnl* popt* gcc* kernel-devel*  popt-static*

tar zxf ipvsadm-1.26.tar.gz

ln -sf ipvsadm-1.26 ipvsadm

cd ipvsadm

make && make install

二、

运行在realserver上的脚本

#/bin/bash

VIP=192.168.10.50

case $1 in

start)

/sbin/ifconfig lo down

/sbin/ifconfig lo up

echo 1 > /proc/sys/net/ipv4/conf/eth0/arp_ignore

echo 2 > /proc/sys/net/ipv4/conf/eth0/arp_announce

echo 1 > /proc/sys/net/ipv4/conf/all/arp_ignore

echo 2 > /proc/sys/net/ipv4/conf/all/arp_announce

/sbin/ifconfig lo:0 $VIP broadcast $VIP netmask 255.255.255.255 up

/sbin/route add -host $VIP dev lo:0

;;

stop)

/sbin/ifconfig lo:0 down

echo 0 > /proc/sys/net/ipv4/conf/eth0/arp_ignore

echo 0 > /proc/sys/net/ipv4/conf/eth0/arp_announce

echo 0 > /proc/sys/net/ipv4/conf/all/arp_ignore

echo 0 > /proc/sys/net/ipv4/conf/all/arp_announce

/sbin/route del $VIP 

;;

status)

islothere = '/sbin/ifconfig lo:0|grep $VIP'

isrothere = 'route -n|grep "lo:0"|grep $VIP'

if [ ! "islothere" -o ! "isrothere" ] ; then

   echo "LVS_DR real server stoped."

else

   echo "LVS_DR real server running."

fi

;;

*)

echo "$0:Usage:$0 {start|stop|status}"

exit 1

;;

esac


运行在direct上的脚本

#Director脚本

#/bin/bash

VIP=192.168.10.50

DIP=192.168.10.53

RIP1=192.168.10.51

RIP2=192.168.10.52

PORT=80

FUNCTION=wlc

TYPE=g

RSWEIGHT1=2

RSWEIGHT2=1


case $1 in

start)

/sbin/ifconfig eth0:0 $VIP broadcast $VIP netmask 255.255.255.255 up

        /sbin/route add -host $VIP dev eth0:0


echo 1 > /proc/sys/net/ipv4/ip_forward

/sbin/iptables -F

/sbin/iptables -Z

/sbin/iptables -C

/sbin/ipvsadm -A -t $VIP:$PORT -s $FUNCTION

/sbin/ipvsadm -a -t $VIP:$PORT -r $RIP1 -$TYPE -w $RSWEIGHT1

/sbin/ipvsadm -a -t $VIP:$PORT -r $RIP2 -$TYPE -w $RSWEIGHT2

#创建一个锁文件

/bin/touch /var/lock/subsys/ipvsadm &> /dev/null

;;

stop)

echo 0 > /proc/sys/net/ipv4/ip_forward

/sbin/ipvsadm -C

/sbin/ifconfig eth0:0 down

/sbin/route del $VIP

#删除锁文件

/bin/rm -rf /var/lock/subsys/ipvsadm

echo "ipvs is stoped..."

;;

status)

if [ ! -e /var/lock/subsys/ipvsadm ] ; then

 echo "ipvs is stoped..."

else

 echo "ipvs is running..."

 ipvsadm -L -n

fi

;;

*)

echo "Usage:$0 {start|stop|status}"

;;

esac


你可能感兴趣的:(ipvs)