Load balancing and network theory

1, TCP three-way handshake introduce four wave
 
Three-way handshake: the client sends a request to the server, the server receives the request, the client sends ack to confirm receipt of the client, the server sends an acknowledgment to the request packet.
 
 
Four wave:
    Close the client and the server is connected to: the client sends a close request, the server receives ACK back to confirm.
    Shut down the server and client connections: the server to the client initiates closing request, the client ACK reply to confirm.
   
     
 
 

2, the network architecture and 7 layer TCP / IP four-layer model

      
 
    
 

3, HTTP principle

    Http is a stateless protocol, short connection server client and server to establish a response after closed. The default port 80
    1. The address resolution; according to resolve an address request protocol name, host name, the port, the path request, then the DNS parse out according to IP
    2. The above-mentioned information and the HTTP request packet encapsulation parameters,
    3. The encapsulated into TCP packets and establish a connection (three-way handshake)
    4. The transmission request command
    The server response
    6. server closes the TCP connection, if Liu kefuduan Connection: keep-alive, TCP connection remains open after transmission
 
 

4, HTTP status code

400 Bad Request (Request Error)
401 Unauthorized (Unauthorized)
402 Payment Required (payment required)
403 Forbidden (Forbidden)
404 Not Found (not found)
405 Method Not Allowed (not allowed in the process)
406 Not Acceptable (unacceptable)
407 Proxy Authentication Required (Proxy authentication required)
408 Request Timeout (Request Timeout)
500 Internal Server Error (Internal Server Error)
501 Implemented (not implemented)
502 Bad Gateway (Gateway error)
503  Service Unavailable(服务不可用)
504  Gateway Timeout (网关超时)
505  HTTP Version Not Supported(HTTP 版本不受支持)
 

5、HTTPS原理

        HTTPS是以安全为目标的HTTP 通道加入 SSL 层,其所用的端口号是 443
1. 建立连接获取证书:客户端通过 TCP 和服务器建立连接,并且在握手中过程中请求证书。即客户端发出一个消息给服务器,这个消息里面包含了自己可实现的算法列表和其它一些需要的消息,SSL的服务器端会回应一个数据包,这里面确定了这次通信所需要的算法,然后服务器向客户端返回证书。(证书里面包含了服务器信息:域名。申请证书的公司,公共秘钥)。
2.证书验证:Client 在收到服务器返回的证书后,判断签发这个证书的公共签发机构,并使用这个机构的公共秘钥确认签名是否有效,客户端还会确保证书中列出的域名就是它正在连接的域名。
3.数据加密和传输: 如果确认证书有效,那么客服端生成对称秘钥并使用服务器的公共秘钥进行加密。然后发送给服务器,服务器使用它的私钥对它进行解密。
   
    
     
 
 
     
 
 
  
 
 

6、HTTP1.0与HTTP1.1的区别

 
 
         Http1.0问题:链接无法复用,即不支持持久链接。每次连接都要三次握手和慢启动(对网路实际容量进行试探,避免由于发送了过量的数据而导致阻塞)。
    线头阻塞(Head of Line Blocking,HOLB, 请求队列的第一个请求因为服务器正忙(或请求格式问题等其他原因),导致后面的请求被阻塞。
    Http1.1 解决的1.0的问题后,通过header 里Connection: keep-alive,请求管道化,增加缓存。
      未来2.0的趋势,多路复用,头部字节压缩传输。
 

7、CDN介绍

    CDN内容分发系统,能够实时地根据网络流量和各节点的连接、负载状况以及到用户的距离和响应时间等综合信息将用户的请求重新导向离用户最近的服务节点上。其目的是使用户可就近取得所需内容,解决 Internet网络拥挤的状况,提高用户访问网站的响应速度。
    CND一般包含分发服务系统、负载均衡系统和管理系统。
 

8、Nginx 反向代理介绍

        使用代理服务器作用:可以提供访问速度(热点和静态内容缓存);防火墙作用(过滤不安全信息);通过代理访问不能访问的站点;
        反向代理作用:可以防止外网对内网服务器的恶性攻击、缓存以减少服务器的压力和访问安全控制之外,还可以进行负载均衡,将用户请求分配给多个服务器
        Nginx的功能:反向代理、动静分离、负载均衡。
 

9、Nginx负载均衡策略

        轮询:
        权重:
        ip_hash:
        url_hash:
        fair 响应时间短优先分配
        least_conn 最少连接
 

10、Nginx常用配置

        限流:Nginx按请求速率限速模块使用的是漏桶算法。
        limit_req_zone 用来限制单位时间内的请求数,即速率限制
        limit_req_conn 用来限制同一时间连接数,即并发限制
        
  
  
 

11、负载均衡软件介绍

        Nginx/LVS/HAProxy的基于Linux的开源免费的负载均衡软件,
        F5/Array 收费的,F5功能更强大,收费也贵
        Web前端采用Nginx/HAProxy+Keepalived作负载均衡器;后端采用MySQL数据库一主多从和读写分离,采用LVS+Keepalived的架构。
 
        七层负载均衡与四层负载均衡的区别:
        七层负载均衡:工作在应用层,还可以支持四层负载均衡,基于URL等应用层信息的负责均衡,例子:Nginx、HAProxy、MySQL Proxy。七层应用负载,可以动静分离,使网络更智能化。
         四层负载均衡:工作在传输层,基于IP+PORT ,例子:LVS、F5。TCP的建立(三次握手)是客户端与服务端直接建立的,负责均衡设备类似路由器功能,负责寻找最佳服务器,对报文中IP地址修改为后端服务器。
 
 
 
 
 
 
 
 

Guess you like

Origin www.cnblogs.com/a747895159/p/10975325.html