Chinaunix首页 | 论坛 | 博客
  • 博客访问: 231706
  • 博文数量: 57
  • 博客积分: 955
  • 博客等级: 准尉
  • 技术积分: 587
  • 用 户 组: 普通用户
  • 注册时间: 2010-11-14 13:30
文章分类

全部博文(57)

文章存档

2012年(2)

2011年(55)

分类: LINUX

2011-06-27 21:08:28

  1. #lvs 三种模式: NAT NAT模式
  2. DR 直接路由
  3. TUN 隧道模式

  4. ## lvs----架构,--
  5. DR模式
  6.  public---router------ld---(1,realserver01; 2,realserver 02)
  7.  使用四台虚拟机实验,全部桥接,-----真实机器作为client实验
  8.  
  9.  client: 10.212.182.2 gw: 10.212.182.1
  10.  router eth0: 10.212.182.1 ,eth1 : 10.212.183.1
  11.  ld eth0: 10.212.183.2 eth0:0 10.212.183.3
  12.  realserver01: 10.212.183.4 lo:0 10.212.183.3
  13.  realserver02: 10.212.183.5 lo:0 10.212.183.3
  14.  
  15.  ---------------------------------------------
  16.  client:
  17.  ifconfig eth0 10.212.182.2
  18.  route add default gw 10.212.182.1
  19.  ----------------------
  20.  router:
  21.  ifconfig eth0 10.212.182.1 netmask 255.255.255.0 broadcast 10.212.182.255 up
  22.   ifconfig eth1 10.212.183.1 netmask 255.255.255.0 broadcast 10.212.183.255 up
  23.   开启包转发
  24. echo 1 > /proc/sys/net/ipv4/ip_forward
  25. ---------------------------------------
  26. ld:
  27. ifconfig eth0 10.212.183.2 netmask 255.255.255.0 broadcast 10.212.183.255 up
  28. ifconfig eth0:0 10.212.183.3 netmask 255.255.255.255 broadcast 10.212.183.3 up
  29. 同样开启包转发
  30. echo 1 > /proc/sys/net/ipv4/ip_forward
  31. 先增加服务
  32. ipvsadm -A -t 10.212.183.3:80 -s rr
  33. -A 添加服务 -t 服务所使用的虚拟ip地址:端口 (虚拟地址工业环境应该是公网ip) -s 算法 (rr 算法就是你一个,我一个)

  34. 把这个服务和后面的server pool进行关联

  35. ipvsadm -a -t 10.212.183.3:80 -r 10.212.183.4 -g
  36. ipvsadm -a -t 10.212.183.3:80 -r 10.212.183.5 -g
  37. -a 添加real server -r real server的ip -g (DR模式) -m是NAT模式

  38. -----------------------------------
  39. realserver01----------------------
  40. 所有realserver的配置脚本实现,当然首先需要安装httpd
  41. #!/bin/bash
  42. #written by booduklee
  43. # time: 2011-06-27
  44. # this is used to configure realserver in the lvs
  45. echo "please mount your cd to /mnt\n"
  46. YUM=/etc/yum.repos.d
  47. VIP=10.212.183.3
  48. ROUTE=10.212.183.1
  49. mkdir /tmp/repo_bak
  50. find $YUM -name "*.repo" -exec mv {} /tmp/repo_bak \;
  51. cat >> $YUM/server.repo << !
  52. [base]
  53. name=server
  54. baseurl=file:///mnt/Server
  55. enabled=1
  56. gpgcheck=0
  57. gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release
  58. !
  59. yum clean all
  60. yum install httpd -y
  61. rm -rf $YUM/server.repo
  62. mv /tmp/repo_bak/* $YUM
  63. rm -rf /tmp/repo_bak
  64. case "$1" in
  65. start)
  66. ifconfig lo:0 $VIP netmask 255.255.255.255 broadcast $VIP up
  67. route add -host $VIP dev lo:0
  68. route add default gw $ROUTE
  69. echo 1 > /proc/sys/net/ipv4/conf/lo/arp_ignore
  70. echo 2 > /proc/sys/net/ipv4/conf/lo/arp_announce
  71. echo 2 > /proc/sys/net/ipv4/conf/all/arp_announce
  72. echo 1 > /proc/sys/net/ipv4/conf/all/arp_ignore
  73. echo "VIP start"
  74. ;;

  75. stop)
  76. ifconfig lo:0 down
  77. echo 0 > /proc/sys/net/ipv4/conf/lo/arp_ignore
  78. echo 0 > /proc/sys/net/ipv4/conf/lo/arp_announce
  79. echo 0 > /proc/sys/net/ipv4/conf/all/arp_announce
  80. echo 0 > /proc/sys/net/ipv4/conf/all/arp_ignore
  81. echo "VIP stop"
  82. ;;

  83. *)
  84. echo "USAGE start | stop"
  85. exit 1
  86. ;;
  87. esac


  88. ---------------------测试---------------------------
  89. client#elinks http://10.212.183.3/index.html --dump
  90.    hello,this is realserver02
  91. client#elinks http://10.212.183.3/index.html --dump
  92.    hello ,this is realserver01
  93. client#elinks http://10.212.183.3/index.html --dump
  94.    hello,this is realserver02
  95. client#elinks http://10.212.183.3/index.html --dump
  96.    hello ,this is realserver01
阅读(1500) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~