因为lvs nat模式下,只有入站方向的流量经过lvs服务器,出站流量直接由Real server服务器响应,所以Real Server服务器必须做相应的配置才能响应客户数据包,即修改Real server做负载均衡时回包的源地址要改为VIP,另外要修改Real server的arp响应策略,关闭arp响应功能。
#!/bin/bash
#description:start real server
VIP=192.168.12.200
./etc/rc.d/init.d/functions
case "$1" in
start)
echo " Start LVS of Real Server "
/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
通过service lvsrs {start|stop}开启或关闭lvsrs