linux 负载均衡(4层)


                              ++++++++++++
                              +     Client            +   eth0 192.168.1.1/24
                              ++++++++++++
            |
             |
                              ++++++++++++   up eth0:192.168.1.254/24
                              +        GW             +
                              ++++++++++++   down eth1:1.1.1.254/24
                                          |
                                           |
                              ++++++++++++   VIP eth0:1.1.1.1/24
                              +      Director        +
                              ++++++++++++   DIP eth1:172.16.1.254/24
                                           |
                        ___________|____________
                       |                                         | 
                       |                                         |
          ++++++++++++            ++++++++++++
          +  Real Server A  +               +  Real Server B  +
          ++++++++++++            ++++++++++++
           eth0:172.16.1.1/24             eth0:172.16.1.2/24


配置LVS VS/NAT模式
=================================
Client:
[[email protected] ~]# route add default gw 192.168.1.254 dev eth0
设置Client 的网关

GW:
[[email protected] ~]# echo 1 > /proc/sys/net/ipv4/ip_forward
在网关服务器设置开启转发

Real Server A & Real Server B:
[[email protected] ~]# yum install httpd    

在两台网站服务器装httpd    

A /var/www/html/index.html A的网页zhangyunming1 

A /var/www/html/index.html B的网页zhangyunming2

  [[email protected] ~]# route add default gw 172.16.1.254 dev eth0
为eth0设置网关

Director:
[[email protected] ~]# echo 1 > /proc/sys/net/ipv4/ip_forward
[[email protected] ~]# route add default gw 1.1.1.254 dev eth0
[[email protected] ~]# yum install ipvsadm

用yum装ipvsadm包
[[email protected] ~]# ipvsadm -A -t 1.1.1.1:80 -s rr
[[email protected] ~]# ipvsadm -a -t 1.1.1.1:80 -r 172.16.1.1:80 -m
[[email protected] ~]# ipvsadm -a -t 1.1.1.1:80 -r 172.16.1.2:80 -m
[[email protected] ~]# ipvsadm -Ln

linux 负载均衡(4层)


[[email protected] ~]# ipvsadm -Ln --stat

linux 负载均衡(4层)


linux 负载均衡(4层)


备注数据包走向
====================================
1.Client---------->GW
sip:CIP dip:VIP
smac:Client_mac dmac:GW_up_mac

2.GW-------------->Director
sip:CIP dip:VIP
smac:GW_down_mac dmac:VIP_mac

3.Director-------->Real Server (DNAT)
sip:CIP dip:RIP
smac:DIP_mac dmac:RealServer_mac

4.Real Server----->Director
sip:RIP dip:CIP
smac:RealServer_mac dmac:DIP_mac

5.Director-------->GW
sip:VIP dip:CIP
smac:VIP_mac dmac:GW_down_mac

6.GW-------------->Client
sip:VIP dip:CIP
smac:GW_up_mac dmac:Client_mac











本文转自zhang25yun51CTO博客,原文链接: http://blog.51cto.com/1585654/1381068,如需转载请自行联系原作者