Chinaunix首页 | 论坛 | 博客
  • 博客访问: 972905
  • 博文数量: 99
  • 博客积分: 3306
  • 博客等级: 中校
  • 技术积分: 1238
  • 用 户 组: 普通用户
  • 注册时间: 2009-04-21 10:14
文章分类

全部博文(99)

文章存档

2012年(37)

2011年(56)

2010年(6)

分类: 系统运维

2011-09-14 19:55:17

DR模式是用的最多的
LVS机器上
  1. #!/bin/bash
  2. # websitedirector vip.
  3. VIP=10.253.3.21
  4. RIP1=10.253.3.14
  5. RIP2=10.253.3.15
  6. RIP3=10.253.3.16
  7. case "$1" in
  8. start)
  9. /sbin/ipvsadm -C
  10. #set lvs vip for dr
  11. /sbin/ipvsadm --set 30 5 60
  12. /sbin/ifconfig eth0:0 $VIP broadcast $VIP netmask 255.255.255.255 up
  13. /sbin/route add -host $VIP dev eth0:0
  14. /sbin/ipvsadm -A -t $VIP:80 -s wlc
  15. /sbin/ipvsadm -a -t $VIP:80 -r $RIP1:80 -g -w 1
  16. /sbin/ipvsadm -a -t $VIP:80 -r $RIP2:80 -g -w 1
  17. /sbin/ipvsadm -a -t $VIP:80 -r $RIP3:80 -g -w 1
  18. ;;
  19. stop)
  20. /sbin/ipvsadm -C
  21. /sbin/ipvsadm -Z
  22. ifconfig eth0:0 down
  23. route del $VIP >/dev/null 2>&1
  24. echo "ipvsadm stoped"
  25. ;;
  26. esac
RealServer上的配置
  1. VIP=10.253.3.21
  2. case "$1" in
  3. start)
  4.         ifconfig lo:0 $VIP netmask 255.255.255.255 broadcast $VIP
  5.         /sbin/route add -host $VIP dev lo:0
  6.         echo "1" >/proc/sys/net/ipv4/conf/lo/arp_ignore
  7.         echo "2" >/proc/sys/net/ipv4/conf/lo/arp_announce
  8.         echo "1" >/proc/sys/net/ipv4/conf/all/arp_ignore
  9.         echo "2" >/proc/sys/net/ipv4/conf/all/arp_announce
  10.         sysctl -p >/dev/null 2>&1
  11.         echo "RealServer Start OK"
  12.          ;;
  13. stop)
  14.         ifconfig lo:0 down
  15.         route del $VIP >/dev/null 2>&1
  16.         echo "0" >/proc/sys/net/ipv4/conf/lo/arp_ignore
  17.         echo "0" >/proc/sys/net/ipv4/conf/lo/arp_announce
  18.         echo "0" >/proc/sys/net/ipv4/conf/all/arp_ignore
  19.         echo "0" >/proc/sys/net/ipv4/conf/all/arp_announce
  20.         echo "RealServer Stoped"
  21.         ;;
  22.  *)
  23.         echo "Usage: $0 {start|stop}"
  24.         exit 1
  25.  esac
tunl模式的配置也类似
服务器上配置
  1. #!/bin/bash
  2. # websitedirector vip.
  3. VIP=10.253.3.21
  4. RIP1=10.253.3.14
  5. RIP2=10.253.3.15
  6. RIP3=10.253.3.16
  7. #./etc/rc.d/init.d/functions
  8. case "$1" in
  9. start)
  10. /sbin/ipvsadm -C
  11. #set lvs vip for eth0:0
  12. /sbin/ipvsadm --set 30 5 60
  13. /sbin/ifconfig eth0:0 $VIP broadcast $VIP netmask 255.255.255.255 up
  14. /sbin/route add -host $VIP dev eth0:0
  15. /sbin/ipvsadm -A -t $VIP:80 -s wlc
  16. /sbin/ipvsadm -a -t $VIP:80 -r $RIP1:80 -i -w 1
  17. /sbin/ipvsadm -a -t $VIP:80 -r $RIP2:80 -i -w 1
  18. /sbin/ipvsadm -a -t $VIP:80 -r $RIP3:80 -i -w 1
  19. ;;
  20. stop)
  21. /sbin/ipvsadm -C
  22. ifconfig eth0:0 down
  23. route del $VIP >/dev/null 2>&1
  24. echo "ipvsadm stoped"
  25. ;;
  26. esac
RealServer
  1. #!/bin/bash
  2. VIP=10.253.3.21
  3. case $1 in
  4. start)
  5. /sbin/ifconfig tunl0 down
  6. /sbin/ifconfig tunl0 up
  7. echo 1 > /proc/sys/net/ipv4/conf/tunl0/arp_ignore
  8. echo 2 > /proc/sys/net/ipv4/conf/tunl0/arp_announce
  9. echo 0 > /proc/sys/net/ipv4/conf/tunl0/rp_filter
  10. echo 1 > /proc/sys/net/ipv4/conf/all/arp_ignore
  11. echo 2 > /proc/sys/net/ipv4/conf/all/arp_announce
  12. /sbin/ifconfig tunl0 $VIP broadcast $VIP netmask 255.255.255.255 up
  13. /sbin/route add -host $VIP dev tunl0
  14. ;;
  15. stop)
  16. /sbin/ifconfig tunl0 down
  17. echo 0 > /proc/sys/net/ipv4/conf/tunl0/arp_ignore
  18. echo 0 > /proc/sys/net/ipv4/conf/tunl0/arp_announce
  19. echo 1 > /proc/sys/net/ipv4/conf/tunl0/rp_filter
  20. echo 0 > /proc/sys/net/ipv4/conf/all/arp_ignore
  21. echo 0 > /proc/sys/net/ipv4/conf/all/arp_announce
  22. ;;
  23. *)
  24. echo "$0: Usage: $0 {start|stop|status}"
  25. exit 1
  26. ;;
  27. esac

阅读(1380) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~