{"id":18191,"date":"2024-11-18T09:25:23","date_gmt":"2024-11-18T01:25:23","guid":{"rendered":"https:\/\/fwq.ai\/blog\/18191\/"},"modified":"2024-11-18T09:25:23","modified_gmt":"2024-11-18T01:25:23","slug":"linux%e8%b4%9f%e8%bd%bd%e5%9d%87%e8%a1%a1%e6%80%8e%e4%b9%88%e8%ae%be%e7%bd%ae","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/18191\/","title":{"rendered":"linux\u8d1f\u8f7d\u5747\u8861\u600e\u4e48\u8bbe\u7f6e"},"content":{"rendered":"<blockquote><p>\n  \u5728 linux \u7cfb\u7edf\u4e2d\uff0c\u8d1f\u8f7d\u5747\u8861\u901a\u8fc7\u5c06\u7f51\u7edc\u8bf7\u6c42\u5206\u5e03\u5230\u591a\u4e2a\u670d\u52a1\u5668\uff0c\u63d0\u9ad8\u4e86\u5904\u7406\u80fd\u529b\u548c\u7cfb\u7edf\u53ef\u9760\u6027\u3002\u5e38\u7528\u5de5\u5177\u5305\u62ec haproxy\u3001nginx\u3001lvs \u548c keepalived\u3002\u8bbe\u7f6e\u6b65\u9aa4\u4e3a\uff1a1\uff09\u5b89\u88c5\u8d1f\u8f7d\u5747\u8861\u8f6f\u4ef6\uff1b2\uff09\u914d\u7f6e\u670d\u52a1\u5668\u53c2\u6570\uff1b3\uff09\u542f\u52a8\u670d\u52a1\uff1b4\uff09\u6d4b\u8bd5\u8d1f\u8f7d\u5747\u8861\uff1b5\uff09\uff08\u53ef\u9009\uff09\u5efa\u7acb\u96c6\u7fa4\u7ba1\u7406\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202406\/04\/2024060413003292063.jpg\" class=\"aligncenter\" title=\"linux\u8d1f\u8f7d\u5747\u8861\u600e\u4e48\u8bbe\u7f6e\u63d2\u56fe\" alt=\"linux\u8d1f\u8f7d\u5747\u8861\u600e\u4e48\u8bbe\u7f6e\u63d2\u56fe\" \/><\/p>\n<p><strong>Linux\u8d1f\u8f7d\u5747\u8861\u8bbe\u7f6e<\/strong><\/p>\n<p><strong>\u8d1f\u8f7d\u5747\u8861\u7684\u4f5c\u7528<\/strong><\/p>\n<p>\u8d1f\u8f7d\u5747\u8861\u5728Linux\u7cfb\u7edf\u4e2d\u626e\u6f14\u7740\u81f3\u5173\u91cd\u8981\u7684\u89d2\u8272\uff0c\u5b83\u53ef\u4ee5\u5c06\u7f51\u7edc\u8bf7\u6c42\u5206\u5e03\u5230\u591a\u4e2a\u670d\u52a1\u5668\u4e0a\uff0c\u4ee5\u63d0\u9ad8\u5904\u7406\u80fd\u529b\uff0c\u589e\u5f3a\u7cfb\u7edf\u53ef\u9760\u6027\uff0c\u5e76\u907f\u514d\u5355\u70b9\u6545\u969c\u3002<\/p>\n<p><strong>\u5e38\u7528\u7684Linux\u8d1f\u8f7d\u5747\u8861\u5de5\u5177<\/strong><\/p>\n<p>Linux\u7cfb\u7edf\u4e2d\u5e38\u7528\u7684\u8d1f\u8f7d\u5747\u8861\u5de5\u5177\u5305\u62ec\uff1a<\/p>\n<ul>\n<li>HAProxy<\/li>\n<li>Nginx<\/li>\n<li>LVS (Linux Virtual Server)<\/li>\n<li>Keepalived<\/li>\n<\/ul>\n<p><strong>\u8d1f\u8f7d\u5747\u8861\u7684\u8bbe\u7f6e\u6b65\u9aa4<\/strong><\/p>\n<p><strong>1. \u5b89\u88c5\u8d1f\u8f7d\u5747\u8861\u8f6f\u4ef6<\/strong><\/p>\n<p>\u6839\u636e\u9700\u8981\u9009\u62e9\u7684\u8d1f\u8f7d\u5747\u8861\u5de5\u5177\uff0c\u901a\u8fc7\u53d1\u884c\u7248\u7684\u5305\u7ba1\u7406\u5de5\u5177\u8fdb\u884c\u5b89\u88c5\u3002\u4f8b\u5982\uff0c\u5bf9\u4e8eUbuntuHAProxy\uff1a<\/p>\n<pre>apt-get install haproxy<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>2. \u914d\u7f6e\u8d1f\u8f7d\u5747\u8861\u670d\u52a1\u5668<\/strong><\/p>\n<p>\u7f16\u8f91\u8d1f\u8f7d\u5747\u8861\u8f6f\u4ef6\u7684\u914d\u7f6e\u6587\u4ef6\uff0c\u6307\u5b9a\u9700\u8981\u5747\u8861\u7684\u670d\u52a1\u5668\uff0c\u7aef\u53e3\u548c\u7b97\u6cd5\u7b49\u53c2\u6570\u3002\u4f8b\u5982\uff0cHAProxy\u7684\u914d\u7f6e\u7247\u6bb5\uff1a<\/p>\n<pre>frontend http-in\n  bind *:80\n  default_backend servers\n\nbackend servers\n  server server1 192.168.1.101:8080\n  server server2 192.168.1.102:8080<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>3. \u542f\u52a8\u8d1f\u8f7d\u5747\u8861\u670d\u52a1<\/strong><\/p>\n<p>\u542f\u52a8\u8d1f\u8f7d\u5747\u8861\u670d\u52a1\uff0c\u5f00\u59cb\u5904\u7406\u7f51\u7edc\u8bf7\u6c42\u3002\u4f8b\u5982\uff0c\u542f\u52a8HAProxy\uff1a<\/p>\n<pre>service haproxy start<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>4. \u6d4b\u8bd5\u8d1f\u8f7d\u5747\u8861<\/strong><\/p>\n<p>\u4f7f\u7528curl\u6216\u5176\u4ed6\u5de5\u5177\u6d4b\u8bd5\u8d1f\u8f7d\u5747\u8861\u662f\u5426\u6b63\u5e38\u5de5\u4f5c\u3002\u4f8b\u5982\uff0c\u6d4b\u8bd5HAProxy\uff1a<\/p>\n<pre>curl http:\/\/loadbalancer.example.com<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>5. \u96c6\u7fa4\u7ba1\u7406\uff08\u53ef\u9009\uff09<\/strong><\/p>\n<p>\u5982\u679c\u9700\u8981\u5efa\u7acb\u8d1f\u8f7d\u5747\u8861\u96c6\u7fa4\uff0c\u53ef\u4ee5\u4f7f\u7528Keepalived\u7b49\u5de5\u5177\u5b9e\u73b0\u6545\u969c\u8f6c\u79fb\u548c\u9ad8\u53ef\u7528\u6027\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u8d1f\u8f7d\u5747\u8861\u600e\u4e48\u8bbe\u7f6e\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5728 linux \u7cfb\u7edf\u4e2d\uff0c\u8d1f\u8f7d\u5747\u8861\u901a\u8fc7\u5c06\u7f51\u7edc\u8bf7\u6c42\u5206\u5e03\u5230\u591a\u4e2a\u670d\u52a1\u5668\uff0c\u63d0\u9ad8\u4e86\u5904\u7406\u80fd\u529b\u548c\u7cfb\u7edf\u53ef\u9760\u6027\u3002\u5e38\u7528\u5de5\u5177\u5305\u62ec haproxy\u3001nginx\u3001lvs \u548c keepalived\u3002\u8bbe\u7f6e\u6b65\u9aa4\u4e3a\uff1a1\uff09\u5b89\u88c5\u8d1f\u8f7d\u5747\u8861\u8f6f\u4ef6\uff1b2\uff09\u914d\u7f6e\u670d\u52a1\u5668\u53c2\u6570\uff1b3\uff09\u542f\u52a8\u670d\u52a1\uff1b4\uff09\u6d4b\u8bd5\u8d1f\u8f7d\u5747\u8861\uff1b5\uff09\uff08\u53ef\u9009\uff09\u5efa\u7acb\u96c6\u7fa4\u7ba1\u7406\u3002 Linux\u8d1f\u8f7d\u5747\u8861\u8bbe\u7f6e \u8d1f\u8f7d\u5747\u8861\u7684\u4f5c\u7528 \u8d1f\u8f7d\u5747\u8861\u5728Linux\u7cfb\u7edf\u4e2d\u626e\u6f14\u7740\u81f3\u5173\u91cd\u8981\u7684\u89d2\u8272\uff0c\u5b83\u53ef\u4ee5\u5c06\u7f51\u7edc\u8bf7\u6c42\u5206\u5e03\u5230\u591a\u4e2a\u670d\u52a1\u5668\u4e0a\uff0c\u4ee5\u63d0\u9ad8\u5904\u7406\u80fd\u529b\uff0c\u589e\u5f3a\u7cfb\u7edf\u53ef\u9760\u6027\uff0c\u5e76\u907f\u514d\u5355\u70b9\u6545\u969c\u3002 \u5e38\u7528\u7684Linux\u8d1f\u8f7d\u5747\u8861\u5de5\u5177 Linux\u7cfb\u7edf\u4e2d\u5e38\u7528\u7684\u8d1f\u8f7d\u5747\u8861\u5de5\u5177\u5305\u62ec\uff1a HAProxy Nginx LVS (Linux Virtual Server) Keepalived \u8d1f\u8f7d\u5747\u8861\u7684\u8bbe\u7f6e\u6b65\u9aa4 1. \u5b89\u88c5\u8d1f\u8f7d\u5747\u8861\u8f6f\u4ef6 \u6839\u636e\u9700\u8981\u9009\u62e9\u7684\u8d1f\u8f7d\u5747\u8861\u5de5\u5177\uff0c\u901a\u8fc7\u53d1\u884c\u7248\u7684\u5305\u7ba1\u7406\u5de5\u5177\u8fdb\u884c\u5b89\u88c5\u3002\u4f8b\u5982\uff0c\u5bf9\u4e8eUbuntuHAProxy\uff1a apt-get install haproxy \u767b\u5f55\u540e\u590d\u5236 2. \u914d\u7f6e\u8d1f\u8f7d\u5747\u8861\u670d\u52a1\u5668 \u7f16\u8f91\u8d1f\u8f7d\u5747\u8861\u8f6f\u4ef6\u7684\u914d\u7f6e\u6587\u4ef6\uff0c\u6307\u5b9a\u9700\u8981\u5747\u8861\u7684\u670d\u52a1\u5668\uff0c\u7aef\u53e3\u548c\u7b97\u6cd5\u7b49\u53c2\u6570\u3002\u4f8b\u5982\uff0cHAProxy\u7684\u914d\u7f6e\u7247\u6bb5\uff1a frontend http-in bind *:80 default_backend servers backend servers server server1 192.168.1.101:8080 server server2 192.168.1.102:8080 \u767b\u5f55\u540e\u590d\u5236 3. \u542f\u52a8\u8d1f\u8f7d\u5747\u8861\u670d\u52a1 \u542f\u52a8\u8d1f\u8f7d\u5747\u8861\u670d\u52a1\uff0c\u5f00\u59cb\u5904\u7406\u7f51\u7edc\u8bf7\u6c42\u3002\u4f8b\u5982\uff0c\u542f\u52a8HAProxy\uff1a service haproxy start \u767b\u5f55\u540e\u590d\u5236 4. \u6d4b\u8bd5\u8d1f\u8f7d\u5747\u8861 \u4f7f\u7528curl\u6216\u5176\u4ed6\u5de5\u5177\u6d4b\u8bd5\u8d1f\u8f7d\u5747\u8861\u662f\u5426\u6b63\u5e38\u5de5\u4f5c\u3002\u4f8b\u5982\uff0c\u6d4b\u8bd5HAProxy\uff1a curl [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[],"class_list":["post-18191","post","type-post","status-publish","format-standard","hentry","category-os"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/18191","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=18191"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/18191\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=18191"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=18191"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=18191"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}