The deployment and application of load balancing LVS-NAT

1. Overview of enterprise cluster applications

(1) The meaning of cluster

1. Cluster, cluster, cluster
2. It is composed of multiple hosts, but it only appears as a whole externally, and only provides one access entry (domain name and IP address), which is equivalent to a large computer.

(Two), the problem

In Internet applications, as sites have higher and higher requirements for hardware performance, response speed, service stability, and data reliability, a single server can no longer meet the requirements for load balancing and high availability.

(Three), the solution

1. Use expensive minicomputers and mainframes
2. Use multiple relatively inexpensive ordinary servers to build a service cluster

By integrating multiple servers, LVS is used to achieve high availability and load balancing of the servers, and the same IP address provides the same services to the outside world.
A cluster technology commonly used in enterprises-LVS (Linux Virtual Server, Linux Virtual Server)

2. Classification of enterprise clusters

(1) According to the target difference of the cluster, it can be divided into three types

1. Load balancing cluster
2. High-availability cluster
3. High-performance computing cluster

(2) Load Balance Cluster

1、提高应用系统的响应能力、尽可能处理更多的访问请求、减少延迟为目标,获得高并发、高负载(LB)的整体性能

2、LB的负载分配依赖于主节点的分流算法,将来自客户机的访问请求分担给多个服务器节点,从而缓解整个系统的负载

(Three), high availability cluster (High Availability Cluster)

1、提高应用系统的可靠性、尽可能地减少中断时间为目标,确保服务的连续性,达到高可用(HA) 的容错效果

2、HA的工作方式包括双工和主从两种模式,双工即所有节点同时在线;主从则只有主节点在线,但当出现故障时从节点能自动切换为主节点。
例如:“故障切换”、“双机热备” 

(4) High Performance Computer Cluster (High Performance Computer Cluster)

1、以提高应用系统的CPU运算速度、扩展硬件资源和分析能力为目标,获得相当于大型、超级计算机的高性能运算(HPC)能力

2、高性能依赖于"分布式运算”、“并行计算”  通过专用硬件和软件将多个服务器的CPU、内存等资源整合在一起,实现只有大型、超级计算机才具备的计算能力

Three, load balancing cluster architecture

(1) The structure of load balancing

At the first level, the load scheduler (Load Balancer or Director)
accesses the unique entrance of the entire cluster system, and uses the VIP address shared by all servers externally, which is also called the cluster IP address. Usually two schedulers, the main and the backup, are configured to achieve hot backup. When the main scheduler fails, it can be smoothly replaced to the backup scheduler to ensure high availability.
The second layer,
the application services provided by the server pool (Server Pool) cluster are borne by the server pool, where each node has an independent RIP address (real IP), and only processes client requests distributed by the scheduler. When a node fails temporarily, the fault-tolerant mechanism of the load scheduler will isolate it and wait for the error to be eliminated before re-entering it into the server pool.
The third layer, Shared Storage
provides stable and consistent file access services for all nodes in the server pool, ensuring the unity of the entire cluster. Shared storage can use NAS devices or provide dedicated servers for NFS sharing services.

Four, load balancing cluster working mode analysis

1、负载均衡群集是目前企业用得最多的群集类型
2、群集的负载调度技术有3种工作模式
●地址转换(NAT模式)
●IP隧道(TUN模式)
●直接路由(DR模式)

Five, three load scheduling working modes

(1) NAT mode

1. Address translation
● Network Address Translation, referred to as NAT mode
● A private network structure similar to a firewall, the load scheduler serves as the gateway of all server nodes, that is, as the access entrance of the client, and also the access exit of each node in response to the client
● Server The node uses a private IP address and is located on the same physical network as the load scheduler. The security is better than the other two methods

(Two), TUN mode

1. IP tunnel
● IP Tunnel, referred to as TUN mode
● Adopting an open network structure, the load scheduler only serves as the client's access entrance, and each node directly responds to the client through its own Internet connection, instead of passing through the load scheduler
● The server nodes are scattered in different locations in the Internet, have independent public IP addresses, and communicate with the load scheduler through a dedicated IP tunnel

(Three), DR mode

1. Direct routing
● Direct Routing, referred to as DR mode
● It adopts a semi-open network structure, which is similar to the structure of TUN mode, but the nodes are not scattered in various places, but are located on the same physical network as the
scheduler ● Load scheduler Connect with each node server through the local network, no need to establish a dedicated IP tunnel

Six, about LVS virtual server

(一)、Linux Virtual Server

 针对Linux内核开发的负载均衡解决方案
 19985月,由我国的章文嵩博士创建
 官方网站: http://www.linuxvirtualserver.orgl
 LVS 实际上相当于基于IP地址的虚拟化应用, 为基于IP地址和内容请求分发的负载均衡提出了一种高效的解决方法

(2) LVS has now become a part of the Linux kernel, compiled as an ip_ vs module by default, and can be called automatically when necessary. In the CentOS 7 system, the following operations can manually load the ip_ vs module and view the version information of the ip_ vs module in the current system.

modprobe ip_vs
cat /proc/net/ip_vs    #确认内核对LVS的支持

(Three), LVS load scheduling algorithm

1. Round Robin
● Distribute the received access requests to each node (real server) in the cluster in turn, and treat each server equally, regardless of the actual number of connections and system load of the server

2. Weighted Round Robin
● Distribute requests according to the weight value set by the scheduler. Nodes with higher weight value will get the task first, and the more requests will be allocated.
● Ensure that the server with strong performance bears more access traffic

3. Least Connections
● Allocate according to the number of connections established by the real server, and prioritize the received access requests to the node with the least number of connections

4. Weighted least connections (Weighted East Connections)
● When the performance difference of server nodes is large, the weight can be automatically adjusted for the real server
● Nodes with higher performance will bear a larger proportion of the active connection load

Seven, LVS cluster creation and management

(1) Steps

1. Create a virtual server
2. Add and delete server nodes
3. View the cluster and node status
4. Save the load distribution strategy

(2) Description of ipvsadm tool options

-A	添加虚拟服务器
-D	删除整个虚拟服务器
-s	指定负载调度算法 (轮询::rr、加权轮询: wrr、最少连接: lc、加权最少连接: wlc )
-a	表示添加真实服务器 (节点服务器)
-d	删除某一个节点
-t	指定 VIP地址及 TCP端口
-r	指定 RIP地址及 TCP端口
-m	表示使用 NAT群集模式.
-g	表示使用 DR模式
-i	表示使用 TUN模式
-w	设置权重 (权重为 0 时表示暂停节点)
-p 60	表示保持长连接60
-l	列表查看 LVS 虚拟服务器 (默认为查看所有)
-n	以数字形式显示地址、端口等信息,常与 “-l” 选项组合使用。ipvsadm -ln

(3) Actual case

Environment: LVS scheduler serves as the gateway of the Web server pool. LVS has two network cards, which are connected to the internal and external networks respectively, and use the round-robin (rr) scheduling algorithm.
--------------NAT mode LVS load balancing cluster deployment --------------
LVS load scheduler (centos7-4): ens33: 192.168.220.6 ens36: 12.0.0.1
NFS server (centos7-5): 192.168.220.7
Web node server 1 (centos7-6): 192.168.220.8
Web node server 2 (centos7-7): 192.168.220.9
client (Window10): 12.0. 0.12

1. Deploy shared storage (NFS server: 192.168.200.7)

Insert picture description here
Insert picture description here

Insert picture description here
Insert picture description here

2. Configure the node server (centos7-6: 192.168.220.8, centos7-7: 192.168.220.9)

centos6 :
Insert picture description here
Insert picture description here
Insert picture description here
centos7 :
Insert picture description here
Insert picture description here

3. Configure the load scheduler (ens33: 192.168.220.6 ens36: 12.0.0.1)

Insert picture description here
Insert picture description here
Insert picture description here
Insert picture description here
Insert picture description here
Insert picture description here
Insert picture description here
Insert picture description here

4. Test results

Use a browser to visit http://12.0.0.1/ on a client with an IP of 12.0.0.12, and constantly refresh the browser to test the load balancing effect. The refresh interval needs to be longer.

显示的内容则为“hi pyy”与“hi ppp”
也就是共享目录里边的HTML里的内容

Guess you like

Origin blog.csdn.net/Pyy0928/article/details/112849407