{"id":224794,"date":"2021-09-04T10:00:49","date_gmt":"2021-09-04T02:00:49","guid":{"rendered":"https:\/\/lrxjmw.cn\/?p=224794"},"modified":"2021-08-26T09:01:57","modified_gmt":"2021-08-26T01:01:57","slug":"installation-haproxy-docke","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/installation-haproxy-docke.html","title":{"rendered":"\u5728docker\u4e2dhaproxy\u7684\u5b89\u88c5\u4ee5\u53camysql\u7684\u8d1f\u8f7d\u5747\u8861\u914d\u7f6e"},"content":{"rendered":"\n\n\n
\u5bfc\u8bfb<\/td>\nHAProxy\u63d0\u4f9b\u9ad8\u53ef\u7528\u6027\u3001\u8d1f\u8f7d\u5747\u8861\u4ee5\u53ca\u57fa\u4e8eTCP\u548cHTTP\u5e94\u7528\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<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n
1 \u4ec0\u4e48\u662fhaproxy<\/strong><\/div>\n

HAProxy\u63d0\u4f9b\u9ad8\u53ef\u7528\u6027\u3001\u8d1f\u8f7d\u5747\u8861\u4ee5\u53ca\u57fa\u4e8eTCP\u548cHTTP\u5e94\u7528\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\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<\/p>\n

2 haproxy\u7684\u5b89\u88c5<\/strong><\/div>\n
1.\u62c9\u53d6\u955c\u50cf<\/strong><\/span><\/div>\n
\r\ndocker pull haproxy\r\n<\/pre>\n
2.\u914d\u7f6e\u76ee\u5f55<\/strong><\/span><\/div>\n
\r\nmkdir \/docker\/haproxy-master\/\r\ntouch \/docker\/haproxy-master\/haproxy.cfg\r\n<\/pre>\n
3.\u914d\u7f6ehaproxy.cfg\u6587\u4ef6<\/strong><\/span><\/div>\n
\r\ndefaults\r\n    mode            tcp\r\n    log             global\r\n    option          tcplog\r\n    option          dontlognull\r\n    option http-server-close\r\n    option          redispatch\r\n    retries         3\r\n    timeout http-request 10s\r\n    timeout queue   1m\r\n    timeout connect 10s\r\n    timeout client  1m\r\n    timeout server  1m\r\n    timeout http-keep-alive 10s\r\n    timeout check   10s\r\n    maxconn         3000\r\nfrontend    mysql\r\n    bind        0.0.0.0:13307\r\n    mode        tcp\r\n    log         global\r\n    default_backend mysql_server\r\n\r\nbackend     mysql_server\r\n    balance roundrobin\r\n    server mysql1 192.168.228.131:3307 check inter 5s rise 2 fall 3\r\n    server mysql2 192.168.228.131:3308 check inter 5s rise 2 fall 3\r\n\r\nlisten stats\r\n    mode    http\r\n    bind    0.0.0.0:1080\r\n    stats   enable\r\n    stats   hide-version\r\n    stats uri \/haproxyamdin?stats\r\n    stats realm Haproxy\\ Statistics\r\n    stats auth admin:admin\r\n    stats admin if TRUE\r\n<\/pre>\n

1080\u7aef\u53e3\u4e3a\u53ef\u89c6\u5316\u754c\u9762
\n\"\"<\/p>\n

4.\u6784\u5efa\u76f8\u5173\u5bb9\u5668<\/strong><\/span><\/div>\n
\r\ndocker run -p 1080:1080 -p 13307:13307 -d --name haproxy-master -v \/docker\/haproxy-master\/haproxy.cfg:\/usr\/local\/etc\/haproxy\/haproxy.cfg --privileged=true haproxy\r\n<\/pre>\n
5.\u8d1f\u8f7d\u5747\u8861\u6d4b\u8bd5\uff08\u672c\u5730\u8fde\u63a5\uff09<\/strong><\/span><\/div>\n

\"\"<\/p>\n

\u53ef\u4ee5\u770b\u5230\u8bbf\u95ee\u4e0d\u540c\u7684server_id\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"

HAProxy\u63d0\u4f9b\u9ad8\u53ef\u7528\u6027\u3001\u8d1f\u8f7d\u5747\u8861\u4ee5\u53ca\u57fa\u4e8eTCP\u548cHTTP\u5e94\u7528\u7684\u4ee3\u7406\uff0c\u652f\u6301\u865a\u62df\u4e3b\u673a\uff0c\u5b83\u662f\u514d\u8d39\u3001\u5feb\u901f\u5e76\u4e14\u53ef\u9760\u7684 […]<\/p>\n","protected":false},"author":1903,"featured_media":218479,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-224794","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\/224794","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\/1903"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=224794"}],"version-history":[{"count":3,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/224794\/revisions"}],"predecessor-version":[{"id":225399,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/224794\/revisions\/225399"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/218479"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=224794"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=224794"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=224794"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}