负载均衡LVS实现

引用网站
http://sery.blog.51cto.com/10037/54645
http://www.wappan.com/html/93/fac20ee3c5bc1659bc8e6ba2771c5b31.html

ipvs安装时与http://www.wappan.com/html/93/fac20ee3c5bc1659bc8e6ba2771c5b31.html为准

配置时与http://sery.blog.51cto.com/10037/54645为准

以下是配置好的代码
分派器代码

#!/bin/sh
VIP=192.168.5.114
RIP1=192.168.5.136
RIP2=192.168.5.31
/etc/rc.d/init.d/functions
case "$1" in
start)
echo "start LVS of DirectorServer"
#Set the Virtual IP Address
/sbin/ifconfig eth0:1 $VIP broadcast $VIP netmask 255.255.255.255 up
/sbin/route add -host $VIP dev eth0:1
#Clear IPVS Table
/sbin/ipvsadm -C
#Set Lvs
/sbin/ipvsadm -A -t $VIP:80 -s rr
/sbin/ipvsadm -a -t $VIP:80 -r $RIP1:80 -g
/sbin/ipvsadm -a -t $VIP:80 -r $RIP2:80 -g
$Run Lvs
/sbin/ipvsadm
;;
stop)
echo "close LVS DirectorServer"
/sbin/ipvsadm -C
/sbin/ifconfig eth0:1 down
;;
*)
echo "Usage: $0 {start|stop}"
exit 1
esac

linux 的real server 代码
#!/bin/sh
VIP=192.168.5.114
/etc/rc.d/init.d/functions
case "$1" in
start)
/sbin/ifconfig lo:0 $VIP broadcast $VIP netmask 255.255.255.255 up
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
;;
stop)
/sbin/ifconfig lo:0 down
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 "Usage: $0 {start|stop}"
exit 1
esac






你可能感兴趣的:(html,c,linux,.net,UP)