Giter Site home page Giter Site logo

jackyxiong.github.io's People

Contributors

jackyxiong avatar

Watchers

 avatar

jackyxiong.github.io's Issues

网络安全 DDoS资料

Nginx 负载均衡

Web 服务的负载均衡是个老生常谈的话题,也出现了多种实现方案。如硬件层的 F5 ,作用于 OSI 七层模型中第四层的 LVS ,通过对 IP 包的拦截修改和转发,来实现流量分发。这两个方案,F5 是硬件,而 LVS 又是扎根于内核,所以性能和稳定性都极高。

而往上,Nginx 来作负载均衡则是作用于应用层,在这一层可以支持更加细粒度的指标来选择后端源服务,而不只是简单的流量分发了。比如可根据UA的不同、IP 所在地区的不同,以及不同的URL等把流量发送到对应的服务实例上。使用 Nginx 作负载均衡一般与其反向代理的功能同时使用,相比于 LVS 而言,部署简单,功能丰富。

看一个 Nginx 配置文件的实例

upstream backend {
    server backend1.example.com       weight=5;
    server backend2.example.com:8080;
    server unix:/tmp/backend3;

    server backup1.example.com:8080   backup;
    server backup2.example.com:8080   backup;
}

server {
    location / {
        proxy_pass http://backend;
    }
}

weight参数默认为1,值越大,对应服务的权重越高。

    server backend1.example.com       weight=5;
    server backend2.example.com:8080;

像这样的配置,则Nginx会每向 backend1 发送5个请求,就会想 backend2 发送一个请求。

除了weight之外,ip_hash 可根据访问者的IP hash值对应到不同的服务实例,有些情况下可以保证session不丢失。
hash 可设置根据变量、常量或者两者的组合来计算hash值,进而映射到不同的服务。
fair叫做是智能模式,这个模块会根据处理请求的响应时间和响应内容大小,动态调整流量的分配。 但是这个指令是第三方库的功能,不是 Nginx自带的功能,如果要使用,需要将其编译到Nginx内部。

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.