DR。。我X,这XX有什么不会的。之傻瓜版

 配置环境

IP 192.168.1.2 client客户端

   192.168.1.1/2.1 路由器(两块网卡)

   192.168.2.2  (Vip:192.168.2.250)分发   需要:yum install ipvsadm -y

   192.168.2.3  (Vip:192.168.2.250)apache服务器   需要:yum install httpd -y

   192.168.2.4  (Vip:192.168.2.250)apache服务器   需要:yum install httpd -y

环境配置完成

 

client客户端设置

设定网关

route add default gw 192.168.1.1

结束。

 

路由器设置

开启转发

 

vim /etc/sysctl.conf 

net.ipv4.ip_forward = 1
结束。
 
分发设置
绑定Vip
ifconfig eth0:0 192.168.2.250/32 broadcast 192.168.2.250 up
设定正确的路由(就是自己)
route add -host 192.168.2.250 dev eth0:0
开始做分发
设定规则为rr(你一次我一次)
ipvsadm -A -t 192.168.2.250:80 -s rr
ipvsadm -a -t 192.168.2.250:80 -r 192.168.2.4 -g
ipvsadm -a -t 192.168.2.250:80 -r 192.168.2.3 -g
查看下呗~~
ipvsadm -ln
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
  -> RemoteAddress:Port           Forward Weight ActiveConn InActConn
TCP  192.168.2.250:80 rr
  -> 192.168.2.4:80               Route   1      0          0         
  -> 192.168.2.3:80               Route   1      0          0     
 
结束。
 
配置apache(IP:2.3)
绑定VIP为lo口,方便设定在路由广播时候不回应
ifconfig lo:0 192.168.2.250/32 broadcast 192.168.2.250 up
设定到主机的路由
route add -host 192.168.2.250 dev lo:0
指定网关
route add default gw 192.168.2.1
查看下呗~~
route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
192.168.2.250   0.0.0.0         255.255.255.255 UH    0      0        0 lo
192.168.2.0     0.0.0.0         255.255.255.0   U     0      0        0 eth0
169.254.0.0     0.0.0.0         255.255.0.0     U     0      0        0 eth0
0.0.0.0         192.168.2.1     0.0.0.0         UG    0      0        0 eth0
忽略路由广播arp协议
echo 1 > /proc/sys/net/ipv4/conf/all/arp_ignore
通告路由
echo 2 > /proc/sys/net/ipv4/conf/all/arp_announce
此文件为老师给的脚本,需要修改如下
vim /etc/init.d/vip.txt
前三行
#!/bin/bash
对应的VIP
VIP=192.168.2.250
对应的网关
ROUTE=192.168.2.1
 
运行脚本
/etc/init.d/vip.txt restart
 
开启http服务
建立一个http文件
echo hello2.3 > /var/www/html/index.html
结束。
下面的那个apache我就不说了,一模一样就可以了~就是把http文件改成
echo hello2.4 > /var/www/html/index.html
 
测试!!!!!
client(客户端)
client1.2#elinks http://192.168.2.250/index.html --dump
   hello2.4
client1.2#elinks http://192.168.2.250/index.html --dump
   hello2.3
client1.2#elinks http://192.168.2.250/index.html --dump
   hello2.4
client1.2#elinks http://192.168.2.250/index.html --dump
   hello2.3
 
 
 
抓包结果:

从抓包结果看,nat不适合大量服务器时候使用,大量的服务器连接,IP地址的更改,会给分发的单一节点巨大压力,使之成为nat的瓶颈~
 
大功告成,功成身退。祝大家圆满完成~~

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章