{"id":36193,"date":"2024-10-01T01:37:09","date_gmt":"2024-09-30T17:37:09","guid":{"rendered":"https:\/\/server.hk\/cnblog\/36193\/"},"modified":"2024-10-01T01:37:09","modified_gmt":"2024-09-30T17:37:09","slug":"apache%e5%ae%89%e5%85%a8%e7%ad%96%e7%95%a5%ef%bc%9a%e4%bd%bf%e7%94%a8mod_proxy_balancer%e9%80%b2%e8%a1%8c%e8%b2%a0%e8%bc%89%e5%9d%87%e8%a1%a1","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/36193\/","title":{"rendered":"Apache\u5b89\u5168\u7b56\u7565\uff1a\u4f7f\u7528mod_proxy_balancer\u9032\u884c\u8ca0\u8f09\u5747\u8861"},"content":{"rendered":"<h1 id=\"apache%e5%ae%89%e5%85%a8%e7%ad%96%e7%95%a5%ef%bc%9a%e4%bd%bf%e7%94%a8mod_proxy_balancer%e9%80%b2%e8%a1%8c%e8%b2%a0%e8%bc%89%e5%9d%87%e8%a1%a1-htXYwADLIn\">Apache\u5b89\u5168\u7b56\u7565\uff1a\u4f7f\u7528mod_proxy_balancer\u9032\u884c\u8ca0\u8f09\u5747\u8861<\/h1>\n<p>\u5728\u7576\u4eca\u7684\u7db2\u7d61\u74b0\u5883\u4e2d\uff0c\u7db2\u7ad9\u7684\u53ef\u7528\u6027\u548c\u6027\u80fd\u81f3\u95dc\u91cd\u8981\u3002Apache\u4f5c\u70ba\u4e00\u500b\u5ee3\u6cdb\u4f7f\u7528\u7684\u7db2\u9801\u4f3a\u670d\u5668\uff0c\u63d0\u4f9b\u4e86\u591a\u7a2e\u529f\u80fd\u4f86\u652f\u6301\u9ad8\u6548\u7684\u8ca0\u8f09\u5747\u8861\u3002\u5176\u4e2d\uff0c<code>mod_proxy_balancer<\/code>\u6a21\u7d44\u662f\u5be6\u73fe\u8ca0\u8f09\u5747\u8861\u7684\u4e00\u500b\u91cd\u8981\u5de5\u5177\u3002\u672c\u6587\u5c07\u63a2\u8a0e\u5982\u4f55\u4f7f\u7528<code>mod_proxy_balancer<\/code>\u4f86\u589e\u5f37Apache\u7684\u5b89\u5168\u6027\u548c\u6027\u80fd\u3002<\/p>\n<h2 id=\"%e4%bb%80%e9%ba%bc%e6%98%afmod_proxy_balancer%ef%bc%9f-htXYwADLIn\">\u4ec0\u9ebc\u662fmod_proxy_balancer\uff1f<\/h2>\n<p><code>mod_proxy_balancer<\/code>\u662fApache\u7684\u4e00\u500b\u6a21\u7d44\uff0c\u5141\u8a31\u7528\u6236\u5c07\u8acb\u6c42\u5206\u914d\u5230\u591a\u500b\u5f8c\u7aef\u4f3a\u670d\u5668\u4e0a\u3002\u9019\u6a23\u53ef\u4ee5\u6709\u6548\u5730\u5206\u6563\u6d41\u91cf\uff0c\u6e1b\u5c11\u55ae\u4e00\u4f3a\u670d\u5668\u7684\u8ca0\u64d4\uff0c\u5f9e\u800c\u63d0\u9ad8\u6574\u9ad4\u7cfb\u7d71\u7684\u53ef\u7528\u6027\u548c\u97ff\u61c9\u901f\u5ea6\u3002<\/p>\n<h2 id=\"%e7%82%ba%e4%bb%80%e9%ba%bc%e9%9c%80%e8%a6%81%e8%b2%a0%e8%bc%89%e5%9d%87%e8%a1%a1%ef%bc%9f-htXYwADLIn\">\u70ba\u4ec0\u9ebc\u9700\u8981\u8ca0\u8f09\u5747\u8861\uff1f<\/h2>\n<ul>\n<li><strong>\u63d0\u9ad8\u53ef\u7528\u6027\uff1a<\/strong>\u7576\u4e00\u53f0\u4f3a\u670d\u5668\u51fa\u73fe\u6545\u969c\u6642\uff0c\u8ca0\u8f09\u5747\u8861\u53ef\u4ee5\u81ea\u52d5\u5c07\u6d41\u91cf\u8f49\u79fb\u5230\u5176\u4ed6\u53ef\u7528\u7684\u4f3a\u670d\u5668\uff0c\u78ba\u4fdd\u7db2\u7ad9\u7684\u6301\u7e8c\u904b\u884c\u3002<\/li>\n<li><strong>\u589e\u5f37\u6027\u80fd\uff1a<\/strong>\u901a\u904e\u5c07\u8acb\u6c42\u5206\u914d\u5230\u591a\u500b\u4f3a\u670d\u5668\uff0c\u53ef\u4ee5\u6e1b\u5c11\u6bcf\u53f0\u4f3a\u670d\u5668\u7684\u8ca0\u8f09\uff0c\u63d0\u9ad8\u97ff\u61c9\u901f\u5ea6\u3002<\/li>\n<li><strong>\u64f4\u5c55\u6027\uff1a<\/strong>\u96a8\u8457\u6d41\u91cf\u7684\u589e\u9577\uff0c\u53ef\u4ee5\u8f15\u9b06\u5730\u6dfb\u52a0\u66f4\u591a\u7684\u4f3a\u670d\u5668\u4f86\u61c9\u5c0d\u9700\u6c42\u3002<\/li>\n<\/ul>\n<h2 id=\"%e5%a6%82%e4%bd%95%e9%85%8d%e7%bd%aemod_proxy_balancer-htXYwADLIn\">\u5982\u4f55\u914d\u7f6emod_proxy_balancer<\/h2>\n<p>\u4ee5\u4e0b\u662f\u914d\u7f6e<code>mod_proxy_balancer<\/code>\u7684\u57fa\u672c\u6b65\u9a5f\uff1a<\/p>\n<h3 id=\"1-%e5%95%9f%e7%94%a8%e6%a8%a1%e7%b5%84-htXYwADLIn\">1. \u555f\u7528\u6a21\u7d44<\/h3>\n<p>\u9996\u5148\uff0c\u78ba\u4fddApache\u5df2\u7d93\u555f\u7528<code>mod_proxy<\/code>\u548c<code>mod_proxy_balancer<\/code>\u6a21\u7d44\u3002\u53ef\u4ee5\u901a\u904e\u4ee5\u4e0b\u547d\u4ee4\u4f86\u555f\u7528\uff1a<\/p>\n<pre><code>sudo a2enmod proxy\nsudo a2enmod proxy_balancer\nsudo a2enmod lbmethod_byrequests\n<\/code><\/pre>\n<h3 id=\"2-%e9%85%8d%e7%bd%ae%e8%b2%a0%e8%bc%89%e5%9d%87%e8%a1%a1%e5%99%a8-htXYwADLIn\">2. \u914d\u7f6e\u8ca0\u8f09\u5747\u8861\u5668<\/h3>\n<p>\u5728Apache\u7684\u914d\u7f6e\u6587\u4ef6\u4e2d\uff08\u901a\u5e38\u662f<code>httpd.conf<\/code>\u6216<code>sites-available\/default.conf<\/code>\uff09\uff0c\u6dfb\u52a0\u4ee5\u4e0b\u914d\u7f6e\uff1a<\/p>\n<pre><code>&lt;Proxy balancer:\/\/mycluster&gt;\n    BalancerMember http:\/\/192.168.1.1:80\n    BalancerMember http:\/\/192.168.1.2:80\n    BalancerMember http:\/\/192.168.1.3:80\n    ProxySet lbmethod=byrequests\n&lt;\/Proxy&gt;\n\n&lt;Location \/&gt;\n    ProxyPass balancer:\/\/mycluster\n    ProxyPassReverse balancer:\/\/mycluster\n&lt;\/Location&gt;\n<\/code><\/pre>\n<p>\u5728\u9019\u6bb5\u914d\u7f6e\u4e2d\uff0c<code>BalancerMember<\/code>\u6307\u4ee4\u7528\u65bc\u6307\u5b9a\u5f8c\u7aef\u4f3a\u670d\u5668\u7684\u5730\u5740\u3002<code>ProxyPass<\/code>\u548c<code>ProxyPassReverse<\/code>\u6307\u4ee4\u5247\u7528\u65bc\u5c07\u8acb\u6c42\u8f49\u767c\u5230\u8ca0\u8f09\u5747\u8861\u5668\u3002<\/p>\n<h3 id=\"3-%e8%a8%ad%e5%ae%9a%e5%81%a5%e5%ba%b7%e6%aa%a2%e6%9f%a5-htXYwADLIn\">3. \u8a2d\u5b9a\u5065\u5eb7\u6aa2\u67e5<\/h3>\n<p>\u70ba\u4e86\u78ba\u4fdd\u8ca0\u8f09\u5747\u8861\u5668\u7684\u6709\u6548\u6027\uff0c\u53ef\u4ee5\u8a2d\u7f6e\u5065\u5eb7\u6aa2\u67e5\u4f86\u76e3\u63a7\u5f8c\u7aef\u4f3a\u670d\u5668\u7684\u72c0\u614b\u3002\u53ef\u4ee5\u4f7f\u7528<code>ProxySet<\/code>\u6307\u4ee4\u4f86\u914d\u7f6e\u5065\u5eb7\u6aa2\u67e5\uff1a<\/p>\n<pre><code>ProxySet balancer:\/\/mycluster ping=5 timeout=2\n<\/code><\/pre>\n<p>\u9019\u6a23\u914d\u7f6e\u5f8c\uff0c\u8ca0\u8f09\u5747\u8861\u5668\u5c07\u6bcf5\u79d2\u6aa2\u67e5\u4e00\u6b21\u5f8c\u7aef\u4f3a\u670d\u5668\u7684\u72c0\u614b\uff0c\u4e26\u5728\u8d85\u66422\u79d2\u5f8c\u5224\u65b7\u4f3a\u670d\u5668\u662f\u5426\u53ef\u7528\u3002<\/p>\n<h2 id=\"%e5%ae%89%e5%85%a8%e6%80%a7%e8%80%83%e9%87%8f-htXYwADLIn\">\u5b89\u5168\u6027\u8003\u91cf<\/h2>\n<p>\u5728\u4f7f\u7528<code>mod_proxy_balancer<\/code>\u6642\uff0c\u5b89\u5168\u6027\u662f\u4e0d\u53ef\u5ffd\u8996\u7684\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u5efa\u8b70\uff1a<\/p>\n<ul>\n<li><strong>\u9650\u5236\u8a2a\u554f\uff1a<\/strong>\u53ef\u4ee5\u4f7f\u7528<code>Require<\/code>\u6307\u4ee4\u4f86\u9650\u5236\u5c0d\u8ca0\u8f09\u5747\u8861\u5668\u7684\u8a2a\u554f\u3002<\/li>\n<li><strong>\u4f7f\u7528SSL\uff1a<\/strong>\u5efa\u8b70\u5728\u4f3a\u670d\u5668\u4e4b\u9593\u4f7f\u7528SSL\u52a0\u5bc6\u901a\u4fe1\uff0c\u4ee5\u4fdd\u8b77\u6578\u64da\u7684\u5b89\u5168\u6027\u3002<\/li>\n<li><strong>\u76e3\u63a7\u65e5\u8a8c\uff1a<\/strong>\u5b9a\u671f\u6aa2\u67e5Apache\u7684\u8a2a\u554f\u65e5\u8a8c\u548c\u932f\u8aa4\u65e5\u8a8c\uff0c\u4ee5\u4fbf\u53ca\u6642\u767c\u73fe\u6f5b\u5728\u7684\u5b89\u5168\u554f\u984c\u3002<\/li>\n<\/ul>\n<h2 id=\"%e7%b8%bd%e7%b5%90-htXYwADLIn\">\u7e3d\u7d50<\/h2>\n<p>\u4f7f\u7528<code>mod_proxy_balancer<\/code>\u9032\u884c\u8ca0\u8f09\u5747\u8861\u4e0d\u50c5\u53ef\u4ee5\u63d0\u9ad8\u7db2\u7ad9\u7684\u6027\u80fd\u548c\u53ef\u7528\u6027\uff0c\u9084\u80fd\u589e\u5f37\u6574\u9ad4\u7684\u5b89\u5168\u6027\u3002\u901a\u904e\u5408\u7406\u7684\u914d\u7f6e\u548c\u76e3\u63a7\uff0c\u53ef\u4ee5\u78ba\u4fdd\u4f3a\u670d\u5668\u5728\u9ad8\u6d41\u91cf\u60c5\u6cc1\u4e0b\u4f9d\u7136\u7a69\u5b9a\u904b\u884c\u3002\u5c0d\u65bc\u5c0b\u6c42\u9ad8\u6548\u80fd\u548c\u7a69\u5b9a\u6027\u7684\u7528\u6236\u4f86\u8aaa\uff0c\u9078\u64c7\u5408\u9069\u7684<code>VPS<\/code>\u89e3\u6c7a\u65b9\u6848\u81f3\u95dc\u91cd\u8981\u3002\u4e86\u89e3\u66f4\u591a\u95dc\u65bc<code><a href=\"https:\/\/server.hk\">\u9999\u6e2fVPS<\/a><\/code>\u548c<code><a href=\"https:\/\/server.hk\">\u4f3a\u670d\u5668<\/a><\/code>\u7684\u8cc7\u8a0a\uff0c\u8acb\u8a2a\u554f\u6211\u5011\u7684\u7db2\u7ad9\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e86\u89e3\u5982\u4f55\u4f7f\u7528Apache\u7684mod_proxy_balancer\u5be6\u73fe\u8ca0\u8f09\u5747\u8861\uff0c\u63d0\u5347\u7db2\u7ad9\u6027\u80fd\u8207\u5b89\u5168\u6027\uff0c\u78ba\u4fdd\u7a69\u5b9a\u7684\u7528\u6236\u9ad4\u9a57\u3002<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4924],"tags":[],"class_list":["post-36193","post","type-post","status-publish","format-standard","hentry","category-setup-tutorials"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/36193","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=36193"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/36193\/revisions"}],"predecessor-version":[{"id":36194,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/36193\/revisions\/36194"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=36193"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=36193"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=36193"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}