【 LVS 】DR 方式實現過程

來源:互聯網
上載者:User

標籤:

LVS-DR方式實現負載平衡

一、環境介紹

 

lvs director配置:

[[email protected] ~]# 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 0lo: 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[[email protected] ~]# ifconfig eno16777736:0 192.168.2.14/32 broadcast 192.168.2.14  # 配置虛擬位址DIP[[email protected] ~]# 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 0eno16777736: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

[[email protected] ~]# route add -host 192.168.2.14 dev eno16777736:0

接下來對realserver進行配置:

  1、首先對arp_ignore和arp_announce進行修改

  2、再次將vip添加到網卡lo

[[email protected] ~]# vim /etc/sysctl.conf    # 在檔案末尾處添加net.ipv4.conf.all.arp_ignore = 1net.ipv4.conf.all.arp_announce = 2net.ipv4.conf.eth0.arp_ignore = 1net.ipv4.conf.eth0.arp_announce = 2[[email protected] ~]# sysctl -p[[email protected] ~]# ifconfig lo:0 192.168.2.14/32 broadcast 192.168.2.14 up    # 在本地迴環地址上添加VIP
[[email protected] ~]# route add -host 192.168.2.14 dev lo:0

兩台realserver一樣的配置,不在貼代碼

 

配置IPVS規則:

[[email protected] ~]# vim /etc/hosts    # 配置好hosts是必須的127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4::1         localhost localhost.localdomain localhost6 localhost6.localdomain6# director192.168.2.13    rhel710.0.0.1        rhel7# realserver10.0.0.10       RS110.0.0.11       RS2[[email protected] ~]# ipvsadm -A -t 192.168.2.14:80 -s rr[[email protected] ~]# ipvsadm -a -t 192.168.2.14:80 -r 192.168.2.10 -g -w 1[[email protected] ~]# ipvsadm -a -t 192.168.2.14:80 -r 192.168.2.11 -g -w 1[[email protected] ~]# ipvsadm -L -n IP Virtual Server version 1.2.1 (size=4096)Prot LocalAddress:Port Scheduler Flags  -> RemoteAddress:Port           Forward Weight ActiveConn InActConnTCP  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 方式實現過程

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.