{"id":438816,"date":"2021-04-18T00:57:58","date_gmt":"2021-04-17T16:57:58","guid":{"rendered":"http:\/\/4563.org\/?p=438816"},"modified":"2021-04-18T00:57:58","modified_gmt":"2021-04-17T16:57:58","slug":"upstream-%e9%85%8d%e7%9a%84-server-%e5%a4%9a%e4%ba%86%e5%90%9e%e5%90%90%e9%87%8f%e5%8f%8d%e8%80%8c%e4%b8%8b%e9%99%8d%e4%b8%a5%e9%87%8d","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=438816","title":{"rendered":"Upstream \u914d\u7684 Server \u591a\u4e86\u541e\u5410\u91cf\u53cd\u800c\u4e0b\u964d\u4e25\u91cd"},"content":{"rendered":"<div>\n<div>\n<div>\n<h1>                  Upstream \u914d\u7684 Server \u591a\u4e86\u541e\u5410\u91cf\u53cd\u800c\u4e0b\u964d\u4e25\u91cd               <\/h1>\n<p> <\/p>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : bantianys <\/span>  <span><i><\/i> 0<\/span> <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div isfirst=\"1\"> <\/p>\n<p>6 \u53f0 Nginx\uff0c\u6bcf\u53f0 Upstream \u4e0a\u914d\u7f6e\u4e86\u76f8\u540c\u7684 30 \u4e2a\u670d\u52a1\u3002\u538b\u6d4b\u65f6\u53d1\u73b0\u538b\u529b\u5206\u53d1\u5230 30 \u4e2a\u670d\u52a1\u7684\u96c6\u7fa4\u8870\u51cf\u4e25\u91cd\u3002 Upstream \u53ea\u914d\u7f6e 2 \u53f0\u65f6\uff0c\u5355\u4e2a\u670d\u52a1\u53ef\u4ee5\u8dd1\u5230 90%\u7684 CPU\uff0c\u6269\u5c55\u540e\u5355\u4e2a\u670d\u52a1\u53ea\u6709 20%\u7684 CPU \u5360\u7528\u3002<\/p>\n<p>\u76ee\u524d\u53d1\u73b0\u5982\u679c\u628a\u8fd9 6 \u53f0 Nginx \u7684 Upstream \u4e0b\u90fd\u914d\u7f6e\u6210\u4e0d\u540c IP \u7684 5 \u4e2a\u670d\u52a1\uff0cNginx \u96c6\u7fa4\u4f9d\u7136\u662f\u53cd\u5411\u4ee3\u7406 30 \u4e2a\u670d\u52a1\uff0c\u6574\u4f53\u541e\u5410\u91cf\u63d0\u5347\u5de8\u5927\u3002\u611f\u89c9\u4e0a\u662f Upstream \u7684 Server \u586b\u591a\u4e86\u4f1a\u5f71\u54cd\u6027\u80fd\u4f3c\u7684\u3002\u8d1f\u8f7d\u5747\u8861\u4ece\u8f6e\u8be2\u5230\u6700\u5c0f\u94fe\u63a5\u90fd\u8bd5\u8fc7\uff0c\u6ca1\u4ec0\u4e48\u6548\u679c\u3002\u611f\u89c9\u662f\u5176\u4ed6\u7684\u914d\u7f6e\u5bfc\u81f4\u7684\u3002<\/p>\n<p>\u6709\u6ca1 Nginx \u5927\u795e\u5e2e\u5fd9\u770b\u4e0b\uff0c\u6700\u53ef\u80fd\u662f\u54ea\u91cc\u51fa\u4e86\u95ee\u9898\u3002<\/p>\n<\/p><\/div>\n<div> <b>\u5927\u4f6c\u6709\u8a71\u8aaa<\/b> (<span>10<\/span>)        <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<ul>\n<li data-pid=\"5751629\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : mongodb <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u6709\u70b9\u6ca1\u770b\u660e\u767d\u3002<\/p>\n<p>\u5982\u679c\u662f\u8bf4 CPU \u5360\u7528\uff0c\u90a3\u5206\u7684\u591a\u4e86 CPU \u4e0b\u964d\u4e0d\u662f\u6b63\u5e38\uff1f<\/p>\n<p>\u4e0d\u662f\u5f88\u660e\u767d\u4f60\u7684\u610f\u601d\u3002                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5751630\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : bantianys <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u5fd8\u8bb0\u8865\u5145\u4e86\u4e00\u70b9\u3002\u56e0\u4e3a\u6784\u9020\u7684\u6d4b\u8bd5\u538b\u529b\u662f\u6309 30 \u53f0\u4f30\u7b97\u540e\u6269\u5c55\u7684\u3002\u6240\u4ee5\u7406\u8bba\u4e0a\u6bcf\u53f0\u670d\u52a1\u7684 CPU \u5360\u7528\u4e0d\u5e94\u8be5\u592a\u4f4e\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5751631\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : bantianys <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             Nginx \u524d\u9762\u662f ELB\uff0c\u53d1\u5f80 ELB \u7684\u538b\u529b\u90fd\u662f\u4e00\u6837\u7684\u30022 \u4e2a\u573a\u666f\u7684\u6d4b\u8bd5\u538b\u529b\u662f\u76f8\u540c\uff0c\u4e0b\u9762\u753b\u4e2a Upstream \u7684\u914d\u7f6e\u793a\u610f\u56fe\u5427\u3002<\/p>\n<p>\u6027\u80fd\u5dee<br \/>Nginx1 ==\u300b 30Servers<br \/>Nginx2 ==\u300b 30Servers<br \/>Nginx3==\u300b 30Servers<br \/>Nginx4==\u300b 30Servers<br \/>Nginx5 ==\u300b 30Servers<br \/>Nginx6 ==\u300b 30Servers<\/p>\n<p>\u6027\u80fd\u6709\u8f83\u5927\u5e45\u5ea6\u63d0\u5347<br \/>Nginx1 ==\u300b 1-5Servers<br \/>Nginx2 ==\u300b 6-10Servers<br \/>Nginx3==\u300b 11-15Servers<br \/>Nginx4==\u300b 16-20Servers<br \/>Nginx5 ==\u300b 21-25Servers<br \/>Nginx6 ==\u300b 26-30Servers<\/p>\n<p>\u60f3\u77e5\u9053\u573a\u666f 2 \u7684\u6574\u4f53\u6027\u80fd\u63d0\u5347\u662f\u5426\u8bf4\u660e Nginx \u7684\u67d0\u4e9b\u914d\u7f6e\u6709\u95ee\u9898\uff0c\u5bfc\u81f4 Upstream \u4e0d\u80fd\u586b\u592a\u591a Server                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5751632\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : Morxi <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @bantianys <\/p>\n<p>\u6211\u731c\u4f60\u6240\u6709\u7684 nginx \u914d\u6240\u6709\u8282\u70b9\u7684\u7ed3\u679c\u662f:\u524d\u51e0\u4e2a\u540e\u7aef Server \u5728\u6297\u5927\u90e8\u5206\u6d41\u91cf<\/p>\n<p>\u6765\u6e90\uff1a http:\/\/nginx.org\/en\/docs\/http\/ngx_http_upstream_module.html<br \/>&#8230;<br \/>By default, requests are distributed between the servers using a weighted round-robin balancing method. In the above example, each 7 requests will be distributed as follows: 5 requests go to backend1.example.com and one request to each of the second and third servers. If an error occurs during communication with a server, the request will be passed to the next server, and so on until all of the functioning servers will be tried. If a successful response could not be obtained from any of the servers, the client will receive the result of the communication with the last server.<br \/>&#8230;<\/p>\n<p>\u7ffb\u8bd1\uff1a<br \/>\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0c\u4f7f\u7528\u52a0\u6743\u5faa\u73af\u5e73\u8861\u65b9\u6cd5\u5728\u670d\u52a1\u5668\u4e4b\u95f4\u5206\u914d\u8bf7\u6c42\u3002\u5728\u4e0a\u9762\u7684\u793a\u4f8b\u4e2d\uff0c\u6bcf 7 \u4e2a\u8bf7\u6c42\u5c06\u5982\u4e0b\u5206\u914d\uff1a5 \u4e2a\u8bf7\u6c42\u8f6c\u5230 backend1.example.com \u7b2c\u4e8c\u4e2a\u548c\u7b2c\u4e09\u4e2a\u670d\u52a1\u5668\u4e2d\u7684\u4e00\u4e2a\u8bf7\u6c42\u3002\u5982\u679c\u5728\u4e0e\u670d\u52a1\u5668\u901a\u4fe1\u671f\u95f4\u53d1\u751f\u9519\u8bef\uff0c\u8be5\u8bf7\u6c42\u5c06\u88ab\u4f20\u9012\u5230\u4e0b\u4e00\u4e2a\u670d\u52a1\u5668\uff0c\u4f9d\u6b64\u7c7b\u63a8\uff0c\u76f4\u5230\u5c1d\u8bd5\u6240\u6709\u6b63\u5e38\u8fd0\u884c\u7684\u670d\u52a1\u5668\u4e3a\u6b62\u3002\u5982\u679c\u65e0\u6cd5\u4ece\u4efb\u4f55\u4e00\u53f0\u670d\u52a1\u5668\u83b7\u5f97\u6210\u529f\u7684\u54cd\u5e94\uff0c\u5219\u5ba2\u6237\u7aef\u5c06\u6536\u5230\u4e0e\u6700\u540e\u4e00\u53f0\u670d\u52a1\u5668\u7684\u901a\u4fe1\u7ed3\u679c\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5751633\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : whileFalse <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u4f60\u8bd5\u8bd5\u6bcf\u4e2a Nginx \u90fd\u586b\u5199 30 \u4e2a Upstream\uff0c\u5e76\u4e14\u6bcf\u4e2a Nginx \u7684\u987a\u5e8f\u4e0d\u540c\uff1a<br \/>Nginx1 ==&gt; 1-30<br \/>Nginx2 ==&gt; 6-30, 1-5<br \/>Nginx3 11-30, 1-10<\/p>\n<p>\u4f9d\u6b64\u7c7b\u63a8                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5751634\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : bantianys <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u4e0a\u5468\u9886\u5bfc\u627f\u8bfa\u8981\u6297 30W QPS\uff0c\u7ed3\u679c\u4e00\u6d4b\u6218\u529b\u53ea\u6709 5 \u3002\u3002\u3002\u6298\u817e\u4e86\u597d\u51e0\u5929\u6700\u7ec8\u7f29\u5c0f\u8303\u56f4\u5230 Nginx \u914d\u7f6e\u8fd9\u5757\u3002<\/p>\n<p>\u611f\u8c22\u5404\u4f4d\u5927\u4f6c\uff0c\u5468\u4e00\u4e0a\u73ed\u53bb\u8bd5\u8bd5\u3002                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5751635\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : akira <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u7528\u8fd9\u6837\u7684\u914d\u7f6e\u987a\u5e8f\u6d4b\u8bd5\u4e00\u4e0b\u5462<\/p>\n<p>nginx1 =&gt; 1-30<br \/>nginx2 =&gt; 6-30,1-5<br \/>nginx3 =&gt; 11-30,1-10<br \/>&#8230;..<br \/>nginx6 =&gt; 26-30,1-25                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5751636\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : rahuahua <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u597d\u5947\u95ee\u4e0b\u7b2c\u4e8c\u79cd\u914d\u7f6e\u63d0\u5347\u4e86\u591a\u5c11                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5751637\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : bantianys <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @rahuahua \u62c6\u5206\u6210\u5c0f\u96c6\u7fa4\u540e QPS \u7531 1.2W \u63d0\u5347\u5230\u63a5\u8fd1 12W \u3002\u5dee\u4e0d\u591a 10 \u500d\u4e86\u3002<br \/>\u4e5f\u4e0d\u6e05\u695a\u539f\u7406\u662f\u4ec0\u4e48\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5751638\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : rahuahua <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @bantianys \u4e56\u4e56\uff0c\u6709\u70b9\u7a81\u7834\u8ba4\u77e5\u4e86\uff0c\u671f\u5f85\u540e\u7eed\u603b\u7ed3~~~                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li>\n","protected":false},"excerpt":{"rendered":"<p>Upstream \u914d\u7684 Serve&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[],"tags":[],"_links":{"self":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/438816"}],"collection":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=438816"}],"version-history":[{"count":0,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/438816\/revisions"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=438816"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=438816"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=438816"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}