{"id":532,"date":"2024-12-06T18:20:04","date_gmt":"2024-12-06T10:20:04","guid":{"rendered":"http:\/\/192.168.5.24\/?p=532"},"modified":"2025-01-10T14:21:27","modified_gmt":"2025-01-10T06:21:27","slug":"haproxykeepalived-%e6%90%ad%e5%bb%ba%e9%ab%98%e5%8f%af%e7%94%a8%e8%b4%9f%e8%bd%bd%e5%9d%87%e8%a1%a1%e9%9b%86%e7%be%a4","status":"publish","type":"post","link":"https:\/\/bigvip.dpdns.org\/?p=532","title":{"rendered":"HAProxy+Keepalived \u642d\u5efa\u9ad8\u53ef\u7528\u8d1f\u8f7d\u5747\u8861\u96c6\u7fa4"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">1\u3001HAProxy\u4ecb\u7ecd<\/h2>\n\n\n\n<p>HAProxy\u63d0\u4f9b\u9ad8\u53ef\u7528\u6027\u3001\u8d1f\u8f7d\u5747\u8861\u4ee5\u53ca\u57fa\u4e8eTCP\u548cHTTP\u5e94\u7528\u5c42\u7684\u4ee3\u7406\uff0c\u652f\u6301\u865a\u62df\u4e3b\u673a\uff0c\u5b83\u662f\u514d\u8d39\u3001\u5feb\u901f\u5e76\u4e14\u53ef\u9760\u7684\u4e00\u79cd\u89e3\u51b3\u65b9\u6848\u3002\u57fa\u4e8eTCP (\u56db\u5c42)\uff0cHTTP (\u4e03\u5c42) \u5e94\u7528\u7684\u8d1f\u8f7d\u5747\u8861\u8f6f\u4ef6\uff0cHAProxy\u7279\u522b\u9002\u7528\u4e8e\u90a3\u4e9b\u8d1f\u8f7d\u7279\u522b\u5927\u7684web\u7ad9\u70b9\uff0c\u8fd9\u4e9b\u7ad9\u70b9\u901a\u5e38\u6709\u9700\u8981\u4f1a\u8bdd\u4fdd\u6301\u6216\u4e03\u5c42\u5904\u7406\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"autoid-9-1-0\">HAProxy\u8f6f\u4ef6\u4f18\u70b9<\/h3>\n\n\n\n<p>\uff081\uff09\u53ef\u9760\u6027\u548c\u7a33\u5b9a\u6027\u975e\u5e38\u597d\uff0c\u53ef\u4ee5\u4e0e\u786c\u4ef6\u7ea7F5\u8d1f\u8f7d\u5747\u8861\u8bbe\u5907\u5ab2\u7f8e<\/p>\n\n\n\n<p>\uff082\uff09\u6700\u9ad8\u53ef\u540c\u4e8b\u7ef4\u62a44W-5W\u4e2a\u5e76\u53d1\u8fde\u63a5\uff0c\u5355\u4f4d\u65f6\u95f4\u5185\u6700\u5927\u8bf7\u6c42\u4e3a20000\u4e2a\uff0c\u6700\u5927\u6570\u636e\u5904\u7406\u80fd\u529b\u53ef\u8fbe10Gbps\u3002<\/p>\n\n\n\n<p>\uff083\uff09\u652f\u6301\u591a\u4e8e8\u4e2d\u8d1f\u8f7d\u5747\u8861\u7b97\u6cd5\uff0c\u540c\u4e8b\u652f\u6301\u4f1a\u8bdd\u4fdd\u6301\u3002<\/p>\n\n\n\n<p>\uff084\uff09\u652f\u6301\u865a\u62df\u4e3b\u673a\u529f\u80fd<\/p>\n\n\n\n<p>\uff085\uff09\u4ece1.3\u7248\u672c\u540e\u652f\u6301\u62d2\u7edd\u8fde\u63a5\uff0c\u5168\u900f\u660e\u4ee3\u7406\uff0c\u8fd9\u4e9b\u529f\u80fd\u5ba4\u5176\u4ed6\u8d1f\u8f7d\u5747\u8861\u6240\u4e0d\u5177\u5907\u7684<\/p>\n\n\n\n<p>\uff086\uff09HAProxy\u62e5\u6709\u4e00\u4e2a\u5f3a\u5927\u7684\u670d\u52a1\u5668\u72b6\u6001\u76d1\u63a7\u9875\u9762\uff0c\u53ef\u4ee5\u901a\u8fc7\u6b64\u9875\u9762\u5b9e\u65f6\u4e86\u89e3\u7cfb\u7edf\u72b6\u51b5<\/p>\n\n\n\n<p>\uff087\uff09HAproxy\u62e5\u6709\u529f\u80fd\u5f3a\u5927\u7684ACL\u652f\u6301\uff0c\u7ed9\u4f7f\u7528\u4e0a\u5e26\u6765\u5f88\u5927\u65b9\u9762<\/p>\n\n\n\n<p>\uff088\uff09HAProxy\u662f\u501f\u52a9\u4e8e\u64cd\u4f5c\u7cfb\u7edf\u7684\u6280\u672f\u7279\u6027\u6765\u5b9e\u73b0\u6027\u80fd\u6700\u5927\u5316\u7684\uff0c\u56e0\u6b64\uff0c\u5728\u4f7f\u7528HAProxy\u65f6\u5bf9\u64cd\u4f5c\u7cfb\u7edf\u7684\u6027\u80fd\u8c03\u4f18\u662f\u975e\u5e38\u91cd\u8981\u7684\u3002<\/p>\n\n\n\n<p>\uff089\uff09\u80fd\u591f\u8865\u5145Nginx\u7684\u4e00\u4e9b\u7f3a\u70b9\uff0c\u6bd4\u5982Session\u7684\u4fdd\u6301\uff0cCookie\u7684\u5f15\u5bfc\u7b49\u5de5\u4f5c\uff0c\u652f\u6301url\u68c0\u6d4b\u540e\u7aef\u7684\u670d\u52a1\u5668\u51fa\u95ee\u9898\u7684\u68c0\u67e5\u4f1a\u6709\u5f88\u597d\u7684\u5e2e\u52a9\uff0c\u5b83\u548cLVS\u4e00\u6837\uff0c\u672c\u8eab\u4ec5\u4ec5\u5c31\u53ea\u662f\u4e00\u6b3e\u8d1f\u8f7d\u5747\u8861\u8f6f\u4ef6\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">2\u3001\u62d3\u6251\u56fe\u53ca\u89c4\u5212<\/h2>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"990\" height=\"496\" src=\"http:\/\/192.168.5.24\/wp-content\/uploads\/2024\/12\/image-1.png\" alt=\"\" class=\"wp-image-542\" srcset=\"https:\/\/bigvip.dpdns.org\/wp-content\/uploads\/2024\/12\/image-1.png 990w, https:\/\/bigvip.dpdns.org\/wp-content\/uploads\/2024\/12\/image-1-300x150.png 300w, https:\/\/bigvip.dpdns.org\/wp-content\/uploads\/2024\/12\/image-1-768x385.png 768w, https:\/\/bigvip.dpdns.org\/wp-content\/uploads\/2024\/12\/image-1-816x409.png 816w, https:\/\/bigvip.dpdns.org\/wp-content\/uploads\/2024\/12\/image-1-400x200.png 400w\" sizes=\"auto, (max-width: 990px) 100vw, 990px\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">3\u3001HAProxy\u5b89\u88c5\u8bbe\u7f6e<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>\u8c03\u5ea6\u670d\u52a1\u56681\u30012\u7684\u914d\u7f6e\uff1a<\/strong>\n\n&#91;root@localhost ~]# cat \/etc\/haproxy\/haproxy.cfg \nglobal\nlog 127.0.0.1 local0 info \nmaxconn 256\nchroot \/usr\/local\/haproxy\nuid 1000\ngid 1000\ndaemon\ndefaults\nmode http\ntimeout connect 1500ms\ntimeout client 5000ms\ntimeout server 5000ms\noption httpclose\noption dontlognull\noption forwardfor\noption redispatch\noption abortonclose\nfrontend http-in\nbind *:80\nlog global\ndefault_backend servers\nbackend servers\noption httpchk GET \/index.html\nbalance roundrobin\nserver server1 192.168.168.142:80 check inter 2000 rise 2 fall 2 \nserver server2 192.168.168.143:80 check inter 2000 rise 2 fall 2 \nlisten stats\nmode http\nbind 0.0.0.0:9999\nstats enable\nlog global\nstats uri \/status\nstats auth haadmin:qm123com<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">4\u3001Keepalived\u7684\u5b89\u88c5\u914d\u7f6e<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>\u8c03\u5ea6\u670d\u52a1\u56681\u7684\u914d\u7f6e\uff1a<\/strong>\n\n&#91;root@localhost ~]# cat \/etc\/keepalived\/keepalived.conf\n! Configuration File for keepalived\n\nglobal_defs {\n   notification_email {\n    sysadmin@firewall.loc\n   }\n   notification_email_from Alexandre.Cassen@firewall.loc\n   smtp_server 192.168.200.1\n   smtp_connect_timeout 30\n   router_id <strong>LVS_147<\/strong>\n   vrrp_skip_check_adv_addr\n#   vrrp_strict\n   vrrp_garp_interval 0\n   vrrp_gna_interval 0\n}\n\nvrrp_instance VI_1 {\n    state <strong>MASTER<\/strong>\n    interface ens33\n    virtual_router_id 51\n    priority 100\n    advert_int 1\n    authentication {\n        auth_type PASS\n        auth_pass 1111\n    }\n    virtual_ipaddress {\n        192.168.168.188\n    }\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>\u8c03\u5ea6\u670d\u52a1\u56682\u7684\u914d\u7f6e\uff1a<\/strong>\n\n&#91;root@localhost ~]# cat \/etc\/keepalived\/keepalived.conf \n! Configuration File for keepalived\n\nglobal_defs {\n   notification_email {\n       sysadmin@firewall.loc\n   }\n   notification_email_from Alexandre.Cassen@firewall.loc\n   smtp_server 192.168.200.1\n   smtp_connect_timeout 30\n   router_id <strong>LVS_148<\/strong>\n   vrrp_skip_check_adv_addr\n#   vrrp_strict\n   vrrp_garp_interval 0\n   vrrp_gna_interval 0\n}\n\nvrrp_instance VI_1 {\n    state<strong> BACKUP<\/strong>\n    interface ens32\n    virtual_router_id 51\n    priority 100\n    advert_int 1\n    authentication {\n        auth_type PASS\n        auth_pass 1111\n    }\n    virtual_ipaddress {\n        192.168.168.188\n    }\n}<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">5\u3001\u5176\u5b83\u8bbe\u7f6e<\/h2>\n\n\n\n<p>     1\uff09NFS\u670d\u52a1\u5668\u7684\u5b89\u88c5\u53ca\u914d\u7f6e\u597d\u540e\uff0c\u628a\u7f51\u7ad9\u6587\u4ef6\u6240\u5728\u76ee\u5f55\u5171\u4eab\u7ed9\u670d\u52a1\u5668\u6c60\u4f7f\u7528\u5373\u53ef\u3002<\/p>\n\n\n\n<p>      2\uff09\u670d\u52a1\u5668\u6c601\u30012\u5b89\u88c5\u914d\u7f6e\u597dhttpd\uff0c\u5e76\u4e14\u628aNFS\u5171\u4eab\u5b58\u50a8\u6302\u8f7d\u5230httpd\u7684\u6587\u6863\u6839\u76ee\u5f55\u4e0b\u5373\u53ef\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">6\u3001\u9a8c\u8bc1<\/h2>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"413\" src=\"http:\/\/192.168.5.24\/wp-content\/uploads\/2024\/12\/image-2-1024x413.png\" alt=\"\" class=\"wp-image-544\" srcset=\"https:\/\/bigvip.dpdns.org\/wp-content\/uploads\/2024\/12\/image-2-1024x413.png 1024w, https:\/\/bigvip.dpdns.org\/wp-content\/uploads\/2024\/12\/image-2-300x121.png 300w, https:\/\/bigvip.dpdns.org\/wp-content\/uploads\/2024\/12\/image-2-768x310.png 768w, https:\/\/bigvip.dpdns.org\/wp-content\/uploads\/2024\/12\/image-2-1536x620.png 1536w, https:\/\/bigvip.dpdns.org\/wp-content\/uploads\/2024\/12\/image-2-816x329.png 816w, https:\/\/bigvip.dpdns.org\/wp-content\/uploads\/2024\/12\/image-2.png 1901w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>1\u3001HAProxy\u4ecb\u7ecd HAProxy\u63d0\u4f9b\u9ad8\u53ef\u7528\u6027\u3001\u8d1f\u8f7d\u5747\u8861\u4ee5\u53ca\u57fa\u4e8eTCP\u548cHTTP\u5e94\u7528\u5c42\u7684\u4ee3\u7406\uff0c\u652f\u6301\u865a\u62df\u4e3b\u673a [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"aside","meta":{"footnotes":""},"categories":[20,36],"tags":[85,84],"class_list":["post-532","post","type-post","status-publish","format-aside","hentry","category-linux","category-36","tag-haproxy","tag-keepalived","post_format-post-format-aside"],"_links":{"self":[{"href":"https:\/\/bigvip.dpdns.org\/index.php?rest_route=\/wp\/v2\/posts\/532","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/bigvip.dpdns.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/bigvip.dpdns.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/bigvip.dpdns.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/bigvip.dpdns.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=532"}],"version-history":[{"count":11,"href":"https:\/\/bigvip.dpdns.org\/index.php?rest_route=\/wp\/v2\/posts\/532\/revisions"}],"predecessor-version":[{"id":726,"href":"https:\/\/bigvip.dpdns.org\/index.php?rest_route=\/wp\/v2\/posts\/532\/revisions\/726"}],"wp:attachment":[{"href":"https:\/\/bigvip.dpdns.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=532"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/bigvip.dpdns.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=532"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/bigvip.dpdns.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=532"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}