1, Meaning of cluster
Cluster, also known as cluster and cluster, is composed of multiple hosts, but it is still a whole. It only provides an access portal (domain name or IP address), which is equivalent to a mainframe computer.
Problem: in practical application, as the site has higher and higher requirements for performance, response speed, data reliability and server stability, a single server has been unable to meet the requirements of load balancing and high availability.
Solutions: 1. Use expensive minicomputers and mainframes to improve hardware performance.
2. Use multiple relatively cheap ordinary servers to build service clusters.
2, Classification of clusters
1. According to the differences targeted by clusters, clusters can be divided into three categories
1. Load balancing cluster
2. High availability cluster
3. High performance computing cluster
Load balancing cluster: improve the corresponding capacity of the application system, handle more access requests as much as possible and reduce latency, so as to obtain the overall performance of high concurrency and high load (LB). The load distribution of LB depends on the shunting algorithm of the master node, which shares the access requests from the client to multiple server nodes, so as to reduce the load pressure of the whole system.
High availability cluster: improve the reliability of the application system, reduce interruption events as much as possible, ensure the continuity of services, and achieve the fault-tolerant effect of high availability (HA).
The working mode of HA includes duplex and master-slave. Duplex means that all nodes are online at the same time; The master-slave only has the master node online, but in case of failure, the slave node can automatically switch to the master node.
High performance computing cluster: with the goal of improving the CPU computing speed of the application system, expanding hardware resources and analysis capabilities, obtain high-performance computing (HPC) capabilities equivalent to large-scale and supercomputers.
High performance depends on "distributed computing" and "parallel computing". The CPU, memory and other resources of multiple servers are integrated through special hardware and software to realize the computing power only large and supercomputers have, such as "cloud computing" and "grid computing".
3, Load balancing cluster architecture
Layer 1: Load Balancer
The only entrance to access the whole cluster system, and use the common VIP (virtual IP) address of all servers, also known as the cluster IP address. Two dispatchers, the primary and standby, are usually configured to realize hot backup. When the primary scheduler fails, it can be smoothly replaced with the standby scheduler to ensure high availability.
Layer 2: Server Pool
The application services provided by the cluster are undertaken by the server pool. Each node has an independent RIP address (real IP) and only processes the 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 it is re included in the server pool.
Layer 3: Share Storage
Provide stable and consistent file storage services for all nodes in the server pool to ensure the unity of the whole cluster. Shared storage can use NAS devices or dedicated servers that provide NFS shared services.
4, Working mode of load balancing cluster
Load balancing cluster is the most widely used cluster type in enterprises.
There are three working modes of cluster load scheduling
1. Address translation (NAT)
2. IP tunnel (VPN)
3. Direct routing (DR)
Address translation NAT
Similar to the private network structure of firewall, the load scheduler acts as the gateway of all server nodes, that is, as the access entrance of clients and the access exit of each node in response to clients.
The server node uses a private IP address and is located in the same physical network as the load scheduler. The security is better than the other two methods.
IP tunnel
IP Tunnel, plus TUN mode
The open network structure is adopted, and the load scheduler is only used as the access entrance of the client. Each node directly responds to the client through its own Internet connection, without going through the load scheduler. The feature is that nodes can be scattered everywhere.
Direct routing DR
The semi open network structure is adopted, which is similar to the TUN mode structure, but the nodes are not scattered everywhere, but located in the same physical network as the scheduler.
The load scheduler is connected with each node server through the local network, and there is no need to establish a special IP tunnel.
Difference between NAT mode and DR mode: both NAT and DR will use the scheduler as the client access entry, but the exit when NAT mode responds to the client request is also the scheduler as the exit. DR responds directly to the client without going through the scheduler.
The security of NAT is also higher than that of DR, because NAT will perform a SNAT conversion, while Dr directly responds to the client, and the server address is directly exposed to the client, so the security is a little lower
5, LVS virtual server
LVS is now called part of the Linux kernel and is compiled as IP by default_ Vs module, which can be called automatically when necessary. In the CentOS7 system, you can manually load IP addresses through the following operations:_ Vs module, and view the IP address in the current system_ Version information of vs module.
modprobe ip_vs
cat /proc/net/ip_vs
The load balancing algorithm determines which healthy servers on the back end will be selected. Here are some common algorithms
Load scheduling algorithm of LVS
Polling: distribute the received access requests to the nodes (real servers) in the cluster in turn, and treat each server equally, regardless of the actual number of connections and system load of the server.
Weighted polling: distribute requests according to the weight value set by the scheduler. Nodes with high weight value get tasks first, and the more requests are allocated.
Ensure that servers with strong performance bear more access traffic.
Least connection: allocate according to the number of connections established by the real server, and give priority to the node with the least number of connections
Weighted least link: 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
6, ipvsadm tool
ipvsadm features and options
-A : Add virtual server -D : Delete entire virtual server -s : Specify the load scheduling algorithm (polling): rr,Weighted polling: wrr,Minimum connections: lc,Weighted minimum connection: wlc)> -a : Indicates adding a real server (node server) -d : Delete a node -t : appoint VIP Address and TCP port -r : appoint RIP Address and TCP port -m : Indicates use NAT Cluster Mode -g : Indicates use DR pattern -i : Indicates use TUN pattern -w : Set the weight (when the weight is 0, it means to pause the node) -p 60 : Indicates a long connection for 60 seconds -l : List view LVS Virtual server (view all by default) -n : Display address, port and other information in digital form, often with“-l"Option combination. ipvsadm -ln**
7, NAT for LVS load balancing cluster deployment
Environment preparation: load scheduler: internal gateway: ens33:192.168.73.88, external gateway: ens36:12.0.0.1
Web node server 1: 192.168.73.188
Web node server 2: 192.168.73.166
NFS server: 192.168.73.66
Client: 12.0.0.12
1. Deploy shared storage (NFS server)
systemctl stop firewalld.service systemctl disable firewalld.service setenforce 0 yum -y install nfs-utils rpcbind systemctl start rpcbind.service systemctl start nfs.service systemctl enable nfs.service systemctl enable rpcbind.service mkdir /opt/uzi mkdir /opt/gala echo "My name is uzi" > ./uzi/index.html echo "My name is gala" > ./gala/index.html chmod 777 /opt/uzi chmod 777 /opt/gala vim /etc/exports /opt/uzi 192.168.73.0/24(rw,sync) /opt/gala 192.168.73.0/24(rw,sync) exportfs -rv
2. Configure node servers (192.168.73.166 and 192.168.73.188)
systemctl stop firewalld.service systemctl disable firewalld.service setenforce 0 yum install httpd -y systemctl start httpd.service systemctl enable httpd.service yum -y install nfs-utils rpcbind showmount -e 192.168.73.66 systemctl start rpcbind systemctl enable rpcbind ----192.168.73.188---- mount 192.168.73.66:/opt/uzi /var/www/html/ ----192.168.73.166---- mount 192.168.73.66:/opt/gala /var/www/html/
3. Configure the load scheduler (internal gateway ens33:192.168.73.88, external gateway ens36:12.0.0.1)
systemctl stop firewalld.service systemctl disable firewalld.service setenforce 0 ----to configure SNAT Forwarding rules---- vim /etc/sysctl.conf net.ipv4.ip_forward = 1 iptables -t nat -F iptables -F iptables -t nat -A POSTROUTING -s 192.168.73.0/24 -o ens36 -j SNAT --to-source 12.0.0.1 ----load LVS Kernel module---- modprobe ip_vs #Load ip_vs module cat /proc/net/ip_vs #View ip_vs version information ----install ipvsadm management tool---- yum -y install ipvsadm ----The load distribution policy must be saved before starting the service,Otherwise, the startup fails---- ipvsadm-save > /etc/sysconfig/ipvsadm systemctl start ipvsadm.service Configure load distribution policy( NAT As long as the mode is configured on the server, the node server does not need special configuration) ipvsadm -C #Clear original policy ipvsadm -A -t 12.0.0.1:80 -s rr ipvsadm -a -t 12.0.0.1:80 -r 192.168.73.188:80 -m ipvsadm -a -t 12.0.0.1:80 -r 192.168.73.166:80 -m ipvsadm #Enable policy ipvsadm -ln #Check the node status. Masq represents NAT mode ipvsadm-save > /etc/sysconfig/ipvsadm #Save policy
4. Go to Windows to test