当前位置:首页 > 操作系统 > Linux

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:
[root@localhost ~]# route add default gw 192.168.1.254 dev eth0
设置Client 的网关
GW:
[root@localhost ~]# echo 1 > /proc/sys/net/ipv4/ip_forward
在网关服务器设置开启转发
Real Server A & Real Server B:
[root@localhost ~]# yum install httpd    

在两台网站服务器装httpd    

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

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

  [root@localhost ~]# route add default gw 172.16.1.254 dev eth0
为eth0设置网关
Director:
[root@localhost ~]# echo 1 > /proc/sys/net/ipv4/ip_forward
[root@localhost ~]# route add default gw 1.1.1.254 dev eth0
[root@localhost ~]# yum install ipvsadm

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

650) this.width=650;" src="/upload/getfiles/default/2022/11/17/20221117122554025.jpg" title="2014-03-21 16:18:02的屏幕截图.png" />


[root@localhost ~]# ipvsadm -Ln --stat

650) this.width=650;" src="/upload/getfiles/default/2022/11/17/20221117122554450.jpg" title="2014-03-21 16:19:36的屏幕截图.png" />


650) this.width=650;" src="/upload/getfiles/default/2022/11/17/20221117122555133.jpg" title="2014-03-21 16:13:05的屏幕截图.png" />


备注 数据包走向
====================================
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



本文出自 “cisco” 博客,请务必保留此出处http://1585654.blog.51cto.com/1575654/1381068

原文:http://1585654.blog.51cto.com/1575654/1381068


【说明】本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:254677821)!