{"id":22213,"date":"2024-02-05T11:30:26","date_gmt":"2024-02-05T11:30:26","guid":{"rendered":"https:\/\/server.hk\/blog\/22213\/"},"modified":"2024-09-12T14:15:23","modified_gmt":"2024-09-12T14:15:23","slug":"configuring-load-balancers-on-your-usa-vps-high-availability-setup","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/22213\/","title":{"rendered":"\u5728\u60a8\u7684\u9999\u6e2fVPS\u4e0a\u914d\u7f6e\u8ca0\u8f09\u5747\u8861\u5668\uff1a\u9ad8\u53ef\u7528\u6027\u8a2d\u7f6e"},"content":{"rendered":"<h1 id=\"configuring-load-balancers-on-your-usa-vps-high-availability-setup-oHHxMXJPei\">\u5728\u60a8\u7684\u9999\u6e2fVPS\u4e0a\u914d\u7f6e\u8ca0\u8f09\u5747\u8861\u5668\uff1a\u9ad8\u53ef\u7528\u6027\u8a2d\u7f6e<\/h1>\n<p>\u8ca0\u8f09\u5747\u8861\u662f\u7ba1\u7406\u9ad8\u6d41\u91cf\u7db2\u7ad9\u6216\u61c9\u7528\u7a0b\u5e8f\u7684\u95dc\u9375\u65b9\u9762\u3002\u5b83\u6709\u52a9\u65bc\u5c07\u9032\u5165\u7684\u7db2\u7d61\u6d41\u91cf\u5206\u4f48\u5728\u591a\u500b\u670d\u52d9\u5668\u4e0a\uff0c\u78ba\u4fdd\u6700\u4f73\u6027\u80fd\u3001\u53ef\u64f4\u5c55\u6027\u548c\u9ad8\u53ef\u7528\u6027\u3002\u5728\u672c\u6587\u4e2d\uff0c\u6211\u5011\u5c07\u63a2\u8a0e\u5728\u60a8\u7684\u9999\u6e2fVPS\u4e0a\u914d\u7f6e\u8ca0\u8f09\u5747\u8861\u5668\u4ee5\u5be6\u73fe\u7a69\u5065\u53ef\u9760\u7684\u9ad8\u53ef\u7528\u6027\u8a2d\u7f6e\u7684\u904e\u7a0b\u3002<\/p>\n<h2 id=\"understanding-load-balancing-oHHxMXJPei\">\u4e86\u89e3\u8ca0\u8f09\u5747\u8861<\/h2>\n<p>\u8ca0\u8f09\u5747\u8861\u6d89\u53ca\u5c07\u9032\u5165\u7684\u7db2\u7d61\u6d41\u91cf\u5206\u4f48\u5728\u591a\u500b\u670d\u52d9\u5668\uff08\u7a31\u70ba\u5f8c\u7aef\u670d\u52d9\u5668\u6216\u7bc0\u9ede\uff09\u4e0a\u3002\u8ca0\u8f09\u5747\u8861\u5668\u5145\u7576\u5ba2\u6236\u7aef\u548c\u5f8c\u7aef\u670d\u52d9\u5668\u4e4b\u9593\u7684\u4e2d\u4ecb\uff0c\u667a\u80fd\u5730\u8def\u7531\u8acb\u6c42\u4ee5\u78ba\u4fdd\u5747\u52fb\u5206\u4f48\u548c\u6709\u6548\u5229\u7528\u8cc7\u6e90\u3002<\/p>\n<p>\u901a\u904e\u5728\u591a\u500b\u670d\u52d9\u5668\u4e0a\u5206\u4f48\u5de5\u4f5c\u8ca0\u8377\uff0c\u8ca0\u8f09\u5747\u8861\u5e6b\u52a9\u9632\u6b62\u4efb\u4f55\u55ae\u4e00\u670d\u52d9\u5668\u56e0\u6d41\u91cf\u904e\u5927\u800c\u8b8a\u5f97\u4e0d\u582a\u91cd\u8ca0\uff0c\u5f9e\u800c\u63d0\u5347\u6027\u80fd\u4e26\u9632\u6b62\u505c\u6a5f\u3002\u5b83\u9084\u5be6\u73fe\u4e86\u6c34\u5e73\u64f4\u5c55\uff0c\u5141\u8a31\u60a8\u6839\u64da\u4e0d\u540c\u7684\u6d41\u91cf\u8ca0\u8377\u9700\u8981\u6dfb\u52a0\u6216\u79fb\u9664\u670d\u52d9\u5668\u3002<\/p>\n<h2 id=\"types-of-load-balancers-oHHxMXJPei\">\u8ca0\u8f09\u5747\u8861\u5668\u7684\u985e\u578b<\/h2>\n<p>\u6709\u5e7e\u7a2e\u985e\u578b\u7684\u8ca0\u8f09\u5747\u8861\u5668\u53ef\u7528\uff0c\u6bcf\u7a2e\u90fd\u6709\u5176\u7368\u7279\u7684\u512a\u52e2\u548c\u4f7f\u7528\u5834\u666f\u3002\u8b93\u6211\u5011\u63a2\u7d22\u5e7e\u7a2e\u5e38\u898b\u985e\u578b\uff1a<\/p>\n<h3 id=\"1-hardware-load-balancers-oHHxMXJPei\">1. \u786c\u4ef6\u8ca0\u8f09\u5747\u8861\u5668<\/h3>\n<p>\u786c\u4ef6\u8ca0\u8f09\u5747\u8861\u5668\u662f\u5c08\u9580\u7528\u65bc\u8ca0\u8f09\u5747\u8861\u7684\u5be6\u9ad4\u8a2d\u5099\u3002\u5b83\u5011\u63d0\u4f9b\u9ad8\u6027\u80fd\u3001\u53ef\u64f4\u5c55\u6027\u548c\u9ad8\u7d1a\u529f\u80fd\u3002\u7136\u800c\uff0c\u5b83\u5011\u53ef\u80fd\u50f9\u683c\u6602\u8cb4\u4e14\u9700\u8981\u5c08\u696d\u77e5\u8b58\u9032\u884c\u914d\u7f6e\u548c\u7dad\u8b77\u3002<\/p>\n<h3 id=\"2-software-load-balancers-oHHxMXJPei\">2. \u8edf\u4ef6\u8ca0\u8f09\u5747\u8861\u5668<\/h3>\n<p>\u8edf\u4ef6\u8ca0\u8f09\u5747\u8861\u5668\u4f5c\u70ba\u5728\u5c08\u7528\u670d\u52d9\u5668\u6216\u865b\u64ec\u6a5f\u4e0a\u904b\u884c\u7684\u8edf\u4ef6\u61c9\u7528\u7a0b\u5e8f\u5be6\u73fe\u3002\u5b83\u5011\u63d0\u4f9b\u9748\u6d3b\u6027\u3001\u7d93\u6fdf\u5be6\u60e0\u548c\u914d\u7f6e\u7c21\u4fbf\u3002\u6d41\u884c\u7684\u8edf\u4ef6\u8ca0\u8f09\u5747\u8861\u5668\u5305\u62ecNginx\u3001HAProxy\u548cApache HTTP Server\u3002<\/p>\n<h3 id=\"3-cloud-load-balancers-oHHxMXJPei\">3. \u96f2\u8ca0\u8f09\u5747\u8861\u5668<\/h3>\n<p>\u96f2\u8ca0\u8f09\u5747\u8861\u5668\u7531\u96f2\u670d\u52d9\u63d0\u4f9b\u5546\u4f5c\u70ba\u6258\u7ba1\u670d\u52d9\u63d0\u4f9b\u3002\u5b83\u5011\u5177\u6709\u6975\u9ad8\u7684\u53ef\u64f4\u5c55\u6027\uff0c\u80fd\u5920\u81ea\u52d5\u8abf\u6574\u4ee5\u9069\u61c9\u8b8a\u5316\u7684\u6d41\u91cf\u6a21\u5f0f\uff0c\u4e26\u7d93\u5e38\u8207\u5176\u4ed6\u96f2\u670d\u52d9\u7121\u7e2b\u6574\u5408\u3002\u4f8b\u5982Amazon Elastic Load Balancer\uff08ELB\uff09\u548cGoogle Cloud Load Balancer\u3002<\/p>\n<h2 id=\"configuring-load-balancers-on-your-usa-vps-oHHxMXJPei\">\u5728\u60a8\u7684\u9999\u6e2fVPS\u4e0a\u914d\u7f6e\u8ca0\u8f09\u5747\u8861\u5668<\/h2>\n<p>\u5728\u60a8\u7684\u9999\u6e2fVPS\u4e0a\u914d\u7f6e\u8ca0\u8f09\u5747\u8861\u5668\u6642\uff0c\u60a8\u6709\u591a\u500b\u9078\u64c7\u3002\u8b93\u6211\u5011\u770b\u770b\u4f7f\u7528Nginx\u4f5c\u70ba\u8edf\u4ef6\u8ca0\u8f09\u5747\u8861\u5668\u7684\u5e38\u898b\u8a2d\u7f6e\uff1a<\/p>\n<h3 id=\"step-1-set-up-backend-servers-oHHxMXJPei\">\u6b65\u9a5f1\uff1a\u8a2d\u7f6e\u5f8c\u7aef\u670d\u52d9\u5668<\/h3>\n<p>\u5728\u914d\u7f6e\u8ca0\u8f09\u5747\u8861\u5668\u4e4b\u524d\uff0c\u60a8\u9700\u8981\u8a2d\u7f6e\u5c07\u8655\u7406\u9032\u5165\u6d41\u91cf\u7684\u5f8c\u7aef\u670d\u52d9\u5668\u3002\u78ba\u4fdd\u6240\u6709\u670d\u52d9\u5668\u5177\u5099\u670d\u52d9\u60a8\u61c9\u7528\u7a0b\u5e8f\u7684\u5fc5\u8981\u8edf\u4ef6\u548c\u914d\u7f6e\u3002<\/p>\n<h3 id=\"step-2-install-and-configure-nginx-oHHxMXJPei\">\u6b65\u9a5f2\uff1a\u5b89\u88dd\u4e26\u914d\u7f6eNginx<\/h3>\n<p>\u5728\u5c07\u7528\u4f5c\u8ca0\u8f09\u5747\u8861\u5668\u7684\u7368\u7acb\u670d\u52d9\u5668\u4e0a\u5b89\u88ddNginx\u3002\u914d\u7f6eNginx\u4ee5\u76e3\u807d\u9032\u5165\u8acb\u6c42\u4e26\u5c07\u5b83\u5011\u5206\u4f48\u5230\u5f8c\u7aef\u670d\u52d9\u5668\u4e0a\u3002\u60a8\u53ef\u4ee5\u4f7f\u7528\u5404\u7a2e\u8ca0\u8f09\u5747\u8861\u7b97\u6cd5\uff0c\u5982\u5faa\u74b0\u8f2a\u8a62\uff08round-robin\uff09\u3001\u6700\u5c11\u9023\u63a5\uff08least connections\uff09\u6216IP\u54c8\u5e0c\uff08IP hash\uff09\uff0c\u53d6\u6c7a\u65bc\u60a8\u7684\u9700\u6c42\u3002<\/p>\n<pre><code>http {\r\n  upstream backend {\r\n    server backend1.example.com;\r\n    server backend2.example.com;\r\n    server backend3.example.com;\r\n  }\r\n\r\n  server {\r\n    listen 80;\r\n\r\n    location \/ {\r\n      proxy_pass http:\/\/backend;\r\n    }\r\n  }\r\n}\r\n<\/code><\/pre>\n<h3 id=\"step-3-test-and-monitor-oHHxMXJPei\">\u6b65\u9a5f3\uff1a\u6e2c\u8a66\u548c\u76e3\u63a7<\/h3>\n<p>\u914d\u7f6e\u8ca0\u8f09\u5747\u8861\u5668\u5f8c\uff0c\u901a\u904e\u5411\u8ca0\u8f09\u5747\u8861\u5668\u7684IP\u5730\u5740\u6216\u57df\u540d\u767c\u9001\u8acb\u6c42\u4f86\u6e2c\u8a66\u5176\u529f\u80fd\u3002\u76e3\u63a7\u5f8c\u7aef\u670d\u52d9\u5668\u4ee5\u78ba\u4fdd\u8ca0\u8f09\u5747\u52fb\u5206\u4f48\uff0c\u4e26\u6709\u6548\u8655\u7406\u6d41\u91cf\u3002<\/p>\n<h2 id=\"conclusion-oHHxMXJPei\">\u7d50\u8ad6<\/h2>\n<p>\u5728\u60a8\u7684\u9999\u6e2fVPS\u4e0a\u914d\u7f6e\u8ca0\u8f09\u5747\u8861\u5668\u662f\u5be6\u73fe\u60a8\u7684\u7db2\u7ad9\u6216\u61c9\u7528\u7a0b\u5e8f\u9ad8\u53ef\u7528\u6027\u8a2d\u7f6e\u7684\u95dc\u9375\u6b65\u9a5f\u3002\u901a\u904e\u5728\u591a\u500b\u670d\u52d9\u5668\u4e0a\u5206\u4f48\u6d41\u91cf\uff0c\u8ca0\u8f09\u5747\u8861\u63d0\u9ad8\u4e86\u6027\u80fd\u3001\u53ef\u64f4\u5c55\u6027\u4e26\u78ba\u4fdd\u4e86\u60a8\u7684\u670d\u52d9\u5728\u9ad8\u6d41\u91cf\u671f\u9593\u4f9d\u7136\u53ef\u7528\u3002\u8003\u616e\u53ef\u7528\u7684\u4e0d\u540c\u985e\u578b\u7684\u8ca0\u8f09\u5747\u8861\u5668\uff0c\u4e26\u9078\u64c7\u6700\u9069\u5408\u60a8\u9700\u6c42\u7684\u4e00\u7a2e\u3002\u901a\u904e\u9069\u7576\u7684\u914d\u7f6e\u548c\u76e3\u63a7\uff0c\u8ca0\u8f09\u5747\u8861\u5668\u80fd\u986f\u8457\u63d0\u5347\u60a8\u7684\u9999\u6e2fVPS\u6258\u7ba1\u74b0\u5883\u7684\u53ef\u9760\u6027\u548c\u6027\u80fd\u3002<\/p>\n<h2 id=\"summary-oHHxMXJPei\">\u6458\u8981<\/h2>\n<p>\u5c07\u8ca0\u8f09\u5747\u8861\u5668\u6574\u5408\u5230\u60a8\u7684\u9999\u6e2fVPS\u6258\u7ba1\u74b0\u5883\u4e2d\u5c0d\u65bc\u5be6\u73fe\u9ad8\u53ef\u7528\u6027\u548c\u6700\u4f73\u6027\u80fd\u81f3\u95dc\u91cd\u8981\u3002\u901a\u904e\u5728\u591a\u500b\u670d\u52d9\u5668\u4e0a\u5206\u4f48\u9032\u5165\u7684\u7db2\u7d61\u6d41\u91cf\uff0c\u8ca0\u8f09\u5747\u8861\u5668\u78ba\u4fdd\u6709\u6548\u5229\u7528\u8cc7\u6e90\u4e26\u9632\u6b62\u4efb\u4f55\u55ae\u4e00\u670d\u52d9\u5668\u56e0\u6d41\u91cf\u904e\u5927\u800c\u8b8a\u5f97\u4e0d\u582a\u91cd\u8ca0\u3002\u5728Server.HK\uff0c\u6211\u5011\u4e86\u89e3\u5728\u5275\u5efa\u5f37\u5927\u7684\u6258\u7ba1\u8a2d\u7f6e\u4e2d\u8ca0\u8f09\u5747\u8861\u7684\u91cd\u8981\u6027\u3002\u8a2a\u554f\u6211\u5011\u7684\u7db2\u7ad9\u4e86\u89e3\u66f4\u591a\u95dc\u65bc\u6211\u5011\u7684<a href=\"https:\/\/server.hk\">\u9999\u6e2fVPS\u6258\u7ba1<\/a>\u89e3\u6c7a\u65b9\u6848\uff0c\u4ee5\u53ca\u6211\u5011\u5982\u4f55\u5e6b\u52a9\u60a8\u914d\u7f6e\u8ca0\u8f09\u5747\u8861\u5668\u4ee5\u6eff\u8db3\u60a8\u7684\u9ad8\u53ef\u7528\u6027\u9700\u6c42\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5728\u60a8\u7684\u9999\u6e2fVPS\u4e0a\u914d\u7f6e\u8ca0\u8f09\u5747\u8861\u5668&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4927],"tags":[],"class_list":["post-22213","post","type-post","status-publish","format-standard","hentry","category-4927"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/22213","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=22213"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/22213\/revisions"}],"predecessor-version":[{"id":23164,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/22213\/revisions\/23164"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=22213"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=22213"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=22213"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}