{"id":18258,"date":"2025-04-19T00:38:59","date_gmt":"2025-04-18T16:38:59","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/18258.html"},"modified":"2025-04-19T00:38:59","modified_gmt":"2025-04-18T16:38:59","slug":"%e5%b8%a6%e4%bd%a0%e5%85%a8%e9%9d%a2%e4%ba%86%e8%a7%a3haproxy-%ef%bc%88%e8%b6%85%e8%af%a6%e7%bb%86%e7%89%88%ef%bc%89","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/18258.html","title":{"rendered":"\u5e26\u4f60\u5168\u9762\u4e86\u89e3haproxy \uff08\u8d85\u8be6\u7ec6\u7248\uff09"},"content":{"rendered":"<h3>\u4e00\u3001\u4e3a\u4ec0\u4e48\u7528haproxy<\/h3>\n<p>\u5728\u8fd9\u6837\u7684\u73af\u5883\u4e2d&#xff1a;\u5982\u56fe\u6240\u793a<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"581\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250418163856-6802802010b2b.png\" width=\"859\" \/><\/p>\n<p>\u5f53\u4e00\u53f0web1\u4e3b\u673a\u6302\u6389 \u5f53\u540e\u7aef\u51fa\u73b0\u95ee\u9898\u7684\u65f6\u5019\u5e94\u8be5\u628a\u6d41\u91cf\u8fbe\u5230\u6b63\u5e38\u5de5\u4f5cweb2\u7684\u670d\u52a1\u5668\u4e0a<\/p>\n<p>\u6b64\u65f6LVS\u662f\u4e0d\u80fd\u6ee1\u8db3\u8fd9\u4e2a\u529f\u80fd\u7684\u00a0<\/p>\n<p>\u6240\u4ee5\u6b64\u65f6\u5c31\u9700\u8981\u7528\u5230haproxy<\/p>\n<\/p>\n<h3>\u4e8c\u3001haproxy-\u4e03\u5c42\u8d1f\u8f7d\u548c\u56db\u5c42\u590d\u6742\u53ca\u6b63\u53cd\u5411\u4ee3\u7406\u7684\u542b\u4e49<\/h3>\n<\/p>\n<p>\u56db\u5c42&#xff1a; 1.\u901a\u8fc7ip&#043;port\u51b3\u5b9a\u8d1f\u8f7d\u5747\u8861\u7684\u53bb\u5411\u3002 2.\u5bf9\u6d41\u91cf\u8bf7\u6c42\u8fdb\u884cNAT\u5904\u7406&#xff0c;\u8f6c\u53d1\u81f3\u540e\u53f0\u670d\u52a1\u5668\u3002 3.\u8bb0\u5f55tcp\u3001udp\u6d41\u91cf\u5206\u522b\u662f\u7531\u54ea\u53f0\u670d\u52a1\u5668\u5904\u7406&#xff0c;\u540e\u7eed\u8be5\u8bf7\u6c42\u8fde\u63a5\u7684\u6d41\u91cf\u90fd\u901a\u8fc7\u8be5\u670d\u52a1\u5668\u5904\u7406\u3002 4.\u652f\u6301\u56db\u5c42\u7684\u8f6f\u4ef6 \u25cfIvs: \u91cd\u91cf\u7ea7\u56db\u5c42\u8d1f\u8f7d\u5747\u8861\u5668\u3002 \u25cfNginx:\u8f7b\u91cf\u7ea7\u56db\u5c42\u8d1f\u8f7d\u5747\u8861\u5668&#xff0c;\u53ef\u7f13\u5b58\u3002(nginx\u56db\u5c42 \u662f\u901a\u8fc7upstream\u6a21\u5757) . Haproxy: \u6a21\u62df\u56db\u5c42\u8f6c\u53d1\u3002<\/p>\n<p>\u4e03\u5c42&#xff1a;<\/p>\n<p>\u4ee3\u7406\u529f\u80fd 1.\u901a\u8fc7\u865a\u62dfur |\u6216\u4e3b\u673aip\u8fdb\u884c\u6d41\u91cf\u8bc6\u522b&#xff0c;\u6839\u636e\u5e94\u7528\u5c42\u4fe1\u606f\u8fdb\u884c\u89e3\u6790&#xff0c;\u51b3\u5b9a\u662f\u5426\u9700\u8981\u8fdb\u884c\u8d1f\u8f7d\u5747\u8861\u3002 2.\u4ee3\u7406\u540e\u53f0\u670d\u52a1\u5668\u4e0e\u5ba2\u6237\u7aef\u5efa\u7acb\u8fde\u63a5,\u5982nginx\u53ef\u4ee3\u7406\u524d\u540e\u7aef&#xff0c;\u4e0e\u524d\u7aef\u5ba2\u6237\u7aeftcp\u8fde\u63a5,\u4e0e\u540e\u7aef\u670d\u52a1\u5668\u5efa \u7acbtcp\u8fde\u63a5, 3.\u652f\u63017\u5c42\u4ee3\u7406\u7684\u8f6f\u4ef6: \u25cfNginx:\u57fa\u4e8ehttp\u534f\u8bae(nginx\u4e03\u5c42\u662f\u901a\u8fc7proxy_ pass) \u25cf&lt; Haproxy:\u4e03\u5c42\u4ee3\u7406&#xff0c;\u4f1a\u8bdd\u4fdd\u6301\u3001\u6807\u8bb0\u3001\u8def\u5f84\u8f6c\u79fb\u7b49\u3002 \u00a0<\/p>\n<p>\u56db\u5c42\u548c\u4e03\u5c42\u7684\u533a\u522b \u6240\u8c13\u7684\u56db\u5230\u4e03\u5c42\u8d1f\u8f7d\u5747\u8861&#xff0c;\u5c31\u662f\u5728\u5bf9\u540e\u53f0\u7684\u670d\u52a1\u5668\u8fdb\u884c\u8d1f\u8f7d\u5747\u8861\u65f6&#xff0c;\u4f9d\u636e\u56db\u5c42\u7684\u4fe1\u606f\u6216\u4e03\u5c42\u7684\u4fe1\u606f\u6765\u51b3\u5b9a\u600e\u4e48\u6837\u8f6c\u53d1\u6d41\u91cf\u56db\u5c42\u7684\u8d1f\u8f7d\u5747\u8861&#xff0c;\u5c31\u662f\u901a\u8fc7\u53d1\u5e03\u4e09\u5c42\u7684IP\u5730\u5740(VIP) &#xff0c;\u7136\u540e\u52a0\u56db\u5c42\u7684\u7aef\u53e3\u53f7,\u6765\u51b3\u5b9a\u54ea\u4e9b\u6d41\u91cf\u9700\u8981\u505a\u8d1f\u8f7d\u5747\u8861&#xff0c;\u5bf9\u9700\u8981\u5904\u7406\u7684\u6d41\u91cf\u8fdb\u884cNAT\u5904\u7406&#xff0c;\u8f6c\u53d1\u81f3\u540e\u53f0\u670d\u52a1\u5668&#xff0c;\u5e76\u8bb0\u5f55\u4e0b\u8fd9\u4e2aTCP\u6216\u8005UDP\u7684\u6d41\u91cf\u662f\u7531\u54ea\u53f0\u670d\u52a1\u5668\u5904\u7406\u7684&#xff0c;\u540e\u7eed\u8fd9\u4e2a\u8fde\u63a5\u7684\u6240\u6709\u6d41\u91cf\u90fd\u540c\u6837\u8f6c\u53d1\u5230\u540c\u4e00\u53f0\u670d\u52a1\u5668\u5904\u7406\u4e03\u5c42\u7684\u8d1f\u8f7d\u5747\u8861&#xff0c;\u5c31\u662f\u5728\u56db\u5c42\u7684\u57fa\u7840\u3002\u4e0a(\u6ca1\u6709\u56db\u5c42\u662f\u7edd\u5bf9\u4e0d\u53ef\u80fd\u6709\u4e03\u5c42\u7684)&#xff0c;\u518d\u8003\u8651\u5e94\u7528\u5c42\u7684\u7279\u5f81&#xff0c;\u6bd4\u5982\u540c\u4e00-\u4e2aWeb\u670d\u52a1\u5668\u7684\u8d1f\u8f7d\u5747\u8861&#xff0c;\u9664\u4e86\u6839\u636eVIP\u52a080\u7aef\u53e3\u8fa8\u522b\u662f\u5426\u9700\u8981\u5904\u7406\u7684\u6d41\u91cf&#xff0c;\u8fd8\u53ef\u6839\u636e\u4e03\u5c42\u7684URL\u3001\u6d4f\u89c8\u5668\u7c7b\u522b\u3001\u8bed\u8a00\u6765\u51b3\u5b9a\u662f\u5426\u8981\u8fdb\u884c\u8d1f\u8f7d\u5747\u8861\u3002 1.\u5206\u5c42\u4f4d\u7f6e:\u56db\u5c42\u8d1f\u8f7d\u5747\u8861\u5728\u4f20\u8f93\u5c42\u53ca\u4ee5\u4e0b&#xff0c;\u4e03\u5c42\u8d1f\u8f7d\u5747\u8861\u5728\u5e94\u7528\u5c42\u53ca\u4ee5\u4e0b 2.\u6027\u80fd:\u56db\u5c42\u8d1f\u8f7d\u5747\u8861\u67b6\u6784\u65e0\u9700\u89e3\u6790\u62a5\u6587\u6d88\u606f\u5185\u5bb9&#xff0c;\u5728\u7f51\u7edc\u541e\u5410\u91cf\u4e0e\u5904\u7406\u80fd\u529b\u4e0a\u8f83\u9ad8:\u4e03\u5c42\u53ef\u652f\u6301\u89e3\u6790\u5e94\u7528\u5c42\u62a5\u6587\u6d88\u606f\u5185\u5bb9&#xff0c;\u8bc6\u522bURL\u3001Cookie\u3001 HTTP header\u7b49\u4fe1\u606f\u3002 3.\u539f\u7406:\u56db\u5c42\u8d1f\u8f7d\u5747\u8861\u662f\u57fa\u4e8eip&#043;port;\u4e03\u5c42\u662f\u57fa\u4e8e\u865a\u62df\u7684URL\u6216\u4e3b\u673aIP\u7b49\u3002 4.\u529f\u80fd\u7c7b\u6bd4:\u56db\u5c42\u8d1f\u8f7d\u5747\u8861\u7c7b\u4f3c\u4e8e\u8def\u7531\u5668\u4e03\u5c42\u7c7b\u4f3c\u4e8e\u4ee3\u7406\u670d\u52a1\u5668\u3002 5.\u5b89\u5168\u6027:\u56db\u5c42\u8d1f\u8f7d\u5747\u8861\u65e0\u6cd5\u8bc6\u522bDDoS\u653b\u51fb;\u4e03\u5c42\u53ef\u9632\u5fa1SYN Cookie\/Flood\u653b\u51fb \u00a0<\/p>\n<h3>\u4e09\u3001haproxy-haproxy\u7b80\u4ecb<\/h3>\n<p>HAProxy\u662f\u6cd5\u56fd\u5f00\u53d1\u8005 \u5a01\u5229\u5854\u7f57(Willy Tarreau)\u57282000\u5e74\u4f7f\u7528C\u8bed\u8a00\u5f00\u53d1\u7684\u4e00\u4e2a\u5f00\u6e90\u8f6f\u4ef6\u662f\u4e00\u6b3e\u5177\u5907\u9ad8\u5e76\u53d1(\u4e07\u7ea7\u4ee5\u4e0a)\u3001\u9ad8\u6027\u80fd\u7684TCP\u548cHTTP\u8d1f\u8f7d\u5747\u8861\u5668\u652f\u6301\u57fa\u4e8ecookie\u7684\u6301\u4e45\u6027&#xff0c;\u81ea\u52a8\u6545\u969c\u5207\u6362&#xff0c;\u652f\u6301\u6b63\u5219\u8868\u8fbe\u5f0f\u53caweb\u72b6\u6001\u7edf\u8ba1\u4f01\u4e1a\u7248\u7f51\u7ad9:https:\/\/www.haproxy.com \u793e\u533a\u7248\u7f51\u7ad9:http:\/\/www.haproxy.org github: https:\/\/github.com\/haprox \u00a0<\/p>\n<p>haproxy\u7684\u57fa\u672c\u914d\u7f6e\u4fe1\u606f HAProxy \u7684\u914d\u7f6e\u6587\u4ef6haproxy.cfg\u7531\u4e24\u5927\u90e8\u5206\u7ec4\u6210&#xff0c;\u5206\u522b\u662f: global:\u5168\u5c40\u914d\u7f6e\u6bb5 \u8fdb\u7a0b\u53ca\u5b89\u5168\u914d\u7f6e\u76f8\u5173\u7684\u53c2\u6570 \u00b7\u6027\u80fd\u8c03\u6574\u76f8\u5173\u53c2\u6570 Debug\u53c2\u6570 proxies:\u4ee3\u7406\u914d\u7f6e\u6bb5 defaults:\u4e3afrontend,backend,listen\u63d0\u4f9b\u9ed8\u8ba4\u914d\u7f6e frontend:\u524d\u7aef&#xff0c;\u76f8\u5f53\u4e8enginx\u4e2d\u7684server{} backend:\u540e\u7aef&#xff0c;\u76f8\u5f53\u4e8enginx\u4e2d\u7684upstream0 listen:\u540c\u65f6\u62e5\u6709\u524d\u7aef\u548c\u540e\u7aef\u914d\u7f6e,\u914d\u7f6e\u7b80\u5355,\u751f\u4ea7\u63a8\u8350\u4f7f\u7528<\/p>\n<h3><\/h3>\n<h3>\u56db\u3001haproxy-\u5b9e\u9a8c\u73af\u5883\u7684\u90e8\u7f72\u65b9\u6cd5<\/h3>\n<p>haproxy<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"98\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250418163856-6802802044ba3.png\" width=\"557\" \/><\/p>\n<p>websever1<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"249\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250418163856-6802802059233.png\" width=\"543\" \/><\/p>\n<p>dnf install nginx -y \u4e0b\u8f7d\u670d\u52a1&#xff01;<\/p>\n<p>\u00a0echo webserver -172.25.254.10 &gt; \/usr\/share\/nginx\/html\/index.html<\/p>\n<p>systemctl enable &#8211;now nginx<\/p>\n<p>webserver2<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"127\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250418163856-6802802070ea3.png\" width=\"596\" \/><\/p>\n<p>dnf install nginx -y<\/p>\n<p>\u00a0echo webserver -172.25.254.20 &gt; \/usr\/share\/nginx\/html\/index.html<\/p>\n<p>systemctl enable &#8211;now nginx<\/p>\n<p>(2)\u6240\u6709\u4e3b\u673a\u5173\u95ed\u9632\u706b\u5899 \u5c06selinux\u8bbe\u7f6e\u4e3a\u5bbd\u5bb9\u6a21\u5f0f<\/p>\n<p>\u00a0\u5173\u95ed\u9632\u706b\u5899<\/p>\n<p>systemctl stop firewalld systemctl mask firewalld<\/p>\n<p>\u914d\u7f6eselinux setenforce 0<\/p>\n<p>\u4ee5\u4e0a\u73af\u5883\u5c31\u914d\u7f6e\u5b8c\u6210\u5566&#xff01;<\/p>\n<\/p>\n<h3>\u4e94\u3001haproxy-haproxy\u7684\u57fa\u672c\u90e8\u7f72\u65b9\u6cd5\u53ca\u8d1f\u8f7d\u5747\u8861\u7684\u5b9e\u73b0<\/h3>\n<p>\u51c6\u5907\u4e09\u53f0\u4e3b\u673a<\/p>\n<p>dnf install haproxy -y<\/p>\n<p>rpm -qc haproxy \u67e5\u627e\u914d\u7f6e\u6587\u4ef6<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"117\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250418163856-6802802085af4.png\" width=\"405\" \/> vim \/etc\/haproxy\/haproxy.cfg\u00a0 \u7f16\u8f91\u914d\u7f6e\u6587\u4ef6<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"496\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250418163856-680280209a961.png\" width=\"1045\" \/><\/p>\n<p>\u6b64\u65f6\u53ef\u4ee5\u5c06web1\u7684ngnix\u7684\u670d\u52a1\u505c\u6389<\/p>\n<p>systemctl stop ngnix<\/p>\n<p>\u8bbf\u95ee172.25.254.100<\/p>\n<p>\u53ef\u4ee5\u53d1\u73b0\u6d41\u91cf\u90fd\u5230web2\u7684\u4e3b\u673a\u4e0a<\/p>\n<h3><\/h3>\n<h3>\u516d\u3001haproxy-haproxy\u7684\u5168\u5c40\u914d\u7f6e\u53c2\u6570\u53ca\u65e5\u5fd7\u5206\u79bb<\/h3>\n<p>\u8bbe\u7f6e\u591a\u8fdb\u7a0b<\/p>\n<p>pstree -p |grep haproxy<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"88\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250418163856-68028020db86c.png\" width=\"890\" \/><\/p>\n<p>vim \/etc\/haproxy\/haproxy.cfg\u00a0 \u7f16\u8f91\u914d\u7f6e\u6587\u4ef6<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"122\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250418163856-68028020f3e95.png\" width=\"536\" \/><\/p>\n<p>systemctl restart haproxy \u91cd\u542f\u670d\u52a1<\/p>\n<p>pstree -p |grep haproxy<img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"91\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250418163857-6802802115081.png\" width=\"581\" \/><\/p>\n<p>vim \/etc\/haproxy\/haproxy.cfg\u00a0 \u7f16\u8f91\u914d\u7f6e\u6587\u4ef6<img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"228\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250418163857-6802802129892.png\" width=\"616\" \/><\/p>\n<p>systemctl restart haproxy<\/p>\n<p>\u67e5\u770b\u591a\u7ebf\u7a0b<\/p>\n<p>cat \/proc\/3112\/status \u00a0|grep -i thread<img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"96\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250418163857-6802802142f77.png\" width=\"723\" \/><\/p>\n<p>\u6ce8\u610f\u8fd9\u91cc\u53ea\u80fd\u591a\u7ebf\u7a0b\u8ddf\u591a\u8fdb\u7a0b\u53ea\u80fd\u5f00\u542f\u4e00\u4e2a \u4e0d\u80fd\u540c\u65f6\u542f\u52a8 vim \/etc\/haproxy\/haproxy.cfg\u00a0 \u7f16\u8f91\u914d\u7f6e\u6587\u4ef6<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"544\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250418163857-6802802157589.png\" width=\"817\" \/> systemctl restart haproxy \u91cd\u542f\u670d\u52a1<\/p>\n<p>\u00a0 \u00a0vim \/etc\/rsyslog.conf<img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"140\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250418163857-680280218a173.png\" width=\"811\" \/> \u00a0systemctl restart rsyslog.service<\/p>\n<\/p>\n<h3>\u4e03\u3001haproxy-haproxy\u4e2d\u7684\u5e38\u7528\u914d\u7f6e\u53c2\u6570<\/h3>\n<p>haproxy\u4e3b\u673a&#xff1a;<\/p>\n<p>vim \/etc\/haproxy\/haproxy.cfg\u00a0 \u7f16\u8f91\u914d\u7f6e\u6587\u4ef6<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"221\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250418163857-68028021a4ef9.png\" width=\"920\" \/><\/p>\n<p>\u4e0b\u8f7dhttpd\u670d\u52a1<\/p>\n<p>dnf install httpd -y<\/p>\n<p>\u6b64\u65f6\u5148\u4e0d\u8981\u542f\u52a8httpd\u670d\u52a1&#xff01;<\/p>\n<p>\u5148\u8fdb\u5165\/etc\/hhtpd\/conf\/httpd.conf \u6587\u4ef6\u4e2d \u5c0680\u7aef\u53e3\u6539\u4e3a8080<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"106\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250418163857-68028021c4d62.png\" width=\"474\" \/><\/p>\n<p>\u6b64\u65f6\u5c31\u53ef\u4ee5\u91cd\u542fhttpd \u670d\u52a1\u5566<\/p>\n<p>systemctl restart httpd<\/p>\n<p>\u00a0\u7ed3\u679c&#xff1a;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"50\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250418163857-68028021d962c.png\" width=\"603\" \/><\/p>\n<p>\u4e0b\u7ebf\u6307\u5b9arealserver<\/p>\n<p>vim \/etc\/haproxy\/haproxy.cfg\u00a0 \u7f16\u8f91\u914d\u7f6e\u6587\u4ef6<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"229\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250418163857-68028021ec3ee.png\" width=\"995\" \/><\/p>\n<p>\u7ed3\u679c;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"166\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250418163858-6802802217268.png\" width=\"548\" \/><\/p>\n<p>\u8bbf\u95ee\u91cd\u5b9a\u5411<\/p>\n<p>vim \/etc\/haproxy\/haproxy.cfg\u00a0 \u7f16\u8f91\u914d\u7f6e\u6587\u4ef6<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"166\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250418163858-680280222dfe9.png\" width=\"797\" \/><\/p>\n<p>systemctl restart haproxy<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"82\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250418163858-680280224aee8.png\" width=\"677\" \/><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"528\" src=\"2025-04-19vasnzuis4n2.png\" width=\"1092\" \/><\/p>\n<\/p>\n<h3 style=\"background-color:transparent\">\u516b\u3001haproxy-haproxy\u70ed\u66f4\u65b0\u65b9\u6cd5<\/h3>\n<p>\u00a0dnf install socat -y<\/p>\n<p>vim \/etc\/haproxy\/haproxy.cfg\u00a0 \u7f16\u8f91\u914d\u7f6e\u6587\u4ef6<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"97\" src=\"2025-04-19oa13hwgjap2.png\" width=\"827\" \/><\/p>\n<p>echo get weight webcluster\/web1 | socat stdio \/var\/lib\/haproxy\/stats \u770b\u5f53\u524d\u72b6\u6001\u7684\u6743\u91cd<\/p>\n<p>echo &#034;set weight webcluster\/web1 1&#034; | socat stdio \/var\/lib\/haproxy\/stats \u66f4\u6539web1\u7684\u6743\u91cd\u4e3a1<\/p>\n<p>echo get weight webcluster\/web1 | socat stdio \/var\/lib\/haproxy\/stats \u518d\u67e5\u770b\u5f53\u524d\u7684\u6743\u91cd<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"101\" src=\"2025-04-19tlj4brfy40y.png\" width=\"1057\" \/><\/p>\n<p>echo &#039;get\u00a0servers\u00a0state&#039; |\u00a0socat\u00a0stdio\u00a0\/var\/lib\/haproxy\/stats echo &#039;show\u00a0servers\u00a0state&#039;\u00a0|\u00a0socat\u00a0stdio\u00a0\/var\/lib\/haproxy\/stats<\/p>\n<p>\u8ba9web1\u4e0b\u7ebf echo &#034;disable\u00a0server\u00a0webcluster\/web1&#034;\u00a0|\u00a0socat\u00a0stdio\u00a0\/var\/lib\/haproxy\/stats<\/p>\n<p>\u591a\u8fdb\u7a0b\u5982\u4f55\u70ed\u5904\u7406<\/p>\n<p>vim \/etc\/haproxy\/haproxy.cfg\u00a0 \u7f16\u8f91\u914d\u7f6e\u6587\u4ef6<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"277\" src=\"2025-04-19sdvqtyawgrg.png\" width=\"895\" \/><\/p>\n<p>echo &#039;show info &#039;\u00a0|\u00a0socat\u00a0stdio\u00a0\/var\/lib\/haproxy\/stats1<\/p>\n<p>echo &#039;show info &#039;\u00a0|\u00a0socat\u00a0stdio\u00a0\/var\/lib\/haproxy\/stats2<\/p>\n<h3>\u4e5d\u3001haproxy-haproxy\u7684\u7b97\u6cd5<\/h3>\n<p> uri 1.\u57fa\u4e8e\u5bf9\u7528\u6237\u8bf7\u6c42\u7684URI\u7684\u5de6\u534a\u90e8\u5206\u6216\u6574\u4e2auri\u505ahash&#xff0c;\u518d\u5c06hash\u7ed3\u679c\u5bf9\u603b\u6743\u91cd\u8fdb\u884c\u53d6\u6a21\u540e 2.\u6839\u636e\u6700\u7ec8\u7ed3\u679c\u5c06\u8bf7\u6c42\u8f6c\u53d1\u5230\u540e\u7aef\u6307\u5b9a\u670d\u52a1\u5668 3.\u9002\u7528\u4e8e\u540e\u7aef\u662f\u7f13\u5b58\u670d\u52a1\u5668\u573a\u666f 4.\u9ed8\u8ba4\u662f\u9759\u6001\u7b97\u6cd5&#xff0c;\u4e5f\u53ef\u4ee5\u901a\u8fc7hash-type\u6307\u5b9amap-based\u548cconsistent&#xff0c;\u6765\u5b9a\u4e49\u4f7f\u7528\u53d6\u6a21\u6cd5\u8fd8\u662f\u4e00\u81f4\u6027hash source \u6e90\u5730\u5740hash&#xff0c;\u57fa\u4e8e\u7528\u6237\u6e90\u5730\u5740hash\u5e76\u5c06\u8bf7\u6c42\u8f6c\u53d1\u5230\u540e\u7aef\u670d\u52a1\u5668&#xff0c;\u540e\u7eed\u540c\u4e00\u4e2a\u6e90\u5730\u5740\u8bf7\u6c42\u5c06\u88ab\u8f6c\u53d1\u81f3\u540c-\u4e2a\u540e\u7aefweb\u670d\u52a1\u5668\u3002\u6b64\u65b9\u5f0f\u5f53\u540e\u7aef\u670d\u52a1\u5668\u6570\u636e\u91cf\u53d1\u751f\u53d8\u5316\u65f6&#xff0c;\u4f1a\u5bfc\u81f4\u5f88\u591a\u7528\u6237\u7684\u8bf7\u6c42\u8f6c\u53d1\u81f3\u65b0\u7684\u540e\u7aef\u670d\u52a1\u5668&#xff0c;\u9ed8\u8ba4\u4e3a\u9759\u6001\u65b9\u5f0f&#xff0c;\u4f46\u662f\u53ef\u4ee5\u901a\u8fc7hash-type\u652f\u6301\u7684\u9009\u9879\u66f4\u6539\u8fd9\u4e2a\u7b97\u6cd5\u4e00\u822c\u662f\u5728\u4e0d\u63d2\u5165Cookie\u7684TCP\u6a21\u5f0f\u4e0b\u4f7f\u7528&#xff0c;\u4e5f\u53ef\u7ed9\u62d2\u7edd\u4f1a\u8bddcookie\u7684\u5ba2\u6237\u63d0\u4f9b\u6700\u597d\u7684\u4f1a\u8bdd\u7c98\u6027&#xff0c;\u9002\u7528\u4e8esession\u4f1a\u8bdd\u4fdd\u6301\u4f46\u4e0d\u652f\u6301cookie\u548c\u7f13\u5b58\u7684\u573a\u666f\u6e90\u5730\u5740\u6709\u4e24\u79cd\u8f6c\u53d1\u5ba2\u6237\u7aef\u8bf7\u6c42\u5230\u540e\u7aef\u670d\u52a1\u5668\u7684\u670d\u52a1\u5668\u9009\u53d6\u8ba1\u7b97\u65b9\u5f0f&#xff0c;\u5206\u522b\u662f\u53d6\u6a21\u6cd5\u548c\u4e00\u81f4\u6027hash leastconn&#xff1a;#\u6570\u636e\u5e93 1.leastconn\u52a0\u6743\u7684\u6700\u5c11\u8fde\u63a5\u7684\u52a8\u6001 2.\u652f\u6301\u6743\u91cd\u7684\u8fd0\u884c\u65f6\u8c03\u6574\u548c\u6162\u542f\u52a8&#xff0c;\u5373:\u6839\u636e\u5f53\u524d\u8fde\u63a5\u6700\u5c11\u7684\u540e\u7aef\u670d\u52a1\u5668\u800c\u975e\u6743\u91cd\u8fdb\u884c\u4f18\u5148\u8c03\u5ea6(\u65b0\u5ba2\u6237\u7aef\u8fde\u63a5) 3.\u6bd4\u8f83\u9002\u5408\u957f\u8fde\u63a5\u7684\u573a\u666f\u4f7f\u7528&#xff0c;\u6bd4\u5982:MySQL\u7b49\u573a\u666f roundrobin 1.\u57fa\u4e8e\u6743\u91cd\u7684\u8f6e\u8be2\u52a8\u6001\u8c03\u5ea6\u7b97\u6cd5 2.\u652f\u6301\u6743\u91cd\u7684\u8fd0\u884c\u65f6\u8c03\u6574&#xff0c;\u4e0d\u540c\u4e8eIvs\u4e2d\u7684rr\u8f6e\u8bad\u6a21\u5f0f 3.HAProxy\u4e2d\u7684roundrobin\u652f\u6301\u6162\u542f\u52a8(\u65b0\u52a0\u7684\u670d\u52a1\u5668\u4f1a\u9010\u6e10\u589e\u52a0\u8f6c\u53d1\u6570) 4.\u5176\u6bcf\u4e2a\u540e\u7aefbackend\u4e2d\u6700\u591a\u652f\u63014095\u4e2areal server, 5.\u652f\u6301\u5bf9real server\u6743\u91cd\u52a8\u6001\u8c03\u6574&#xff0c; 6.roundrobin\u4e3a\u9ed8\u8ba4\u8c03\u5ea6\u7b97\u6cd5,\u6b64\u7b97\u6cd5\u4f7f\u7528\u5e7f\u6cdb<\/p>\n<p>static-rr&#xff1a;#\u9002\u7528\u4e8e\u505a\u4e86session\u5171\u4eab\u7684web\u96c6\u7fa4 \u4e0d\u652f\u6301\u6162\u542f\u52a8(\u5f00\u542f\u4e4b\u540e\u6d41\u91cf\u6162\u6162\u7ed9) \u652f\u6301\u6743\u91cd \u4e0d\u652f\u6301\u4fee\u6539\u6743\u91cd balance static-rr first&#xff1a;#\u4f7f\u7528\u8f83\u5c11 balance first \u81ea\u4e0a\u800c\u4e0b\u8fdb\u884c\u8c03\u7528 \u5f53\u4e00\u53f0\u7684\u670d\u52a1\u5668\u8fbe\u5230\u4e86\u4e0a\u9650 \u624d\u4f1a\u7ed9\u4e0b\u4e00\u53f0 \u4e0d\u652f\u6301\u4fee\u6539\u6743\u91cd \u4e0d\u652f\u6301socat\u5de5\u5177\u8fdb\u884c\u663e\u793a \u6bd4\u5982get set disable enable<\/p>\n<p>\u5b9e\u9a8c&#xff1a; static-rr<\/p>\n<p>vim \/etc\/haproxy\/haproxy.cfg\u00a0 \u7f16\u8f91\u914d\u7f6e\u6587\u4ef6<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"244\" src=\"2025-04-19cgthbjpv2ed.png\" width=\"876\" \/><\/p>\n<p>vim \/etc\/haproxy\/haproxy.cfg\u00a0 \u7f16\u8f91\u914d\u7f6e\u6587\u4ef6<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"97\" src=\"2025-04-19oa13hwgjap2.png\" width=\"827\" \/><\/p>\n<p>echo &#034;set weight webcluster\/web1 1&#034; | socat stdio \/var\/lib\/haproxy\/stats.<\/p>\n<p>\u6b64\u65f6\u4e0d\u80fd\u66f4\u6539\u6743\u91cd<\/p>\n<p>first<\/p>\n<p>vim \/etc\/haproxy\/haproxy.cfg\u00a0 \u7f16\u8f91\u914d\u7f6e\u6587\u4ef6<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"266\" src=\"2025-04-1901s03dugt1e.png\" width=\"978\" \/><\/p>\n<p>\u5728\u591a\u53f0\u4e3b\u673a\u4e2d\u6267\u884c\u6b7b\u5faa\u73af\u6d4b\u8bd5\u6548\u679c<\/p>\n<p>\u5229\u7528\u547d\u4ee4 while ture;do curl 172.25.254.100;sleep 0.1;done<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"344\" src=\"2025-04-192agf02ooyd3.png\" width=\"935\" \/><\/p>\n<p>vim \/etc\/haproxy\/haproxy.cfg\u00a0 \u7f16\u8f91\u914d\u7f6e\u6587\u4ef6<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"305\" src=\"2025-04-19ueqvygoq0yc.png\" width=\"981\" \/><\/p>\n<p>vim \/etc\/haproxy\/haproxy.cfg\u00a0 \u7f16\u8f91\u914d\u7f6e\u6587\u4ef6<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"512\" src=\"2025-04-19ynbtdcbtqjp.png\" width=\"1038\" \/><\/p>\n<p>vim \/etc\/haproxy\/haproxy.cfg\u00a0 \u7f16\u8f91\u914d\u7f6e\u6587\u4ef6<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"232\" src=\"2025-04-19uy4t1sj1zit.png\" width=\"865\" \/><\/p>\n<h3>\u5341\u3001haproxy-haproxy\u7684\u72b6\u6001\u9875\u9762\u76d1\u63a7<\/h3>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"216\" src=\"2025-04-19zltlf3ciqfu.png\" width=\"328\" \/><\/p>\n<p>systemctl restart haproxy<\/p>\n<p>\u8bb0\u4f4f\u5173\u95edselinux!! \u4e0d\u7136haproxy\u670d\u52a1\u542f\u52a8\u4e0d\u4e86<\/p>\n<p>\u8bbf\u95ee 172.25.254.100&#xff1a;9999<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"930\" src=\"2025-04-19qbm21q12tvf.png\" width=\"1200\" \/><\/p>\n<\/p>\n<h3>\u5341 \u4e00\u3001haproxy-\u57fa\u4e8ecookie\u7684\u4f1a\u8bdd\u4fdd\u6301<\/h3>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"297\" src=\"2025-04-19pf3v41yu0gg.png\" width=\"1010\" \/><\/p>\n<p>curl -b WEBCOOKIE&#061;lee1 172.25.254.100<\/p>\n<p>curl -b WEBCOOKIE&#061;lee1 172.25.254.100<\/p>\n<p>\u6765\u8fdb\u884c\u6d4b\u8bd5<\/p>\n<\/p>\n<h3>\u5341 \u4e8c\u3001haproxy-ip\u900f\u4f20\u6280\u672f<\/h3>\n<p>\u5728web1\u4e2d\u4e0b\u8f7dhttpd\u670d\u52a1<\/p>\n<p>dnf insatll httpd -y<\/p>\n<p>vim \/etc\/httpd\/conf\/httpd.conf<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"387\" src=\"2025-04-19ogizkychmzl.png\" width=\"1200\" \/><\/p>\n<p>vim \/etc\/haproxy\/haproxy.cfg\u00a0 \u7f16\u8f91\u914d\u7f6e\u6587\u4ef6<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"137\" src=\"2025-04-19my0u1vwdwsv.png\" width=\"1200\" \/><\/p>\n<p>\u5176\u4e2dweb1\u4e3ahttpd\u670d\u52a1 web2\u4e3angnix\u670d\u52a1<\/p>\n<p>\u7ed3\u679c&#xff1a;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"154\" src=\"2025-04-19w4w2u4ipmfx.png\" width=\"664\" \/><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"312\" src=\"2025-04-19043weoeqauk.png\" width=\"645\" \/><\/p>\n<\/p>\n<h3 style=\"background-color:transparent\">\u5341 \u4e09\u3001 haproxy-haproxy\u7684\u8bbf\u95ee\u63a7\u5236\u5217\u8868\u4ee5\u53ca\u5229\u7528acl\u505a\u52a8\u9759\u5206\u79bb\u7b49\u8bbf\u95ee\u63a7\u5236<\/h3>\n<p>\u4ee5bbs\u5f00\u5934&#xff1a;<\/p>\n<p>vim \/etc\/haproxy\/haproxy.cfg\u00a0 \u7f16\u8f91\u914d\u7f6e\u6587\u4ef6<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"359\" src=\"2025-04-19x1zyo01tutc.png\" width=\"756\" \/><\/p>\n<p>\u5728windows\u4e2d\u505a\u57df\u540d\u89e3\u6790<\/p>\n<p>C:\\\\Windows\\\\System32\\\\drivers\\\\etc \u7684hosts\u6587\u4ef6\u4e2d\u8fdb\u884c\u66f4\u6539<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"162\" src=\"2025-04-19gw2lvn1dvsf.png\" width=\"662\" \/><\/p>\n<p>\u6d4b\u8bd5\u4e00\u4e0b\u7ed3\u679c&#xff1a;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"290\" src=\"2025-04-19lgynvevfafc.png\" width=\"429\" \/><\/p>\n<p>\u00a0\u5176\u4e2dweb1\u4e3ahttpd\u670d\u52a1 web2\u4e3angnix\u670d\u52a1<\/p>\n<p>\u57fa\u4e8e\u57df\u540d\u8bbf\u95ee&#xff1a;<\/p>\n<p>vim \/etc\/haproxy\/haproxy.cfg\u00a0 \u7f16\u8f91\u914d\u7f6e\u6587\u4ef6<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"536\" src=\"2025-04-19m4kwn2wakvi.png\" width=\"895\" \/><\/p>\n<\/p>\n<p>\u5728windows\u4e2d\u505a\u57df\u540d\u89e3\u6790<\/p>\n<p>C:\\\\Windows\\\\System32\\\\drivers\\\\etc \u7684hosts\u6587\u4ef6\u4e2d\u8fdb\u884c\u66f4\u6539<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"95\" src=\"2025-04-19bhhrc550txf.png\" width=\"392\" \/><\/p>\n<p>\u57fa\u4e8eip<\/p>\n<p>vim \/etc\/haproxy\/haproxy.cfg\u00a0 \u7f16\u8f91\u914d\u7f6e\u6587\u4ef6<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"343\" src=\"2025-04-19zwdvpr2zdwp.png\" width=\"1051\" \/><\/p>\n<p>vim \/etc\/haproxy\/haproxy.cfg\u00a0 \u7f16\u8f91\u914d\u7f6e\u6587\u4ef6<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"599\" src=\"2025-04-19sso0n4a0ykf.png\" width=\"857\" \/><\/p>\n<\/p>\n<p>webserver1 \u4e2d\u4e0b\u8f7dphp\u670d\u52a1<\/p>\n<p>vim \/var\/www\/html\/index.php<\/p>\n<h3><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"109\" src=\"2025-04-19gb3nsc0xf43.png\" width=\"634\" \/><\/h3>\n<p>\u52a8\u9759\u5206\u79bb&#xff1a;<\/p>\n<p>vim \/etc\/haproxy\/haproxy.cfg\u00a0 \u7f16\u8f91\u914d\u7f6e\u6587\u4ef6<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"535\" src=\"2025-04-19xnokyq0g2la.png\" width=\"831\" \/><\/p>\n<p>vim \/etc\/haproxy\/haproxy.cfg\u00a0 \u7f16\u8f91\u914d\u7f6e\u6587\u4ef6<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"441\" src=\"2025-04-19lclg3rd5ooz.png\" width=\"805\" \/><\/p>\n<p>\u7f16\u8f91\u5b8c\u914d\u7f6e\u6587\u4ef6\u540e\u8bb0\u5f97\u91cd\u542fhaproxy\u670d\u52a1<\/p>\n<h3>\u5341 \u56db\u3001\u81ea\u52a8\u9519\u8bef\u9875\u9762\u5185\u5bb9<\/h3>\n<p>\u5b9e\u9a8c\u601d\u8def;<\/p>\n<p>\u67e5\u627e\u4e00\u4e0b\u9519\u8bef\u6587\u4ef6\u5728\u54ea\u91cc<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"234\" src=\"2025-04-19arnmy4mlksj.png\" width=\"576\" \/><\/p>\n<p>\u521b\u5efa\u4e00\u4e2a\u76ee\u5f55\u4e3a \/etc\/haproxy\/errorpage\/503.http<\/p>\n<p>mkdir -p\u00a0 \u00a0\/etc\/haproxy\/errorpage\/503.http<\/p>\n<p>\u7136\u540e\u5c06\/usr\/share\/haproxy\/503.http \u4e2d\u7684\u5185\u5bb9\u590d\u5236\u5728\u521b\u5efa\u7684\u76ee\u5f55\u4e2d<\/p>\n<p>cp \/usr\/share\/haproxy\/503.http\u00a0\u00a0 \/etc\/haproxy\/errorpage\/503.http<\/p>\n<p>vim \/etc\/haproxy\/errorpage\/503.http \u7f16\u8f91\u5185\u5bb9<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"231\" src=\"2025-04-19wjbqzp3jldp.png\" width=\"633\" \/><\/p>\n<p>vim \/etc\/haproxy\/haproxy.cfg\u00a0 \u7f16\u8f91\u914d\u7f6e\u6587\u4ef6<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"260\" src=\"2025-04-19l0ffni4ohxs.png\" width=\"838\" \/><\/p>\n<\/p>\n<h3>\u5341 \u4e94\u3001haproxy-haproxy\u7684\u56db\u5c42\u8d1f\u8f7d\u793a\u4f8b<\/h3>\n<p>\u5728web1.2\u5206\u522b\u4e0b\u8f7dmysql\u670d\u52a1&#xff1a;dnf install mariadb -y<\/p>\n<p>dnf install mariadb-server -y<\/p>\n<p>(\u5185\u5305\u542b\u4e00\u4e2amariadb-server \u8981\u5b58\u5728\u8fd9\u4e2a\u5305\u624d\u53ef\u4ee5\u542f\u52a8\u670d\u52a1)<\/p>\n<p>webserver1&#xff1a;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"196\" src=\"2025-04-19puxvuruqa3i.png\" width=\"516\" \/><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"439\" src=\"2025-04-19wpp41w5cj3z.png\" width=\"812\" \/><\/p>\n<p>webserver2&#xff1a;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"184\" src=\"2025-04-190eddyvvczvm.png\" width=\"529\" \/><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"452\" src=\"2025-04-1955fauthkakr.png\" width=\"812\" \/><\/p>\n<\/p>\n<p>haproxy\u8fde\u63a510\u4e3b\u673a\u7684mysql&#xff1a;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"95\" src=\"2025-04-19rhxynzcutcz.png\" width=\"916\" \/><\/p>\n<p>\u8bf4\u660e\u6ca1\u6709\u8bbe\u7f6e10\u4e3b\u673a\u53ef\u4ee5\u8fdc\u7a0b\u767b\u5f55<\/p>\n<p>\u8fdb\u884c172.25.254.10\u4e0e172.25.254.20\u4e3b\u673a\u8fdc\u7a0b\u767b\u5f55&#xff1a;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"490\" src=\"2025-04-19omac345xsq4.png\" width=\"731\" \/><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"290\" src=\"2025-04-19nmjbejjdvgs.png\" width=\"919\" \/><\/p>\n<\/p>\n<p>vim \/etc\/haproxy\/haproxy.cfg<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"396\" src=\"2025-04-19wp4hrklifn2.png\" width=\"890\" \/><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"260\" src=\"2025-04-19wmsnqvqafos.png\" width=\"865\" \/><\/p>\n<\/p>\n<p>\u8fdb\u884c\u4f9d\u6b21\u67e5\u770b\u4e09\u53f0\u4e3b\u673a \u4f1a\u663e\u793arr\u8f6e\u8be2\u72b6\u6001<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"536\" src=\"2025-04-19dus2vubeswq.png\" width=\"890\" \/><\/p>\n<h3><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"471\" src=\"2025-04-191m4b1hczszq.png\" width=\"896\" \/><\/h3>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"517\" src=\"2025-04-19trlxkoaxb1w.png\" width=\"901\" \/><\/p>\n<h3>\u5341 \u516d\u3001haproxy-https\u52a0\u5bc6<\/h3>\n<p>1.\u5236\u4f5c\u8bc1\u4e66<\/p>\n<p>\u5148\u521b\u5efa\u4e00\u4e2a\u76ee\u5f55<\/p>\n<p>mkdir -p \/etc\/haproxy\/certs<\/p>\n<p>\u5236\u4f5c\u8bc1\u4e66 openssl req -newkey rsa:2048 -nodes -sha256 -keyout \u00a0\/etc\/haproxy\/certs\/timinglee.org.key -x509 -days 365 -out \/etc\/haproxy\/certs\/timinglee.org.crt<\/p>\n<p> \u5c06\u5bc6\u94a5\u653e\u5728\/etc\/haproxy\/certs\/timinglee.pem\u8fd9\u4e2a\u76ee\u5f55\u4e0b cat \/etc\/haproxy\/certs\/timinglee.org.key \/etc\/haproxy\/certs\/timinglee.org.crt &gt; \/etc\/haproxy\/certs\/timinglee.pem<\/p>\n<p>\u00a0\u7f16\u8f91\u914d\u7f6e\u6587\u4ef6\u7f16\u8f91\u914d\u7f6e\u6587\u4ef6vim \/etc\/haproxy\/haproxy.cfg\u00a0 &#xff1a;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"260\" src=\"2025-04-19fterou1mjfk.png\" width=\"875\" \/><\/p>\n<\/p>\n<p>\u67e5\u770b\u7aef\u53e3&#xff1a;<\/p>\n<p>netstat -antlupe |grep haproxy<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"83\" src=\"2025-04-19gv5hlwbv13m.png\" width=\"1200\" \/><\/p>\n<p>\u91cd\u542fweb1 \u4e0eweb2 \u7684\u670d\u52a1<\/p>\n<p>systemctl restart httpd\u00a0 systemctl restart ngnix<\/p>\n<p>\u8bbf\u95eehttps:\/\/172.25.254.100<\/p>\n<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"801\" src=\"2025-04-19boal2sugjwt.png\" width=\"1200\" \/><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"843\" src=\"2025-04-19csjs4trjc3d.png\" width=\"1085\" \/><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"336\" src=\"2025-04-19qmpwwdm00a1.png\" width=\"779\" \/><\/p>\n<p>\u5168\u7ad9\u52a0\u5bc6&#xff1a;<\/p>\n<p>vim \/etc\/haproxy\/haproxy.cfg\u00a0<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"378\" src=\"2025-04-19sb4rw42iiz3.png\" width=\"788\" \/><\/p>\n<p>\u00a0 systemctl restart haproxy.service\u00a0<\/p>\n<p>\u901a\u8fc7http\u7684\u65b9\u5f0f\u8fdb\u884c\u8bbf\u95ee<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"165\" src=\"2025-04-19evgkzq454rg.png\" width=\"646\" \/><\/p>\n<p>\u4f1a\u81ea\u52a8\u8df3\u8f6c\u5230https\u00a0 \u8fd9\u5c31\u662f\u5168\u7ad9\u52a0\u5bc6<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"138\" src=\"2025-04-19omh2zmier53.png\" width=\"729\" \/><\/p>\n<p>\u5230\u8fd9\u91cc\u5206\u4eab\u5c31\u7ed3\u675f\u5566!!!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb2.2k\u6b21\uff0c\u70b9\u8d5e25\u6b21\uff0c\u6536\u85cf20\u6b21\u3002HAProxy\u662f\u6cd5\u56fd\u5f00\u53d1\u8005 \u5a01\u5229\u5854\u7f57(Willy Tarreau)\u57282000\u5e74\u4f7f\u7528C\u8bed\u8a00\u5f00\u53d1\u7684\u4e00\u4e2a\u5f00\u6e90\u8f6f\u4ef6\u662f\u4e00\u6b3e\u5177\u5907\u9ad8\u5e76\u53d1(\u4e07\u7ea7\u4ee5\u4e0a)\u3001\u9ad8\u6027\u80fd\u7684TCP\u548cHTTP\u8d1f\u8f7d\u5747\u8861\u5668\u652f\u6301\u57fa\u4e8ecookie\u7684\u6301\u4e45\u6027\uff0c\u81ea\u52a8\u6545\u969c\u5207\u6362\uff0c\u652f\u6301\u6b63\u5219\u8868\u8fbe\u5f0f\u53caweb\u72b6\u6001\u7edf\u8ba1\u4f01\u4e1a\u7248\u7f51\u7ad9:https:\/\/www.haproxy.com\u793e\u533a\u7248\u7f51\u7ad9:http:\/\/www.haproxy.orghaproxy\u7684\u57fa\u672c\u914d\u7f6e\u4fe1\u606fHAProxy \u7684\u914d\u7f6e\u6587\u4ef6haproxy.cfg\u7531\u4e24\u5927\u90e8\u5206\u7ec4\u6210\uff0c\u5206\u522b\u662f:global:\u5168\u5c40\u914d\u7f6e\u6bb5\u3002_haproxy<\/p>\n","protected":false},"author":2,"featured_media":18238,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[43,44],"topic":[],"class_list":["post-18258","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-server","tag-43","tag-44"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>\u5e26\u4f60\u5168\u9762\u4e86\u89e3haproxy \uff08\u8d85\u8be6\u7ec6\u7248\uff09 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/18258.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"\u5e26\u4f60\u5168\u9762\u4e86\u89e3haproxy \uff08\u8d85\u8be6\u7ec6\u7248\uff09 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb2.2k\u6b21\uff0c\u70b9\u8d5e25\u6b21\uff0c\u6536\u85cf20\u6b21\u3002HAProxy\u662f\u6cd5\u56fd\u5f00\u53d1\u8005 \u5a01\u5229\u5854\u7f57(Willy Tarreau)\u57282000\u5e74\u4f7f\u7528C\u8bed\u8a00\u5f00\u53d1\u7684\u4e00\u4e2a\u5f00\u6e90\u8f6f\u4ef6\u662f\u4e00\u6b3e\u5177\u5907\u9ad8\u5e76\u53d1(\u4e07\u7ea7\u4ee5\u4e0a)\u3001\u9ad8\u6027\u80fd\u7684TCP\u548cHTTP\u8d1f\u8f7d\u5747\u8861\u5668\u652f\u6301\u57fa\u4e8ecookie\u7684\u6301\u4e45\u6027\uff0c\u81ea\u52a8\u6545\u969c\u5207\u6362\uff0c\u652f\u6301\u6b63\u5219\u8868\u8fbe\u5f0f\u53caweb\u72b6\u6001\u7edf\u8ba1\u4f01\u4e1a\u7248\u7f51\u7ad9:https:\/\/www.haproxy.com\u793e\u533a\u7248\u7f51\u7ad9:http:\/\/www.haproxy.orghaproxy\u7684\u57fa\u672c\u914d\u7f6e\u4fe1\u606fHAProxy \u7684\u914d\u7f6e\u6587\u4ef6haproxy.cfg\u7531\u4e24\u5927\u90e8\u5206\u7ec4\u6210\uff0c\u5206\u522b\u662f:global:\u5168\u5c40\u914d\u7f6e\u6bb5\u3002_haproxy\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/18258.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2025-04-18T16:38:59+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250418163856-6802802010b2b.png\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/18258.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/18258.html\",\"name\":\"\u5e26\u4f60\u5168\u9762\u4e86\u89e3haproxy \uff08\u8d85\u8be6\u7ec6\u7248\uff09 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2025-04-18T16:38:59+00:00\",\"dateModified\":\"2025-04-18T16:38:59+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/18258.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/18258.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/18258.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"\u5e26\u4f60\u5168\u9762\u4e86\u89e3haproxy \uff08\u8d85\u8be6\u7ec6\u7248\uff09\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"\u5e26\u4f60\u5168\u9762\u4e86\u89e3haproxy \uff08\u8d85\u8be6\u7ec6\u7248\uff09 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wsisp.com\/helps\/18258.html","og_locale":"zh_CN","og_type":"article","og_title":"\u5e26\u4f60\u5168\u9762\u4e86\u89e3haproxy \uff08\u8d85\u8be6\u7ec6\u7248\uff09 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb2.2k\u6b21\uff0c\u70b9\u8d5e25\u6b21\uff0c\u6536\u85cf20\u6b21\u3002HAProxy\u662f\u6cd5\u56fd\u5f00\u53d1\u8005 \u5a01\u5229\u5854\u7f57(Willy Tarreau)\u57282000\u5e74\u4f7f\u7528C\u8bed\u8a00\u5f00\u53d1\u7684\u4e00\u4e2a\u5f00\u6e90\u8f6f\u4ef6\u662f\u4e00\u6b3e\u5177\u5907\u9ad8\u5e76\u53d1(\u4e07\u7ea7\u4ee5\u4e0a)\u3001\u9ad8\u6027\u80fd\u7684TCP\u548cHTTP\u8d1f\u8f7d\u5747\u8861\u5668\u652f\u6301\u57fa\u4e8ecookie\u7684\u6301\u4e45\u6027\uff0c\u81ea\u52a8\u6545\u969c\u5207\u6362\uff0c\u652f\u6301\u6b63\u5219\u8868\u8fbe\u5f0f\u53caweb\u72b6\u6001\u7edf\u8ba1\u4f01\u4e1a\u7248\u7f51\u7ad9:https:\/\/www.haproxy.com\u793e\u533a\u7248\u7f51\u7ad9:http:\/\/www.haproxy.orghaproxy\u7684\u57fa\u672c\u914d\u7f6e\u4fe1\u606fHAProxy \u7684\u914d\u7f6e\u6587\u4ef6haproxy.cfg\u7531\u4e24\u5927\u90e8\u5206\u7ec4\u6210\uff0c\u5206\u522b\u662f:global:\u5168\u5c40\u914d\u7f6e\u6bb5\u3002_haproxy","og_url":"https:\/\/www.wsisp.com\/helps\/18258.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2025-04-18T16:38:59+00:00","og_image":[{"url":"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250418163856-6802802010b2b.png"}],"author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"4 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/18258.html","url":"https:\/\/www.wsisp.com\/helps\/18258.html","name":"\u5e26\u4f60\u5168\u9762\u4e86\u89e3haproxy \uff08\u8d85\u8be6\u7ec6\u7248\uff09 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2025-04-18T16:38:59+00:00","dateModified":"2025-04-18T16:38:59+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/18258.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/18258.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/18258.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"\u5e26\u4f60\u5168\u9762\u4e86\u89e3haproxy \uff08\u8d85\u8be6\u7ec6\u7248\uff09"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/18258","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=18258"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/18258\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media\/18238"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=18258"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=18258"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=18258"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=18258"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}