lvs 负载均衡配置(dr 模式)

全栈 shanhuhai 3791℃ 0评论

负载均衡机 load blancer

!/bin/bash

GW=10.2.19.255

website director vip.

SNS_VIP=10.2.19.83
SNS_RIP1=10.2.19.85
SNS_RIP2=10.2.19.86

logger $0 called with $1
case “$1” in
start)
# set squid vip
/sbin/ipvsadm –set 30 5 60
/sbin/ifconfig eth1:0 $SNS_VIP broadcast $SNS_VIP netmask 255.255.255.255 up
/sbin/route add -host $SNS_VIP dev eth1:0
/sbin/ipvsadm -A -t $SNS_VIP:80 -s wrr -p 3
/sbin/ipvsadm -a -t $SNS_VIP:80 -r $SNS_RIP1:80 -g -w 1
/sbin/ipvsadm -a -t $SNS_VIP:80 -r $SNS_RIP2:80 -g -w 1
touch /var/lock/subsys/ipvsadm >/dev/null 2>&1
;;
stop)
/sbin/ipvsadm -C
/sbin/ipvsadm -Z
ifconfig eth1:0 down
ifconfig eth1:1 down
route del $SNS_VIP
rm -rf /var/lock/subsys/ipvsadm >/dev/null 2>&1
echo “ipvsadm stoped”
;;
status)
if [ ! -e /var/lock/subsys/ipvsadm ];then
echo “ipvsadm stoped”
exit 1
else
echo “ipvsadm OK”
fi
;;
*)
echo “Usage: $0 {start|stop|status}”
exit 1
esac
exit 0

真实机

!/bin/bash

. /etc/init.d/functions
SNS_VIP=10.2.19.83

case “$1” in
start)

  ifconfig lo:0 $SNS_VIP netmask 255.255.255.255 broadcast $SNS_VIP 
  /sbin/route add -host $SNS_VIP dev lo:0 
  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 
  sysctl -p >/dev/null 2>&1 
  echo "RealServer Start OK" 
  ;; 

stop)

 ifconfig lo:0 down 
  route del $SNS_VIP >/dev/null 2>&1 
  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 "RealServer Stoped" 
  ;; 

*)

  echo "Usage: $0 {start|stop}" 
  exit 1 

esac
exit 0

cp lvs_dr.sh /etc/rc.d/init.d/
service lvs_dr.sh start #启动lvs RS服务器

http://wolfchen.blog.51cto.com/2211749/1122841

修改keepalive日志位置

我们只需要修改 /etc/sysconfig/keepalived 就可以了
把KEEPALIVED_OPTIONS=”-D” 修改为KEEPALIVED_OPTIONS=”-D -d -S 0″

最后设置syslog,修改/etc/rsyslog.conf
最后添加:

keepalived -S 0

local0.* /var/log/keepalived.log
重新启动日志
/etc/init.d/rsyslog restart
使用以下命令进行验证
/etc/init.d/keepalived restart;tailf /var/log/keepalived.log

转载请注明:大后端 » lvs 负载均衡配置(dr 模式)

喜欢 (0)or分享 (0)
发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址