LVS cluster (built in NET mode)

Table of contents

1. Cluster overview

1. Types of load balancing technology

2. Implementation method of load balancing

Two, LVS cluster structure

1. Three-layer structure

Second, the structure of the object

3. LVS working mode

4. LVS load balancing algorithm

1. Static load balancing      

2. Dynamic load balancing

5. Detailed explanation of ipvsadm command

6. Build the experimental process

1. First open three virtual machines

2. The new network card is ens37

3. Enter to view the host IP

 4. Restart the network card to ping Baidu

5. Install epel source and nginx on the second and third machines

 6. Start the service

 7. Verify the listening port

 8. Go back to the first station to open routing and verify

9. Failed to start the service

10. After successful startup

11. Preservation strategy   

12. Verification Results

7. Configuration case flow chart


1. Cluster overview

1. Types of load balancing technology

A four-layer load balancer is also called a four-layer switch. It mainly realizes load balancing based on IP and ports by analyzing the traffic of the IP layer and the TCP/UDP layer, such as common LVS, F5, etc.;

Layer 7 load balancer, also known as layer 7 switch, is located at the highest layer of OSI, that is, the application layer. This load balancer supports multiple protocols, such as HTTP, FTP, SMTP, etc. The Layer 7 load balancer can select the back-end server according to the content of the message and cooperate with a certain load balancing algorithm, that is, the "content switch". Such as common HAProxy, Nginx.

2. Implementation method of load balancing

Hardware load balancing products: F5, Sangfor, Radware

Software load balancing products: LVS (Linux Virtual Server), Haproxy, Nginx, Ats (apache traffic server)

Two, LVS cluster structure

1. Three-layer structure

load scheduler

server pool

server pool

Second, the structure of the object

VS: Virtual Server, also known as Director, load balancing server

RS: Real Server, real server, each node in the cluster

VIP: Director's IP that provides services to the outside world

DIP: Director communicates with RS internally

RIP: the IP of the real server

CIP: Client's IP

3. LVS working mode

LVS-NAT (NAT mode)
LVS-DR (direct routing mode) (most widely used)
LVS-TUN (IP tunnel (Tunnel) mode, not commonly used)
FULL-NAT mode (two-way conversion mode, not commonly used)

4. LVS load balancing algorithm

1. Static load balancing
      

         rr (round robin, polling)
        wrr (weight round robin, weighted round robin)
        sh (source hashing, source address hashing algorithm (HASH))
        dh (destination hashing, destination address HASH)

2. Dynamic load balancing

lc (leash-connection, least connection)
    simple algorithm: active * 256 + inactive (whose choice)
wlc (weighted least connection)
    simple algorithm: (active * 256 + inactive) / weight (whose choice)
sed (minimum expected delay)
    simple algorithm: (active + 1) * 256 / weight (whose choice is who)
nq (never queue, never queue)
LBLC (least connection based on locality)
LBLCR (band replication based on locality ) function's minimum connections)

5. Detailed explanation of ipvsadm command

-A Add virtual service node
-D Delete virtual service node
-L View virtual service node list
-a Add real service node
-d Delete real service node
-l View real service node list
-t Specify virtual server IP address
-s Specify scheduling algorithm
-r specifies the real server node IP address
-w specifies the weight value
-g direct routing mode (default)
-i tunnel mode (not commonly used)
-m NAT mode

6. Build the experimental process

1. First open three virtual machines

NET mode, configure the IP and environment, add a network card to the first virtual machine, and use Vimnat1

And verify ip connectivity

 

 verify

2. The new network card is ens37

 Type win+R 

3. Enter to view the host IP

To change the 37 network card to 150 network segment

enter change

 

 Check

Change the network adapter gateway to 150 segments

 4. Restart the network card to ping Baidu

Install yum -y install ipvsadm

5. Install epel source and nginx on the second and third machines

 

Change the gateway of the second and third machines to the ip of the first machine

vim /etc/sysconfig/network-scripts/ifcfg-ens33

 6. Start the service

 This command will write "nginx1" into the index.html file and overwrite the existing content if index.html exists

 7. Verify the listening port

 

 route -n (the second and third are the same operation)

 8. Go back to the first station to open routing and verify

vim /etc/sysctl.conf

 Load the ip_vs module

modprobe ip_vs

 lsmod |grep ip_vs

 systemctl status ipvsadm

9. Failed to start the service

Missing directories and files

Create a file 

10. After successful startup

 This is a curl command, which is used to access a URL or IP address over the network. In this case, curl is used to access the server at IP address 192.168.115.4.

Access two ip addresses

 

11. Preservation strategy 
  

 ipvsadm-save > /etc/sysconfig/ipvsadm/test1

 

 show result vim ipvsadm.txt

12. Verification Results

Enter IP 192.168.150.100

Refreshing again will switch back and forth

 Then the cluster in LVS NAT mode is created successfully

7. Configuration case flow chart

 

 

 

 

Guess you like

Origin blog.csdn.net/Mapinyi666/article/details/132459053