码迷,mamicode.com
首页 > 其他好文 > 详细

【 LVS 】DR 方式实现过程

时间:2016-04-24 17:19:31      阅读:285      评论:0      收藏:0      [点我收藏+]

标签:

LVS-DR方式实现负载均衡

一、环境介绍

技术分享

 

lvs director配置:

[root@rhel7 ~]# ifconfig 
eno16777736: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.2.13  netmask 255.255.255.0  broadcast 192.168.2.255
        inet6 fe80::20c:29ff:feeb:7e7d  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:eb:7e:7d  txqueuelen 1000  (Ethernet)
        RX packets 534  bytes 47172 (46.0 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 422  bytes 44139 (43.1 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 0  (Local Loopback)
        RX packets 23  bytes 2480 (2.4 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 23  bytes 2480 (2.4 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

[root@rhel7 ~]# ifconfig eno16777736:0 192.168.2.14/32 broadcast 192.168.2.14  # 配置虚拟地址DIP
[root@rhel7 ~]# ifconfig 
eno16777736: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.2.13  netmask 255.255.255.0  broadcast 192.168.2.255
        inet6 fe80::20c:29ff:feeb:7e7d  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:eb:7e:7d  txqueuelen 1000  (Ethernet)
        RX packets 673  bytes 58778 (57.4 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 503  bytes 53741 (52.4 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

eno16777736:0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.2.14  netmask 0.0.0.0  broadcast 192.168.2.14
        ether 00:0c:29:eb:7e:7d  txqueuelen 1000  (Ethernet)

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 0  (Local Loopback)
        RX packets 23  bytes 2480 (2.4 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 23  bytes 2480 (2.4 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

[root@rhel7 ~]# route add -host 192.168.2.14 dev eno16777736:0

接下来对realserver进行配置:

  1、首先对arp_ignore和arp_announce进行修改

  2、再次将vip添加到网卡lo

[root@server1 ~]# vim /etc/sysctl.conf    # 在文件末尾处添加
net.ipv4.conf.all.arp_ignore = 1
net.ipv4.conf.all.arp_announce = 2
net.ipv4.conf.eth0.arp_ignore = 1
net.ipv4.conf.eth0.arp_announce = 2

[root@server1 ~]# sysctl -p
[root@server1 ~]# ifconfig lo:0 192.168.2.14/32 broadcast 192.168.2.14 up    # 在本地回环地址上添加VIP
[root@server1 ~]# route add -host 192.168.2.14 dev lo:0

两台realserver一样的配置,不在贴代码

 

配置IPVS规则:

[root@rhel7 ~]# vim /etc/hosts    # 配置好hosts是必须的

127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
# director
192.168.2.13    rhel7
10.0.0.1        rhel7

# realserver
10.0.0.10       RS1
10.0.0.11       RS2

[root@rhel7 ~]# ipvsadm -A -t 192.168.2.14:80 -s rr
[root@rhel7 ~]# ipvsadm -a -t 192.168.2.14:80 -r 192.168.2.10 -g -w 1
[root@rhel7 ~]# ipvsadm -a -t 192.168.2.14:80 -r 192.168.2.11 -g -w 1
[root@rhel7 ~]# ipvsadm -L -n 
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
  -> RemoteAddress:Port           Forward Weight ActiveConn InActConn
TCP  192.168.2.14:80 rr
  -> 192.168.2.10:80              Route   1      0          0         
  -> 192.168.2.11:80              Route   1      0          0

测试:

技术分享    技术分享

技术分享

 

【 LVS 】DR 方式实现过程

标签:

原文地址:http://www.cnblogs.com/hukey/p/5427431.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!