Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Detailed explanation of load balancing Cluster based on simulated lvs-nat Mode

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/03 Report--

The following brings you a detailed explanation of the load balancing cluster that simulates the lvs-nat model, hoping to give you some help in practical application. There are many things involved in load balancing, not many theories, and there are many books on the Internet. Today, we will use the accumulated experience in the industry to do an answer.

I. Preface

All the experiments are carried out in the virtual machine environment, and the purpose of the experiment is to build a load balancing cluster based on lvs-nat mode. This paper does not involve the principle of lvs, but only simulates the load balancing cluster of lvs-nat mode.

2. Topology diagram

Tool: ipvsadm

Environmental preparation:

Client: 192.168.91.128

Cloud load balancer CVM: VIP:192.168.91.3 DIP:10.0.0.254

Real server RS1:IP:10.0.0.111 gw:10.0.0.254

Real server RS2:IP:10.0.0.5 gw:10.0.0.254

III. Experimental operation

1. Client operation

[root@localhost ~] # ip al | grep "ens33" # View ip2: ens33: mtu 1500 qdisc pfifo_fast state UP qlen 1000 inet 192.168.91.128and24 brd 192.168.91.255 scope global dynamic ens33

2.RS1 server operation

[root@rs1 ~] # ip al | grep "ens33" # View ip2: ens33: mtu 1500 qdisc pfifo_fast state UP qlen 1000 inet 10.0.111 scope global ens33 24 brd 10.0.0.255 scope global ens33 [root@rs1 ~] # setenforce 0 # close selinux [root@rs1 ~] # iptables-F # for the convenience of the experiment Clear firewall rule yum install httpd # install httpd [root @ rs1 ~] # cat / var/www/html/index.html # View test web content web server RS1 [root@rs1 ~] # systemctl start httpd # launch httpd [root @ rs1 ~] # ss-tln | grep 80LISTEN 0 128: 80:: *

3.RS2 server operation

The operation is probably the same as above.

[root@rs2 ~] # ip al | grep "ens33" 2: ens33: mtu 1500 qdisc pfifo_fast state UP qlen 1000 inet 10.0.0.5 up 24 brd 10.0.0.255 scope global ens33 [root@rs2 ~] # setenforce 0 [root@rs2 ~] # iptables-F yum install httpd [root@rs2 ~] # cat / var/www/html/index.html web server RS2 [root@rs2 ~] # systemctl start httpd [root@rs2 ~] # ss-tln | grep 80LISTEN 0 128:: 80: *

4. Load balancer server operation

[root@localhost ~] # ip al | egrep "ens33 | ens37" # View ip2: ens33: mtu 1500 qdisc pfifo_fast state UP qlen 1000 inet 192.168.91.3 scope global dynamic ens333 24 brd 192.168.91.255 scope global dynamic ens333: ens37: mtu 1500 qdisc pfifo_fast state UP qlen 1000 inet 10.0.254 scope global ens37yum install ipvsadm # install lvs management tool ipvsadm [root@localhost ~ ] # rpm-ql ipvsadm # View ipvsadm program environment / etc/sysconfig/ipvsadm-config # configuration file / usr/lib/systemd/system/ipvsadm.service / usr/sbin/ipvsadm # core tools / usr/sbin/ipvsadm-restore # read configuration file / usr/sbin/ipvsadm-save # guarantee Save ipvsadm rule / usr/share/doc/ipvsadm-1.27/usr/share/doc/ipvsadm-1.27/README/usr/share/man/man8/ipvsadm-restore.8.gz/usr/share/man/man8/ipvsadm-save.8.gz/usr/share/man/man8/ipvsadm.8.gz [root@localhost ~] # systemctl enable ipvsadm # set boot self-startup [root@localhost ~] # systemctl start ipvsadm # startup service echo 1 > / proc / sys/net/ipv4/ip_forward # enable core forwarding [root@localhost ~] # cat / proc/sys/net/ipv4/ip_forward 1setenforce 0 # turn off selinux iptabels-F # for the convenience of experiment Clear the firewall rule ipvsadm- A-t 192.168.91.3lvs rr # the algorithm for setting the lvs scheduler is to poll ipvsadm- a-t 192.168.91.3lvs 80-r 10.0.0.111lvs 80-m # add a RS1 server, and the-m option specifies the nat mode ipvsadm- a-t 192.168.91.3lvs 80-r 10.0.0.0.5 lvs 80-m # add a RS2 server

5. Client test

According to the analysis of the results of the script, the client polling visits two real servers (RS1 and RS2), which proves that the load balancing mode of the polling scheduling algorithm has been successfully implemented.

[root@localhost ~] # for i in {1.. 10}; do curl http://192.168.91.3;doneweb server RS2web server RS1web server RS2web server RS1web server RS2web server RS1web server RS2web server RS1web server RS2web server RS1

6. Modify the scheduling algorithm to wrr (weighted polling)

Server-side operation of load balancing

[root@localhost ~] # ipvsadm-E-t 192.168.91.3 wrr 80-s wrr # modify the scheduling algorithm to wrr [root@localhost ~] # ipvsadm-e-t 192.168.91.3wrr 80-r 10.0.111wrr 80-m-w 2 # modify the weight of RS1 to 2 [root@localhost ~] # ipvsadm-Ln # View Rule IP Virtual Server Version 1.2.1 (size=4096) Prot LocalAddress:Port Scheduler Flags-> RemoteAddress:Port Forward Weight ActiveConn InActConnTCP 192.168.91.3 wrr 80 wrr-> 10.0.0.5 wrr 80 Masq 10 11-> 10.0.111 wrr 80 Masq 2 014

Client operation

According to the analysis of the results of the script, the client visits the RS2 once, and then visits the RS1 twice, thus iterating. It is proved that the load balancing mode of the weighted polling scheduling algorithm is successfully realized.

Test [root@localhost ~] # for i in {1... 10}; do curl 192.168.91.3

Fourth, the problems needing attention in the experiment

1. According to the real environment, VIP is a public network address, and RIP should be a private address, so as to hide the server. Therefore, in the virtual machine experiment, it is best to set VIP to bridging mode and RID to host-only mode.

The gateway of the 2.RID must point to the DIP of the load balancer, and the RID and DIP are in the same network segment.

3. Load balancer must enable core forwarding function

4. Set up the appropriate firewall rules (or turn it off directly) and turn off selinux.

After reading the above detailed explanation of the load balancing cluster of simulated lvs-nat mode, if you have anything else you need to know, you can find out what you are interested in in the industry information or find our professional and technical engineers who have more than ten years of experience in the industry.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report