日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

nginx学习九 upstream 负载均衡

發布時間:2024/1/17 编程问答 36 豆豆
生活随笔 收集整理的這篇文章主要介紹了 nginx学习九 upstream 负载均衡 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

2019獨角獸企業重金招聘Python工程師標準>>>

  • 語法 Syntax: upstream name {...} Default:-- Context:http

    ?

  • 后端服務器在負載均衡調度中的狀態:
    down當前的server暫時不參與負載均衡
    backup預留的備份服務器
    max_fails允許請求失敗的次數
    fail_timeout經過max_fails失敗后,服務暫停的時間
    max_conns限制最大的接收的連接數

    ?

  • ?nginx 的調度算法:
    輪詢?按時間順序逐一分配到不同的后端服務器
    加權輪詢??weight值越大,分配到的訪問幾率越高
    ip_hash每個請求按訪問IP的hash結果分配,這樣來自同一個IP的請求,固定訪問一個
    least_conn最少連接數,哪個機器連接數少就分發
    url_hash按照訪問的URL的hash結果來分配請求,是每個URL定向到同一個后端服務器
    hash關鍵數值hash自定義的key

    ?

  • 例?/etc/nginx/conf.d/default.con server {listen 8001;server_name localhost;#charset koi8-r;access_log /var/log/nginx/server.access.log main;location / {root /opt/app/code1;index index.html index.htm;} ... ... }server {listen 8002;server_name localhost;#charset koi8-r;access_log /var/log/nginx/server.access.log main;location / {root /opt/app/code2;index index.html index.htm;} ... ... }server {listen 8003;server_name localhost;#charset koi8-r;access_log /var/log/nginx/server.access.log main;location / {root /opt/app/code3;index index.html index.htm;} ... ... }server {listen 80;server_name localhost;#charset koi8-r;access_log /var/log/nginx/test_proxy.access.log main;location / {proxy_pass http://test_upstream;} ... ... }##普通輪詢 upstream test_upstream {server localhost:8001;server localhost:8002;server localhost:8003; }

    ?

  • 加權輪詢 upstream test_upstream {server localhost:8001;server localhost:8002 weight=5;server localhost:8003; }

    ?

  • 備份節點? upstream test_upstream {server localhost:8001 down;?server localhost:8002 backup;server localhost:8003 max_fails=1 fail_timeout=10s; }

    ?

  • ip_hash? upstream test_upstream {ip_hash;server localhost:8001; server localhost:8002;server localhost:8003; }

    ?

  • url_hash ?語法(1.7.2版本開始) Syntax: hash key [consistent]; Default: -- Context: upstream ##例: upstream test_upstream {hash $request_uri;server localhost:8001; server localhost:8002;server localhost:8003; } ?

轉載于:https://my.oschina.net/langgege/blog/1930524

總結

以上是生活随笔為你收集整理的nginx学习九 upstream 负载均衡的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。