{"id":4263,"date":"2024-10-25T15:15:01","date_gmt":"2024-10-25T07:15:01","guid":{"rendered":"https:\/\/dasmz.com\/?p=4263"},"modified":"2024-11-22T00:03:32","modified_gmt":"2024-11-21T16:03:32","slug":"%e7%bc%96%e8%af%91%e5%ae%89%e8%a3%85haproxy","status":"publish","type":"post","link":"https:\/\/dasmz.com\/?p=4263","title":{"rendered":"\u7f16\u8bd1\u5b89\u88c5HaProxy 2024-10-25"},"content":{"rendered":"\n<p><strong>\u524d\u7f00\u3001\u6587\u6863\u4fee\u6539\u8bb0\u5f55<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">20241025 \u521d\u59cb\u5316\u7f16\u8f91\u6b64\u6587\u7ae0\uff0c\u5b8c\u7a3f\uff0c\u6587\u7ae0\u4e2d\u7684\u6700\u65b0\u7a33\u5b9a\u7248\u672c\uff0c\u4e3a\u4e66\u5199\u6b64\u6587\u65f6\u95f4\u7684v3.0.5\n20241119 \u66f4\u65b0\u5230v3.0.6\u7248\u672c\n20241121 \u66f4\u65b0\u5c0f\u90e8\u5206\u5185\u5bb9<\/pre>\n\n\n\n<p><strong>\u7ae0\u82821\u3001\u9700\u6c42\u63cf\u8ff0<\/strong><\/p>\n\n\n\n<p>\u5728Debian\/Ubuntu\u7cfb\u5217\u7cfb\u7edf\u4e0a\uff0c\u7f16\u8bd1\u5b89\u88c5\u6700\u65b0\u7a33\u5b9a\u7248\u672c\u7684haproxy version v3.0.X\uff0c\u8be5\u7248\u672c\u4e3aLTS\uff0c\u652f\u6301\u52302029\u5e74Q2\u5b63\u5ea6\u3002<\/p>\n\n\n\n<p>\u5730\u5740\uff1a <a href=\"http:\/\/git.haproxy.org\/git\/haproxy-3.0.git\/\" data-type=\"URL\" data-id=\"http:\/\/git.haproxy.org\/git\/haproxy-3.0.git\/\">http:\/\/git.haproxy.org\/git\/haproxy-3.0.git\/<\/a><\/p>\n\n\n\n<p>\u4e0b\u8f7d\u5730\u5740\uff1a <a href=\"https:\/\/www.haproxy.org\/download\/3.0\/src\/haproxy-3.0.6.tar.gz\">https:\/\/www.haproxy.org\/download\/3.0\/src\/haproxy-3.0.6.tar.gz<\/a><\/p>\n\n\n\n<p>\u7ae0\u82822\u3001\u7f16\u8bd1\u6b65\u9aa4<\/p>\n\n\n\n<p>\u5b9e\u6d4b\u901a\u8fc7\uff0c\u7528\u7684Ubuntu 20.04.2 LTS\u3001Debian 12\u7cfb\u7edf\u73af\u5883\uff0c\u5efa\u4e00\u4e2a src\u76ee\u5f55\uff0c\u4f9b\u653e\u7f6e\u8f6f\u4ef6\u6e90\u4ee3\u7801\u538b\u7f29\u5305<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">mkdir -p \/root\/src\/\n\ncd \/root\/src\/\nwget https:\/\/www.haproxy.org\/download\/3.0\/src\/haproxy-3.0.6.tar.gz<\/pre>\n\n\n\n<p>\u5982\u679c\u662f\u5185\u7f51\u73af\u5883\uff0c\u4f7f\u7528\u4efb\u610f\u5de5\u5177\uff0c\u628a\u672c\u5730\u7684haproxy-3.0.6.tar.gz\u6587\u4ef6\u4f20\u8f93\u5230\u670d\u52a1\u5668\u7684\u76ee\u5f55 \/root\/src\/haproxy-3.0.6.tar.gz<\/p>\n\n\n<div class=\"wp-block-image is-style-default\">\n<figure class=\"aligncenter size-full\"><img decoding=\"async\" loading=\"lazy\" width=\"389\" height=\"113\" src=\"https:\/\/dasmz.com\/wp-content\/uploads\/2024\/10\/Screenshot-from-2024-10-25-15-22-27.png\" alt=\"\" class=\"wp-image-4266\"\/><\/figure><\/div>\n\n\n<p>\u5b89\u88c5\u5fc5\u8981\u7684\u4f9d\u8d56<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">apt update\napt install -y gcc make build-essential libpcre3-dev libssl-dev zlib1g-dev libsystemd-dev<\/pre>\n\n\n\n<p>\u89e3\u538b\u6e90\u4ee3\u7801\u7684\u538b\u7f29\u5305<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">cd \/root\/src\/\ntar -zxvf haproxy-3.0.6.tar.gz\ncd haproxy-3.0.6\/<\/pre>\n\n\n\n<p>\u521b\u5efa\u4e00\u4e9b\u5fc5\u8981\u7684\u7528\u6237\u548c\u76ee\u5f55<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">mkdir -p \/etc\/haproxy  \/var\/lib\/haproxy  \/run\/haproxy\nuseradd -U -s '\/usr\/sbin\/nologin' -d '\/var\/lib\/haproxy' haproxy\ncd \/var\/lib\/\nchown -R haproxy:haproxy .\/haproxy\ncd \/run\/\nchown -R haproxy:haproxy .\/haproxy<\/pre>\n\n\n\n<p>\u7f16\u8bd1\u5b89\u88c5<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">\/\/ \u7f16\u8bd1\ncd \/root\/src\/haproxy-3.0.6\/\nmake TARGET=linux-glibc USE_SYSTEMD=1 USE_OPENSSL=1 USE_ZLIB=1 USE_PCRE=1\n\n\u7f16\u8bd1\u53c2\u6570\u9009\u9879\u8bf4\u660e\uff1a\nTARGET=linux-glibc\uff1a\u6307\u5b9a\u76ee\u6807\u5e73\u53f0,\u6211\u8fd9\u91cc\u662f64\u4f4d\u7684X86_64\u7cfb\u7edf\u3002\nUSE_OPENSSL=1\uff1a\u5f00\u542f SSL \u652f\u6301\u3002\nUSE_ZLIB=1\uff1a\u5f00\u542f zlib \u652f\u6301\uff0c\u7528\u4e8e\u538b\u7f29\u54cd\u5e94\u6570\u636e\u3002\nUSE_PCRE=1\uff1a\u542f\u7528 PCRE \u5e93\u652f\u6301\u6b63\u5219\u8868\u8fbe\u5f0f\u3002\nUSE_TFO=1\uff1a\u53ef\u9009\uff0c\u542f\u7528 TFO \u652f\u6301\uff0cTCP Fast Open\uff0c\u9002\u5408\u5ef6\u8fdf\u654f\u611f\u7684\u5e94\u7528\uff0c\u5982\u8d1f\u8f7d\u5747\u8861\u3001Web \u670d\u52a1\n\/\/ \u53ef\u9009\uff0c\u914d\u5957\u9700\u8981\u5f00\u542f \/proc\/sys\/net\/ipv4\/tcp_fastopen \u7f6e\u4e8e3,\u5f00\u542f\u540c\u65f6\u652f\u6301\u5ba2\u6237\u7aef\u548c\u670d\u52a1\u5668\u7aef\u7684TFO\nUSE_LUA=1\uff1a\u53ef\u9009\uff0c\u542f\u7528 Lua \u811a\u672c\u652f\u6301\nUSE_SYSTEMD=1\uff1a\u53ef\u9009\uff0c\u542f\u7528systemd\u7ba1\u7406 HAProxy\u670d\u52a1\n\n\n\/\/ \u5b89\u88c5\nmake install\n\n\/\/ \u6267\u884c\u6587\u4ef6\ncp .\/examples\/haproxy.init  \/etc\/init.d\/haproxy\nchmod +x \/etc\/init.d\/haproxy\n<\/pre>\n\n\n\n<p>\u67e5\u770b\u4e00\u4e0b\u7248\u672c\u4fe1\u606f<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">\/usr\/local\/sbin\/haproxy -v<\/pre>\n\n\n\n<figure class=\"wp-block-image size-full is-style-default\"><img decoding=\"async\" loading=\"lazy\" width=\"854\" height=\"121\" src=\"https:\/\/dasmz.com\/wp-content\/uploads\/2024\/10\/Screenshot-from-2024-10-25-16-23-49.png\" alt=\"\" class=\"wp-image-4279\" srcset=\"https:\/\/dasmz.com\/wp-content\/uploads\/2024\/10\/Screenshot-from-2024-10-25-16-23-49.png 854w, https:\/\/dasmz.com\/wp-content\/uploads\/2024\/10\/Screenshot-from-2024-10-25-16-23-49-768x109.png 768w, https:\/\/dasmz.com\/wp-content\/uploads\/2024\/10\/Screenshot-from-2024-10-25-16-23-49-624x88.png 624w\" sizes=\"(max-width: 854px) 100vw, 854px\" \/><\/figure>\n\n\n\n<p>\u521b\u5efa\u914d\u7f6e\u76f8\u5173\u7684\u76ee\u5f55<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">mkdir -p \/etc\/haproxy  \/var\/lib\/haproxy  \/run\/haproxy<\/pre>\n\n\n\n<p>\u521b\u5efa\u4e00\u4e2a\u7a7a\u7684\u914d\u7f6e\u6587\u4ef6\uff0c\u914d\u7f6e\u6587\u4ef6\u7684\u5185\u5bb9\u5b9a\u4e49\uff0c\u8fd9\u4e2a\u6839\u636e\u4f60\u4eec\u4e1a\u52a1\u7684\u5b9e\u9645\u6765\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">touch \/etc\/haproxy\/haproxy.cfg<\/pre>\n\n\n\n<p>\u5199\u5165\u4e00\u4e2a\u7b80\u5355\u7684\u6d4b\u8bd5\u5185\u5bb9\uff0c\u8f6e\u5faa2\u4e2a\u540e\u7aefHTTP\u7684WEB<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">global\n   strict-limits \n\ndefaults\n   mode http\n   balance random      # power-of-two-choices\n   timeout client 60s\n   timeout server 60s\n   timeout connect 1s\n\nlisten p\n   bind :8000\n   balance roundrobin\n   server server_web01    47.1.2.101:11111 check inter 8000 rise 2 fall 3 weight 1 maxconn 8192\n   server server_web02    47.3.4.102:12222 check inter 8000 rise 2 fall 3 weight 1 maxconn 8192\n\n\n<\/pre>\n\n\n\n<p>\u7528curl\u547d\u4ee4\uff0c\u6d4b\u8bd5\u4e00\u4e0b\u8bbf\u95ee<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">admin@Desktop:~$ curl http:\/\/122.222.100.83:8000\n&lt;p&gt;S01&lt;\/p&gt;\nadmin@Desktop:~$ curl http:\/\/122.222.100.83:8000\n&lt;p&gt;S02&lt;\/p&gt;\nadmin@Desktop:~$ curl http:\/\/122.222.100.83:8000\n&lt;p&gt;S01&lt;\/p&gt;\nadmin@Desktop:~$ curl http:\/\/122.222.100.83:8000\n&lt;p&gt;S02&lt;\/p&gt;\nadmin@Desktop:~$ \n<\/pre>\n\n\n\n<p>\u521b\u5efa\u4e00\u4e2ahaproxy\u540d\u79f0\u7684\u670d\u52a1\u6587\u4ef6<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">cat &gt; \/etc\/systemd\/system\/haproxy.service &lt;&lt; EOF\n[Unit]\nDescription=HAProxy Load Balancer\nAfter=network.target\n\n[Service]\nExecStart=\/usr\/local\/sbin\/haproxy -f \/etc\/haproxy\/haproxy.cfg\nExecReload=\/bin\/kill -USR2 \\$MAINPID\nKillMode=mixed\nRestart=always\n\n[Install]\nWantedBy=multi-user.target\nEOF<\/pre>\n\n\n\n<p>\u542f\u52a8\u505c\u6b62\u547d\u4ee4<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">systemctl daemon-reload\nsystemctl start haproxy    # \u542f\u52a8\nsystemctl stop haproxy    # \u505c\u6b62\nsystemctl enable haproxy    # \u81ea\u52a8\u5f00\u673a\u542f\u52a8\nsystemctl status haproxy    # \u67e5\u770b\u72b6\u6001<\/pre>\n\n\n\n<p><strong>\u9644\u5f551\u3001\u89c6\u9891\u64cd\u4f5c\u6f14\u793a<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">\u672c\u671f\u535a\u5ba2\u5730\u5740 https:\/\/dasmz.com\/?p=4263\n\u672c\u671f\u89c6\u9891\u5730\u5740 https:\/\/youtu.be\/oYm4jI1TTdo<\/pre>\n\n\n\n<figure class=\"wp-block-embed is-type-video is-provider-youtube wp-block-embed-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio\"><div class=\"wp-block-embed__wrapper\">\n<iframe loading=\"lazy\" title=\"000155  Linux\u73af\u5883\uff0cDebian11\u7cfb\u7edf\u4e0b\u7f16\u8bd1\u5b89\u88c5HAProxy \u6700\u65b0\u7a33\u5b9a3 0 6\u7248\u672c 2024-11-21\" width=\"625\" height=\"352\" src=\"https:\/\/www.youtube.com\/embed\/oYm4jI1TTdo?feature=oembed\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" referrerpolicy=\"strict-origin-when-cross-origin\" allowfullscreen><\/iframe>\n<\/div><\/figure>\n\n\n\n<p><strong>\u9644\u5f552\u3001@Dasmz<\/strong><\/p>\n\n\n\n<p>\u535a\u5ba2\u5185\uff0c\u6240\u6709\u6559\u7a0b\u4e3a\u624b\u6253\u539f\u521b\u6559\u7a0b\uff0c\u5982\u679c\u6280\u672f\u6559\u7a0b\u5bf9\u60a8\u6709\u6240\u5e2e\u52a9\uff0c\u6b22\u8fce\u6253\u8d4f\u4f5c\u8005\u3002\u6280\u672f\u5c42\u9762\uff0c\u95fb\u9053\u6709\u5148\u540e\uff0c\u5982\u6709\u758f\u6f0f\u3001\u9519\u8bef\uff0c\u6b22\u8fce\u6307\u6b63\u3002\u6280\u672f\u535a\u5ba2\u7684\u5185\u5bb9\uff0c\u4e00\u822c\u5177\u6709\u4e00\u5b9a\u7684\u73af\u5883\u4f9d\u8d56\uff0c\u5177\u6709\u4e00\u5b9a\u7684\u5e74\u4ee3\u4f9d\u8d56\uff0c\u914c\u60c5\u53c2\u8003\u5176\u4e2d\u7684\u5185\u5bb9\uff0c\u8bf7\u52ff\u5b8c\u5168\u7167\u642c\u7167\u6284\u3002<\/p>\n\n\n\n<p>\u5bf9\u4e8e\u535a\u5ba2\u5185\u5df2\u63d0\u53ca\u7684\u4e13\u4e1a\u77e5\u8bc6\uff0c\u5982\u679c\u9700\u8981\u6280\u672f\u6307\u5bfc\uff0c\u6b22\u8fce\u8054\u7cfb\u6211\uff0c\u4ec5\u9700\u652f\u4ed8\u5de5\u65f6\u8d39<\/p>\n\n\n\n<p>Twitter: <a href=\"https:\/\/twitter.com\/fdmove\">Dasmz<\/a><\/p>\n\n\n\n<p>Youtube: <a href=\"https:\/\/www.youtube.com\/@DasmzStudio\" data-type=\"URL\" data-id=\"https:\/\/www.youtube.com\/@DasmzStudio\">@DasmzStudio<\/a><\/p>\n\n\n\n<p>Telegram: <a href=\"https:\/\/t.me\/fdmove\" data-type=\"URL\" data-id=\"https:\/\/t.me\/fdmove\">@Dasmz<\/a><\/p>\n\n\n<div class=\"wp-block-image is-style-default\">\n<figure class=\"aligncenter size-large\"><img decoding=\"async\" loading=\"lazy\" width=\"574\" height=\"446\" src=\"https:\/\/dasmz.com\/wp-content\/uploads\/2020\/12\/DONATE.jpg\" alt=\"Donate\" class=\"wp-image-18\"\/><figcaption class=\"wp-element-caption\">\u4e91\u4e5e\u8ba8<\/figcaption><\/figure><\/div>","protected":false},"excerpt":{"rendered":"<p>\u524d\u7f00\u3001\u6587\u6863\u4fee\u6539\u8bb0\u5f55 20241025 \u521d\u59cb\u5316\u7f16\u8f91\u6b64\u6587\u7ae0\uff0c\u5b8c\u7a3f\uff0c\u6587\u7ae0\u4e2d\u7684\u6700\u65b0\u7a33\u5b9a\u7248\u672c\uff0c\u4e3a\u4e66\u5199\u6b64\u6587\u65f6\u95f4\u7684v3.0. [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[3],"tags":[165,167,166,164],"_links":{"self":[{"href":"https:\/\/dasmz.com\/index.php?rest_route=\/wp\/v2\/posts\/4263"}],"collection":[{"href":"https:\/\/dasmz.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/dasmz.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/dasmz.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/dasmz.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=4263"}],"version-history":[{"count":30,"href":"https:\/\/dasmz.com\/index.php?rest_route=\/wp\/v2\/posts\/4263\/revisions"}],"predecessor-version":[{"id":4329,"href":"https:\/\/dasmz.com\/index.php?rest_route=\/wp\/v2\/posts\/4263\/revisions\/4329"}],"wp:attachment":[{"href":"https:\/\/dasmz.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4263"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dasmz.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4263"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dasmz.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4263"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}