{"id":97212,"date":"2024-06-06T19:06:11","date_gmt":"2024-06-06T11:06:11","guid":{"rendered":"https:\/\/lrxjmw.cn\/?p=97212"},"modified":"2024-06-06T19:06:11","modified_gmt":"2024-06-06T11:06:11","slug":"haproxy-detailed-explanation","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/haproxy-detailed-explanation.html","title":{"rendered":"haproxy\u8be6\u89e3"},"content":{"rendered":"\n\n\n
\u5bfc\u8bfb<\/td>\nHAProxy\u662f\u4e00\u4e2a\u4f7f\u7528C\u8bed\u8a00\u7f16\u5199\u7684\u81ea\u7531\u53ca\u5f00\u653e\u6e90\u4ee3\u7801\u8f6f\u4ef6\uff0c\u5176\u63d0\u4f9b\u9ad8\u53ef\u7528\u6027\u3001\u8d1f\u8f7d\u5747\u8861\uff0c\u4ee5\u53ca\u57fa\u4e8eTCP\u548cHTTP\u7684\u5e94\u7528\u7a0b\u5e8f\u4ee3\u7406\u3002HAProxy\u7279\u522b\u9002\u7528\u4e8e\u90a3\u4e9b\u8d1f\u8f7d\u7279\u5927\u7684web\u7ad9\u70b9\uff0c\u8fd9\u4e9b\u7ad9\u70b9\u901a\u5e38\u53c8\u9700\u8981\u4f1a\u8bdd\u4fdd\u6301\u6216\u4e03\u5c42\u5904\u7406\u3002HAProxy\u8fd0\u884c\u5728\u5f53\u524d\u7684\u786c\u4ef6\u4e0a\uff0c\u5b8c\u5168\u53ef\u4ee5\u652f\u6301\u6570\u4ee5\u4e07\u8ba1\u7684\u5e76\u53d1\u8fde\u63a5\u3002\u5e76\u4e14\u5b83\u7684\u8fd0\u884c\u6a21\u5f0f\u4f7f\u5f97\u5b83\u53ef\u4ee5\u5f88\u7b80\u5355\u5b89\u5168\u7684\u6574\u5408\u8fdb\u60a8\u5f53\u524d\u7684\u67b6\u6784\u4e2d\uff0c \u540c\u65f6\u53ef\u4ee5\u4fdd\u62a4\u4f60\u7684web\u670d\u52a1\u5668\u4e0d\u88ab\u66b4\u9732\u5230\u7f51\u7edc\u4e0a\u3002<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n
1.\u5b89\u88c5haproxy<\/strong><\/div>\n

CentOS\u81ea\u5e26\u4e86haproxy\uff0c\u4f46\u53ef\u80fd\u7248\u672c\u6bd4\u8f83\u8001\u3002\u53ef\u4ee5\u5728IUS\u6e90\u4e0a\u627e\u5230\u6700\u65b0\u7a33\u5b9a\u7248\u7684haproxy\u3002<\/p>\n

cat <\/etc\/yum.repos.d\/ius.repo\r\n[ius]\r\nname=iusrepo\r\nbaseurl=https:\/\/mirrors.tuna.tsinghua.edu.cn\/ius\/stable\/CentOS\/$releasever\/\\$basearch\r\ngpgcheck=0\r\nenable=1\r\neof\r\n\r\nyum -y install haproxy17u\r\n<\/pre>\n

\u4ee5\u4e0b\u662f\u7f16\u8bd1\u5b89\u88c5haproxy-1.7.10\u7684\u8fc7\u7a0b\u3002<\/p>\n

\u7f16\u8bd1\u5b89\u88c5haproxy\u65f6\uff0c\u53ef\u4ee5\u501f\u52a9\u4e8epcre\u73af\u5883\uff0c\u8be5\u73af\u5883\u4e0b\u7f16\u8bd1\u65f6\u501f\u52a9\u6b63\u5219\u8868\u8fbe\u5f0f\u5206\u6790\u7f16\u8bd1\u901f\u5ea6\u4f1a\u5feb\u5f88\u591a\uff0c\u4f46\u662f\u6ca1\u6709\u8be5\u73af\u5883\u4e5f\u53ef\u4ee5\u5b89\u88c5\u3002<\/p>\n

yum -y install pcre pcre-devel\r\ntar xf haproxy-1.7.10.tar.gz\r\ncd haproxy-1.7.10\r\nmake TARGET=linux2628 ARCH=x86_64 PREFIX=\/usr\/local\/haproxy USE_PCRE=1\r\nmake install PREFIX=\/usr\/local\/haproxy\r\n<\/pre>\n

make\u65f6\u9700\u8981\u4f7f\u7528TARGET\u6307\u5b9a\u5185\u6838\u53ca\u7248\u672c\uff0c\u7248\u672c\u5982\u4e0b\uff1a<\/p>\n

- linux22 for Linux 2.2\r\n- linux24 for Linux 2.4 and above (default)\r\n- linux24e for Linux 2.4 with support for a working epoll (> 0.21)\r\n- linux26 for Linux 2.6 and above\r\n- linux2628 for Linux 2.6.28, 3.x, and above (enables splice and tproxy)\r\n- solaris for Solaris 8 or 10 (others untested)\r\n- freebsd for FreeBSD 5 to 10 (others untested)\r\n- netbsd for NetBSD\r\n- osx for Mac OS\/X\r\n- openbsd for OpenBSD 5.7 and above\r\n- aix51 for AIX 5.1\r\n- aix52 for AIX 5.2\r\n- cygwin for Cygwin\r\n- haiku for Haiku\r\n- generic for any other OS or version.\r\n- custom to manually adjust every setting\r\n<\/pre>\n

\u4f7f\u7528ARCH\u6307\u5b9a\u67b6\u6784\uff0c\u4e0d\u8fc7ARCH\u9009\u9879\u53ef\u7701\u3002\u4f7f\u7528USE_PCRE=1\u8868\u793a\u4f7f\u7528PCRE\u73af\u5883\u7f16\u8bd1\uff0c\u52a0\u5feb\u7f16\u8bd1\u901f\u5ea6\u3002<\/p>\n

\u7f16\u8bd1\u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u53ea\u67093\u4e2a\u76ee\u5f55\uff1adoc\u3001share\u548csbin\uff0csbin\u91cc\u9762\u53ea\u6709\u4e00\u4e2ahaproxy\u7684\u4e3b\u7a0b\u5e8fhaproxy\u3002\u4e3a\u4e86\u65b9\u4fbf\u7ba1\u7406haproxy\u670d\u52a1\uff0c\u53ef\u4ee5\u4eceyum\u5b89\u88c5\u7684haproxy\u4e2d\u590d\u5236\/etc\/init.d\/haproxy\u3002<\/p>\n

2.haproxy\u547d\u4ee4<\/strong><\/div>\n

\u5e38\u7528\u7684\u51e0\u4e2a\uff1a<\/p>\n

# \u68c0\u67e5\u914d\u7f6e\u6587\u4ef6\u8bed\u6cd5\r\nhaproxy -c -f \/etc\/haproxy\/haproxy.cfg\r\n\r\n# \u4ee5daemon\u6a21\u5f0f\u542f\u52a8\uff0c\u4ee5systemd\u7ba1\u7406\u7684daemon\u6a21\u5f0f\u542f\u52a8\r\nhaproxy -D -f \/etc\/haproxy\/haproxy.cfg [-p \/var\/run\/haproxy.pid]\r\nhaproxy -Ds -f \/etc\/haproxy\/haproxy.cfg [-p \/var\/run\/haproxy.pid]\r\n\r\n# \u542f\u52a8\u8c03\u8bd5\u529f\u80fd\uff0c\u5c06\u663e\u793a\u6240\u6709\u8fde\u63a5\u548c\u5904\u7406\u4fe1\u606f\u5728\u5c4f\u5e55\r\nhaproxy -d -f \/etc\/haproxy\/haproxy.cfg\r\n\r\n# restart\u3002\u9700\u8981\u4f7f\u7528st\u9009\u9879\u6307\u5b9apid\u5217\u8868\r\nhaproxy -f \/etc\/haproxy.cfg [-p \/var\/run\/haproxy.pid] -st `cat \/var\/run\/haproxy.pid`\r\n\r\n# graceful restart\uff0c\u5373reload\u3002\u9700\u8981\u4f7f\u7528sf\u9009\u9879\u6307\u5b9apid\u5217\u8868\r\nhaproxy -f \/etc\/haproxy.cfg [-p \/var\/run\/haproxy.pid] -sf `cat \/var\/run\/haproxy.pid`\r\n\r\n# \u663e\u793ahaproxy\u7f16\u8bd1\u548c\u542f\u52a8\u4fe1\u606f\r\nhaproxy -vv\r\n<\/pre>\n
\n

\u539f\u6587\u6765\u81ea\uff1ahttps:\/\/www.cnblogs.com\/f-ck-need-u\/p\/8546010.html<\/a><\/p>\n

\u672c\u6587\u5730\u5740\uff1a https:\/\/lrxjmw.cn\/haproxy-detailed-explanation.html<\/a>\u7f16\u8f91\uff1a\u51af\u745e\u6d9b\uff0c\u5ba1\u6838\u5458\uff1a\u9004\u589e\u5b9d<\/span><\/p>\n<\/blockquote>\n","protected":false},"excerpt":{"rendered":"

\u5bfc\u8bfb HAProxy\u662f\u4e00\u4e2a\u4f7f\u7528C\u8bed\u8a00\u7f16\u5199\u7684\u81ea\u7531\u53ca\u5f00\u653e\u6e90\u4ee3\u7801\u8f6f\u4ef6\uff0c\u5176\u63d0\u4f9b\u9ad8\u53ef\u7528\u6027\u3001\u8d1f\u8f7d\u5747\u8861\uff0c\u4ee5\u53ca\u57fa\u4e8eTCP\u548cHT […]<\/p>\n","protected":false},"author":1329,"featured_media":97213,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-97212","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-thread"],"acf":[],"_links":{"self":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/97212","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/users\/1329"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=97212"}],"version-history":[{"count":3,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/97212\/revisions"}],"predecessor-version":[{"id":291836,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/97212\/revisions\/291836"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/97213"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=97212"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=97212"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=97212"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}