{"id":9164,"date":"2024-05-10T09:01:01","date_gmt":"2024-05-10T01:01:01","guid":{"rendered":""},"modified":"2024-05-10T09:01:01","modified_gmt":"2024-05-10T01:01:01","slug":"\u4e92\u8054\u7f51\u5927\u5382\u6280\u672f-Nginx-\u8d1f\u8f7d\u5747\u8861\u63a2\u6d3bmax_fails\u548cfail_timeout\u7684\u8bbe\u7f6e\u3001\u6839\u636e\u53c2\u6570\u8f6c\u53d1upstream","status":"publish","type":"post","link":"https:\/\/mushiming.com\/9164.html","title":{"rendered":"\u4e92\u8054\u7f51\u5927\u5382\u6280\u672f-Nginx-\u8d1f\u8f7d\u5747\u8861\u63a2\u6d3bmax_fails\u548cfail_timeout\u7684\u8bbe\u7f6e\u3001\u6839\u636e\u53c2\u6570\u8f6c\u53d1upstream"},"content":{"rendered":"
\u76ee\u5f55<\/strong><\/p>\n \u4e00\u3001max_fails\u548cfail_timeout\u7684\u8bbe\u7f6e<\/p>\n \u4e8c\u3001max_fails \u548c fail_timeout \u7684\u529f\u80fd\u8be6\u89e3<\/p>\n \u4e09\u3001max_fails \u673a\u5236 \u548c \u4e3b\u52a8\u5065\u5eb7\u68c0\u67e5 \u673a\u5236\u9700\u8981\u5171\u5b58\u7684\u539f\u56e0<\/p>\n \u4e00\u3001max_fails\u548cfail_timeout\u7684\u8bbe\u7f6e<\/p>\n Nginx\u8d1f\u8f7d\u5747\u8861max_fails\u548cfail_timeout\u7684\u8bbe\u7f6e\u4f5c\u7528,\u76f4\u63a5\u8d34\u914d\u7f6e\u4e0a\uff0c\u770b\u5e72\u8d27<\/p>\n \u8fd9\u91cc\u4f1a\u628a header\u4e2d param_key \u8fd9\u4e2a\u53c2\u6570\u62ff\u51fa\u6765\u8ddf$pool \u4e2d\u8bbe\u7f6e\u7684header_param_key\u7684key\u8fdb\u884c\u6bd4\u8f83\uff0c\u547d\u4e2d\u7684\u5982\uff1aheader_param_key_3 \u4f1a\u8f6c\u53d1\u5230loadbalance_1\uff0c\u6ca1\u6709\u547d\u4e2d\u7684\u4f1a\u8f6c\u53d1\u5230\u9ed8\u8ba4loadbalance_2\uff1b<\/p>\n weight=8 max_fails=1 fail_timeout=30s;<\/span><\/p>\n weight \u4f5c\u7528\uff1a\u6d41\u91cf\u5207\u5272<\/span><\/p>\n max_fails=1 fail_timeout=30s; \u8f6c\u53d1\u7ed9\u540e\u7aef\u670d\u52a1\u65f6\uff0c\u82e5\u53d1\u73b0\u540e\u7aef\u670d\u52a1\u6545\u969c\uff0c\u5219\u5c06\u8bf7\u6c42\u8f6c\u53d1\u7ed9\u5176\u4ed6\u8282\u70b9\u8fdb\u884c\u5904\u7406\uff0c\u5e76\u5c06\u670d\u52a1\u5668\u6807\u8bb0\u4e3a\u6545\u969c\u3001\u572830s\u65f6\u95f4\u5185\u4e0d\u518d\u8f6c\u53d1\u7ed9\u6545\u969c\u670d\u52a1\u5668\u300230s\u540e\u91cd\u8bd5\u8f6c\u53d1\u7ed9\u6545\u969c\u670d\u52a1\u5668\uff0c\u82e5\u4ecd\u65e7\u4e0d\u6210\u529f\u5219\u91cd\u590d\u521a\u624d\u7684\u64cd\u4f5c\uff1b<\/span><\/p>\n \u6574\u4f53\u6765\u770b\u4e0d\u5f71\u54cd\u8bd5\u9519\u7684\u8bf7\u6c42\uff1b<\/p>\n<\/p>\n Nginx \u7684 upstream \u6a21\u5757\u4f1a\u5b9e\u73b0\u6240\u8c13\u7684\u88ab\u52a8\u5065\u5eb7\u68c0\u67e5\uff0c\u4e5f\u5c31\u662f\u5229\u7528 max_fails \u673a\u5236\u6765\u5b9e\u73b0\uff0c\u5982\u679c\u8bf7\u6c42\u540e\u7aef upstream peer\u51fa\u73b0\u4e00\u4e9b\u9519\u8bef\uff0c\u5f53\u9519\u8bef\u7684\u7d2f\u8ba1\u6b21\u6570\u8fbe\u5230 max_fails\uff0c\u90a3\u4e48\u8be5 upstream peer \u4f1a\u88ab Nginx \u6458\u6389 fail_timeout \u65f6\u95f4\uff0c\u5728\u8fd9\u4e2a\u65f6\u95f4\u5185\uff0c\u8fd9\u4e2a upstream peer \u8282\u70b9\u7981\u6b62\u5bf9\u5916\u63d0\u4f9b\u670d\u52a1\u3002<\/p>\n \u9700\u8981\u91cd\u70b9\u6ce8\u610f\u7684\u662f fails \u662f\u4e00\u4e2a\u533a\u95f4\u5185\u5931\u8d25\u7684\u7d2f\u52a0\u503c\uff0c\u4e5f\u5c31\u662f\u5728 fail_timeout \u7684\u8fd9\u4e2a\u65f6\u95f4\u533a\u95f4\u5185\uff0c\u4e24\u4e2a\u9519\u8bef\u4e4b\u95f4\u5373\u4f7f\u6709\u6210\u529f\u7684\u8bf7\u6c42\uff0cfails \u4e5f\u4f9d\u7136\u4f1a\u8fdb\u884c\u7d2f\u52a0\u8ba1\u7b97<\/strong>\u3002\u66f4\u4e3a\u7cbe\u786e\u7684\u8868\u8ff0\u8fd9\u4e2a\u529f\u80fd\u7ec6\u8282\u5982\u4e0b\uff1a<\/p>\n \u5982\u679c\u5728 T0 \u65f6\u523b\u51fa\u73b0\u4e86\u4e00\u4e2a\u9519\u8bef\uff0c\u90a3\u4e48 fails = 1\uff1b<\/p>\n<\/li>\n \u5728 T0 ~ T0 + fail_timeout \u7684\u65f6\u95f4\u533a\u95f4\u5185\uff1a<\/p>\n \u5982\u679c\u6ca1\u6709\u51fa\u73b0\u9519\u8bef\uff0c\u90a3\u4e48 fails \u4f1a\u91cd\u7f6e\u4e3a 0\uff1b<\/p>\n<\/li>\n \u5982\u679c\u51fa\u73b0\u4e86\u4e00\u4e2a\u65b0\u9519\u8bef\uff0c\u6bd4\u5982\u5728 T1 \u65f6\u523b\u51fa\u73b0\u4e00\u4e2a\u65b0\u7684\u9519\u8bef\uff0c\u90a3\u4e48 fails \u4f1a\u7ee7\u7eed\u7d2f\u52a0\uff0cfails = 2<\/p>\n<\/li>\n<\/ol>\n<\/li>\n \u63a5\u7740\u4f1a\u91cd\u65b0\u4ee5\u65b0\u7684\u65f6\u95f4\u533a\u95f4 T1 ~ T1 + fail_timeout \u5f00\u59cb\u7edf\u8ba1\u4f46\u662f fails \u503c\u5374\u662f\u7ee7\u7eed\u7d2f\u52a0\uff0c\u5982\u679c\u8fd9\u4e2a\u65f6\u95f4\u533a\u95f4\u53c8\u6709\u4e00\u4e2a\u65b0\u7684\u9519\u8bef\uff0c\u90a3\u4e48 fails = 3<\/p>\n<\/li>\n \u76f4\u5230 T2 \u65f6\u523b\uff0c\u51fa\u73b0\u4e86\u65b0\u7684\u9519\u8bef\u5e76 fails >= max_fails\uff0c\u90a3\u4e48 peer \u8282\u70b9\u4f1a\u88ab\u6458\u9664\uff0c\u5728 T2 ~ T2 + fail_timeout \u8fd9\u4e2a\u65f6\u95f4\u5185\uff0c\u8282\u70b9\u5c31\u65e0\u6cd5\u5bf9\u5916\u63d0\u4f9b\u670d\u52a1\uff0c\u5e76\u4e14\u91cd\u7f6e fails \u4e3a 0\uff0c\u7136\u540e\u5f00\u542f\u65b0\u7684\u4e00\u8f6e\u68c0\u6d4b<\/p>\n<\/li>\n<\/ol>\n max_fails \u673a\u5236 \u548c \u4e3b\u52a8\u5065\u5eb7\u68c0\u67e5 \u7684\u5904\u7406\u903b\u8f91\u5982\u4e0b\uff1a<\/p>\n max_fails \u662f\u8bbf\u95ee upstream \u7684\u6240\u6709\u63a5\u53e3\u8bf7\u6c42\u9519\u8bef\u90fd\u7b97\uff08\u629b\u5f00 proxy_next_upstream \u6307\u5b9a\u7684\u4e00\u4e9b\u9519\u8bef\u7c7b\u578b\uff09\uff0c\u8fd9\u6837\u7684\u8bdd\uff0c\u5f53 QPS \u5f88\u5927\u7684\u60c5\u51b5\u4e0b\uff0c\u6bd4\u5982 3-5w QPS \uff1b\u90a3\u4e1a\u52a1\u8bbf\u95ee\u8fd9\u4e2a upstream\uff0c\u4e5f\u8bb8\u53ea\u5728 1s \u5185\u5c31\u80fd\u8fbe\u5230 max_fails \u6b21\u6570\uff0c\u7136\u540e\u5c31\u4f1a\u6458\u6389 fail_timeout \u65f6\u95f4\uff0c\u8fd9\u6837\u5c31\u53ef\u4ee5\u5f88\u5feb\u6458\u6389<\/p>\n \u8fd9\u4e2a\u7684\u95ee\u9898\u662f\uff0c\u53ea\u6709\u628a\u6d41\u91cf\u6253\u8fdb\u53bb\uff0c\u624d\u80fd\u77e5\u9053\u662f\u5426\u6709\u5f02\u5e38\uff0c\u8fd9\u4e2a\u5bf9\u4e1a\u52a1\u662f\u6709\u635f\u7684\u3002<\/p>\n<\/li>\n<\/ol>\n<\/li>\n \u4e3b\u52a8\u5065\u5eb7\u68c0\u67e5\uff0c\u662f\u56fa\u5b9a\u9891\u7387\u68c0\u6d4b\u56fa\u5b9a\u63a5\u53e3\uff0c\u6bd4\u5982\u6211\u6bcf\u9694 3s \u68c0\u6d4b\u4e00\u6b21\uff0c\u7136\u540e\u5931\u8d25 2 \u6b21\u5c31\u8ba4\u4e3a\u8282\u70b9\u4e0d\u53ef\u7528\uff0c\u4f46\u662f\u8fd9\u4e2a\u6700\u957f\u8017\u65f6\u9700\u8981 6s \u624d\u80fd\u6458\u6389<\/p>\n check \u4e3b\u52a8\u68c0\u6d4b\uff0c\u9700\u8981\u957f\u8fbe 6s \u624d\u80fd\u6458\u6389\uff0c\u5728\u9ad8\u5e76\u53d1\u7684\u60c5\u51b5\u4e0b\uff0c\u65e0\u6cd5\u63a5\u53d7\u79d2\u7ea7\u522b\u7684\u5931\u8d25\uff0c\u5f88\u591a\u4e1a\u52a1\u65b9\u4f1a\u654f\u611f\uff0c\u6211\u4eec\u8981\u53bb\u964d\u4f4e\u5f71\u54cd\u9762\uff0cmax_fails \u76f8\u5f53\u4e8e\u589e\u52a0\u4e86\u4e00\u4e2a\u7194\u65ad\u673a\u5236\u3002<\/p>\n<\/li>\n \u8fd9\u4e2a\u7684\u4f18\u52bf\u662f\u63d0\u524d\u68c0\u6d4b\uff0c\u4e0d\u6d89\u53ca\u4e1a\u52a1\u672c\u8eab\u7684\u6d41\u91cf\uff1b\u4f46\u662f\u52a3\u52bf\u662f\u9700\u8981\u4e00\u4e2a\u65f6\u95f4\u8303\u56f4\uff0c\u4e0d\u80fd\u9a6c\u4e0a\u6458\u9664\u3002<\/p>\n<\/li>\n<\/ol>\n<\/li>\n \u5171\u5b58\u5c31\u662f\u4e3a\u4e86\u540c\u65f6\u5de5\u4f5c\uff0c\u4ece\u4e0d\u540c\u7684\u89d2\u5ea6\u6765\u68c0\u6d4b\u5065\u5eb7\u72b6\u6001\uff0c\u4e24\u8005\u7684\u4f18\u52a3\u8fdb\u884c\u4e92\u8865\uff0c\u521a\u597d\u76f8\u4e92\u5f25\u8865\u7f3a\u9677\uff0c\u4ece\u800c\u5c3d\u5feb\u5254\u9664\u6709\u95ee\u9898\u7684\u8282\u70b9\uff0c\u63d0\u9ad8\u670d\u52a1\u8d28\u91cf\u3002<\/p>\n<\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"\u4e92\u8054\u7f51\u5927\u5382\u6280\u672f-Nginx-\u8d1f\u8f7d\u5747\u8861\u63a2\u6d3bmax_fails\u548cfail_timeout\u7684\u8bbe\u7f6e\u3001\u6839\u636e\u53c2\u6570\u8f6c\u53d1upstreammax_fails=1fail_timeout=30s;\u8f6c\u53d1...","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"_links":{"self":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/posts\/9164"}],"collection":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/comments?post=9164"}],"version-history":[{"count":0,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/posts\/9164\/revisions"}],"wp:attachment":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/media?parent=9164"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/categories?post=9164"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/tags?post=9164"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}
\nserver {\nlisten 80;\nserver_name xxxx.ikong.com;\nlocation \/ {\n proxy_pass http:\/\/$pool;\n proxy_set_header Host $host;\n proxy_set_header X-Real-IP $remote_addr;\n proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;\n }\n}\nupstream loadbalance_1 {\n server 192.168.20.216:8080 weight=8 max_fails=1 fail_timeout=30s;\n server 192.168.20.217:8080 weight=1 max_fails=1 fail_timeout=30s;\n server 192.168.20.218:8080 weight=1 max_fails=1 fail_timeout=30s;\n}\n\nupstream loadbalance_2 {\n server 192.168.20.211:8081 weight=3;\n server 192.168.20.212:8081 weight=3;\n server 192.168.20.213:8089 weight=2;\n server 192.168.20.214:8089 weight=2;\n}\n\nmap $http_header_param_key $pool {\n default \"loadbalance_2\";\n header_param_key_3 \"loadbalance_1\";\n header_param_key_1 \"loadbalance_1\";\n header_param_key_2 \"loadbalance_1\";\n}<\/code><\/pre>\n<\/p>\n
\u4e8c\u3001max_fails \u548c fail_timeout \u7684\u529f\u80fd\u8be6\u89e3<\/h3>\n
\n
\n
\u4e09\u3001max_fails \u673a\u5236 \u548c \u4e3b\u52a8\u5065\u5eb7\u68c0\u67e5 \u673a\u5236\u9700\u8981\u5171\u5b58\u7684\u539f\u56e0<\/h3>\n
\n
\n
\n