summary

Type of cluster :
Whatever kind of server , Both include at least two node servers , And the external performance as a whole , Only one access portal is provided ( Domain name or IP Address ), It's like a mainframe computer . Depending on the target of the cluster , It can be divided into the following three types :
1. Load balancing (Load Balancer) to cluster around
In order to improve the response ability of the application system . Handle as many access requests as possible . The goal is to reduce delay , Get high concurrency , High load (LB) Overall performance of , for example "DNS polling "、" Application layer switching "," Reverse proxy " Can be used as load balancing cluster .LB The load distribution depends on the shunting algorithm of the master node to share the access requests from clients to multiple server nodes , So as to relieve the load pressure of the whole system .
2. High availability (High Available) to cluster around
In order to improve the reliability of the application system , The goal is to minimize interruption time , Ensure continuity of service , To achieve high availability (HA) Fault tolerant effect of , for example " Fail over "," hot standby "," Multi machine hot standby " And so on belong to high availability cluster technology .HA The ways in which they work include duplex , Master and slave modes —— Duplex means that all nodes are online at the same time , Only the master node is online , But when there is a failure, the slave node can automatically switch to the master node .
3. High Performance Computing (High Performance Computer) to cluster around
In order to improve the efficiency of the application system CP speed , Expand hardware resources and analysis capabilities for the goal of obtaining the equivalent of large , High performance computing in supercomputers (HPC) Ability , for example “ Cloud computing ”,“ Grid computing ” It can also be regarded as a kind of high performance computing .HPC Its high performance depends on , Distributed computing ” Parallel computing “, Through dedicated hardware and software, multiple servers will be CPU, Memory and other resources are integrated to achieve only large , The computing power of supercomputers .

A hierarchical structure for load balancing :

first floor , Load scheduler : This is the entrance to the whole cluster system , Common for external use VIP(Virtual IP, fictitious IP) Address , Also known as clustering IP Address ;

The second floor , The server pool : The application services provided by the cluster are undertaken by the server pool , Each of these nodes has its own RIP( real IP) Address , Only handle client requests distributed by the scheduler ;

The third level , Shared memory : Provide stability for all nodes in the server pool 、 Consistent file access service , Ensure the consistency of the entire cluster ;

Working mode of load balancing :

About the load scheduling technology of cluster , Can be based on IP port , Content, etc , Based on IP Load scheduling is the most efficient . be based on IP In the load balancing mode of , The common ones are address translation ,IP Tunnel 、 There are three working modes of direct routing :
1. address translation (Netwo Out AddressTranslat used n): abbreviation NAT Pattern , A private network structure similar to a firewall , The load scheduler acts as a gateway to all server nodes , That is, as the access portal of the client , It is also the access exit for each node to respond to the client . The server node uses private IP Address , On the same physical network as the load scheduler , Security is better than the other two .

2.IP Tunnel (IPTunnel): abbreviation TUN Pattern , Adopt an open network structure , The load scheduler serves only as the access portal for the client , Each node through its own Internet Connect to the direct response client , Instead of going through the load scheduler . Server nodes are scattered in different locations in the Internet , It has an independent public network IP Address , Through dedicated IP The tunnel communicates with the load scheduler .
3. Direct routing (DirectRout used g); abbreviation DR Pattern , Adopt semi open network structure , And TUN The structure of the pattern is similar to , But the nodes are not scattered all over the place , It's on the same physical network as the scheduler . The load scheduler is connected to each node server through the local network , There is no need to create a dedicated IP Tunnel .

In the above three working modes ,NAT It only needs a public network IP Address , So it becomes the most easy to use load balancing mode , The security is also better , Many hardware load balancing devices use this method ; By comparison ,DR Patterns and TN Patterns are more powerful 、 It's more applicable , But the security of nodes is a little bit worse .

LVS Load scheduling algorithm of :

LVS The scheduler provides a variety of different load scheduling algorithms, among which the four most commonly used algorithms include :

1. Between wheels (Round Robin): The received access requests are assigned to each node in the cluster in turn ( Real server ) Treat each server equally , Regardless of the server's actual number of connections and system load .
2. Weighted polling (Weghted Round Robin): The received access requests are allocated in turn according to the processing capacity of the real server , The scheduler can automatically check the load of each node , And dynamically adjust its weight . This can ensure that the server with strong processing capacity can bear more access traffic .
3. The minimum connection (Least Connections): Allocate according to the number of connections established by the real server , Assign the received access request to the node with the least number of connections first . If the performance of all server nodes is similar , In this way, the load can be better balanced .
4. Weighted least connected (Weighted Least Connections); When the performance of server nodes varies greatly , You can automatically adjust weights for real servers , The nodes with higher weight will bear a larger proportion of the active connection load .
LVS The usage of load balancing is flexible , It can be applied to Web,FTP,DHCP,DNS And so on .

ipvsadm Tool use

LVS Now it has become Linux Part of the kernel , The default compilation is ip_vs modular , You can use ipvsadm Tool management LVS to cluster around

1. load ip_vs modular

[root@LVS ~]# modprobe ip_vs // Load module 
[root@LVS ~]# lsmod | grep ip_vs // Check the status
ip_vs
libcrc32c ip_vs
ipv6 ip_vs,ip6t_REJECT,nf_conntrack_ipv6,nf_defrag_ipv6
2. install ipvsadm Tools
[root@LVS ~]# rpm -ivh /mnt/Packages/ipvsadm-1.25-.el6.i686.rpm <==rpm Package installation method 
[root@LVS ~]# yum -y install ipvsadm <==yum Installation method
[root@LVS ~]# ipvsadm -v <== see ipvsadm edition

3. Use

1) Create a virtual server

[root@LVS ~]# ipvsadm -A -t 172.16.1.128: -s rr

Parameters, :
-A  Indicates the addition of a virtual server
-t   Used to specify VIP Address and TCP port
-s   Used to specify the load scheduling algorithm —— polling (rr), Weighted polling (wrr), The minimum connection (lc), Weighted least connected (wlc)

2) Add server nodes

[root@LVS ~]# ipvsadm -a -t 172.16.1.128: -r 192.168.1.1: -m -w
[root@LVS ~]# ipvsadm -a -t 172.16.1.128: -r 192.168.1.2: -m -w

Parameters, :
-a   Represents adding a real server
-t    Used to specify VIP Address and TCP port
-r    Used to specify RIP Address and TCP port
-m  Said the use of NAT Cluster mode (-g DR Pattern ,-i TUN Pattern )
-W  Used to set weights ( The weight of 0 Represents a pause node )

3) View cluster node status

[root@LVS ~]# ipvsadm -L -n <== View node status 
IP Virtual Server version 1.2. (size=)
Prot LocalAddress:Port Scheduler Flags
-> RemoteAddress:Port Forward Weight ActiveConn InActConn
TCP 172.16.1.128: rr
-> 192.168.1.1: Masq
-> 192.168.1.2: Masq
#Forward The column corresponds to Masquerade( Address camouflage ), The cluster mode is NAT, If it is Route The cluster mode is DR.
[root@LVS ~]# ipvsadm -Lnc <== Check load connections
IPVS connection entries
pro expire state source virtual destination
TCP : FIN_WAIT 172.16.1.33: 172.16.1.128: 192.168.1.1:
TCP : FIN_WAIT 172.16.1.33: 172.16.1.128: 192.168.1.2:

4) Delete server node

[root@LVS ~]# ipvsadm -d -r 192.168.1.2: -t 172.16.1.128:

5) Delete this virtual server

[root@LVS ~]# ipvsadm -D -t 172.16.1.128:
-A -t 172.16.1.128: -s rr
-a -t 172.16.1.128: -r 192.168.1.1: -m -w
-a -t 172.16.1.128: -r 192.168.1.2: -m -w

6) Service management

[root@LVS ~]# service ipvsadm stop <== Out of Service 
[root@LVS ~]# service ipvsadm start <== Start the service
[root@LVS ~]# chkconfig ipvsadm on <== Add power on self start

NAT Mode LVS to cluster around

step :

1. To configure IP

Client and Web The server needs to be configured with a gateway

2. To configure LVS The server

1) Turn on LVS The routing and forwarding of the server

[root@LVS ~]# vim /etc/sysctl.conf
net.ipv4.ip_forward =
[root@LVS ~]# sysctl -p

2) For internal Web The server does SNAT transformation

[root@LVS ~]# service iptables start
[root@LVS ~]# iptables -F -t nat
[root@LVS ~]# iptables -F -t mangle
[root@LVS ~]# iptables -F -t raw
[root@LVS ~]# iptables -F -t filter
[root@LVS ~]# iptables -t nat -A POSTROUTING -s 192.168.10.0/ -o eth0 -j SNAT --to-source 1.1.1.1
[root@LVS ~]# service iptables save

3) load ip_vs modular , install ipvsadm Tools

[root@LVS ~]# modprobe ip_vs
[root@LVS ~]# yum -y install ipvsadm

4) Configure load distribution rules

[root@LVS ~]# service ipvsadm stop // Clear the old rules 
[root@LVS ~]# ipvsadm -A -t 1.1.1.1: -s rr
[root@LVS ~]# ipvsadm -a -t 1.1.1.1: -r 192.168.10.100: -m -w
[root@LVS ~]# ipvsadm -a -t 1.1.1.1: -r 192.168.10.200: -m -w
[root@LVS ~]# service ipvsadm save // Preservation rules
[root@LVS ~]# chkconfig --add ipvsadm

5. To configure Web Node server ( various Web The server configuration is the same )

install httpd service , Create a test page , And start the httpd service

[root@Web1 ~]#echo "LVS test 1" > /var/www/html/index.html // first web Server content 
[root@Web2 ~]#echo "LVS test 2" > /var/www/html/index.html // the second web Server content

6. Customer verification

Polling access to two servers web Site , Because the home page is different , So it's easy to see the effect

[root@LVS ~]# ipvsadm -Lnc
IPVS connection entries
pro expire state source virtual destination
TCP : TIME_WAIT 1.1.1.254: 1.1.1.1: 192.168.10.100:
TCP : TIME_WAIT 1.1.1.254: 1.1.1.1: 192.168.10.200:
TCP : TIME_WAIT 1.1.1.254: 1.1.1.1: 192.168.10.200:
TCP : TIME_WAIT 1.1.1.254: 1.1.1.1: 192.168.10.100:
TCP : TIME_WAIT 1.1.1.254: 1.1.1.1: 192.168.10.100:
TCP : TIME_WAIT 1.1.1.254: 1.1.1.1: 192.168.10.200:80
.....

DR Mode LVS to cluster around

1. To configure IP Address

A little

2. To configure LVS The server ( Turn off firewall )

1) To configure VIP

[root@LVS ~]# cd /etc/sysconfig/network-scripts/
[root@LVS network-scripts]# cp ifcfg-eth0 ifcfg-eth0:
[root@aery network-scripts]# vim ifcfg-eth0:
# It is amended as follows :
DEVICE=eth0:
ONBOOT=yes
IPADDR=192.168.10.1
NETMASK=255.255.255.0
[root@LVS ~]# ifconfig eth0:
eth0: Link encap:Ethernet HWaddr :0C::::8F
inet addr:192.168.10.1 Bcast:192.168.10.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU: Metric:

2) Configure response parameters ( Turn off redirection , No jump , Increase the corresponding speed )

[root@LVS ~]# vim /etc/sysctl.con
add to :
net.ipv4.conf.all.send_redirects =
net.ipv4.conf.default.send_redirects =
net.ipv4.conf.eth0.send_redirects =
[root@LVS ~]# sysctl -p

3) Install and configure ipvsadm

[root@LVS ~]# yum -y install ipvsadm
[root@LVS ~]# modprobe ip_vs
[root@LVS ~]# service ipvsadm stop
[root@LVS ~]# ipvsadm -A -t 192.168.10.1: -s rr
[root@LVS ~]# ipvsadm -a -t 192.168.10.1: -r 192.168.10.100: -g -w
[root@LVS ~]# ipvsadm -a -t 192.168.10.1: -r 192.168.10.200: -g -w
[root@LVS ~]# service ipvsadm save
[root@LVS ~]# chkconfig --add ipvsadm
[root@LVS ~]# chkconfig ipvsadm on

3. To configure Web Node server ( various Web The server configuration is the same )

1) To configure VIP

[root@Web ~]# cd /etc/sysconfig/network-scripts/
[root@Web network-scripts]# cp ifcfg-lo ifcfg-lo:
[root@Web network-scripts]# vim ifcfg-lo:
# It is amended as follows :
DEVICE=lo:
IPADDR=192.168.10.1 // Cluster address
NETMASK=255.255.255.255 // The subnet mask must be all 1
ONBOOT=yes
[root@Web network-scripts]# ifdown lo:
[root@Web network-scripts]# ifup lo:
[root@Web ~]# ifconfig lo:
lo: Link encap:Local Loopback
inet addr:192.168.10.1 Mask:255.255.255.255
UP LOOPBACK RUNNING MTU: Metric:
[root@Web network-scripts]# route add -host 192.168.10.1 dev lo: // add to VIP Local access routing
[root@Web ~]# vim /etc/rc.local // Add to file , Power on automatic execution
add to :
route add -host 192.168.10.1 dev lo: // add to VIP Local access routing

2) adjustment /proc Parameters ( Use unicast access , Increase the corresponding speed )

[root@localhost ]# vim /etc/sysctl.conf
add to :
net.ipv4.conf.all.arp_ignore =
net.ipv4.conf.all.arp_announce =
net.ipv4.conf.default.arp_ignore =
net.ipv4.conf.default.arp_announce =
net.ipv4.conf.lo.arp_ignore =
net.ipv4.conf.lo.arp_announce =
[root@localhost ]# sysctl -p

3) install httpd service , Create a test page , And start the httpd service

[root@Web1 ~]#echo "LVS test 1" > /var/www/html/index.html // first web Server content 
[root@Web2 ~]#echo "LVS test 2" > /var/www/html/index.html // the second web Server content

4. Customer verification

Polling access to two servers web Site , Because the home page is different , So it's easy to see the effect

LVS More articles on load balancing clustering

  1. build Lvs Load balancing cluster

    One .Lvs Detailed explanation lvs Kernel model 1. model analysis The data accessed by the user can enter the scheduler Match the virtual... Assigned by the scheduler IP|IP+ port ( Routing direction ) Determine the matching server according to the scheduler's algorithm 2. Scheduling conditions : be based on IP. Based on the port . Based on the inside ...

  2. LVS Load balancing cluster (NAT)

    ---- structure NAT Mode LVS to cluster around ----------client---------------LVS----------------WEB1-----------WEB2------------NF ...

  3. High performance Linux The server The first 11 Chapter Build highly available LVS Load balancing cluster

    High performance Linux The server The first 11 Chapter Build highly available LVS Load balancing cluster libnet software package <- rely on -heartbeat( contain ldirectord plug-in unit ( need perl-MailTools Of rpm package )) l ...

  4. Implementation is based on LVS E-commerce website architecture of load balancing cluster

    background In the last issue, we set up the Xiaomi website , As the business grows , More and more visits to the website , Website visits have gone from the original 1000QPS, Turn into 3000QPS, The website has been overwhelmed , Slow response , Facing this scene , It's just a single machine LNMP It's impossible to ...

  5. Project details 2—LVS Load balancing details

    One . Introduction to load balancing cluster 1. colony ①  colony (cluster) Technology is a relatively new technology , Through cluster technology , Can be achieved at a lower cost in the case of performance . reliability . Relatively high benefits in terms of flexibility , Its task scheduling is the core technology in cluster system ...

  6. Linux in keepalived+LVS Load balancing build test

    1.1 LVS brief introduction       LVS(Linux Virtual Server), That is to say Linux Virtual server , A free software project . Use LVS The goal of technology is : adopt LVS Load balancing technology and Lin ...

  7. Load balancing cluster LB

    Load balancing cluster is the most commonly used cluster type in enterprises , Through the master node load scheduler (Director), Using a specific streaming algorithm , Sharing access requests from clients to multiple server nodes for common processing , So as to relieve the load pressure of the whole system , Respond to more requests : Group ...

  8. structure LVS Load balancing cluster ——NAT Pattern ( The easiest way )

    One . Equipped with a lvs The scheduler host requires two network cards, one for internal LAN ip, One is the public network ip #IP The address setting process is not repeated [root@localhost ~]# ip a | grep eth0 # Intranet ip : et ...

  9. LVS Summary of load balancing theory and algorithm

    One . LVS brief introduction LVS yes Linux Virtual Server For short , That is to say Linux Virtual server , Free software project initiated by Dr. Zhang wensong , Its official website is www.linuxvirtualserver.or ...

Random recommendation

  1. Vesions ignore &amp; ld: library not found for -l...

    1. Recursively delete... In the specified directory .git..svn file find . -name .git | xargs rm -fr find . -name .svn | xargs rm -rf The first one is not often used ...

  2. controller,link,compile Different

    Test cases .directive('testDirective', function() { return { restrict: 'E', template: '<p>Hello {{nu ...

  3. Distributed database Cobar

    Cobar brief introduction : Cobar It is a distributed processing system of relational database , It can look like a traditional database to provide you with massive data services in a distributed environment . Products in Alibaba B2B The company has been running steadily 3 In the above . It's taken over now 3000 ...

  4. Vim The solution of copy paste format disorder

    occasionally , Copy text ( Especially the code ) To Vim, There will be a problem of disordered format . it seems , It should be the automatic indent that caused the disaster . This article does not go deep into the reasons , Give the solution directly . 1. paste Pattern Run the following command , Get into paste Pattern : :s ...

  5. Book one :lesson forty five.

    original text : The boss's letter. A:Can you come here a minute please,Bob? B:Yes,sir. A:Where is C? B:She is ne ...

  6. Item 22: When using Pimpl Mechanism , The implementation of special member function is given in the implementation file

    This article is translated from <effective modern C++>, Due to limited level , Therefore, there is no guarantee that the translation is completely correct , Welcome to point out the mistakes . thank you ! Blog has moved here If you've ever struggled with too much compile time , So you must be right Pi ...

  7. Spring Of Log4J Configurator Log4jWebConfigurer Introduce

    1. Logj4 brief introduction Log4j yes Apache It's a subproject of the company , It can be used to redirect the output stream of the application log file , Whether we want to export the log file to the console or the network or other places , Both can pass logj4 To configure the , If our application ...

  8. webgl opengl Tutorial samples

    webgl2 Examples : http://webglsamples.org opengl course : https://learnopengl.com/ http://www.opengl-tutorial.org/ ...

  9. iOS Coding specification reference

    Catalog      notes 1.1  Multiline comment 1.2  Single-line comments 1.3  Comments on functions   name 2.1  Name of constant 2.2  Function name 2.3  Variable name 2.3.1  Member variables 2.3.2  Male ...

  10. Use... On touch screen devices html5 Cut the picture ( turn )

    Preface Now touch screen devices are more and more popular , And most of them have supported html5 了 . For this purpose , Develop image clipping function for touch screen devices , So that it can directly process images , Reduce the server pressure . Technical point Browsers must support html5, Include fileReader, ...