{"id":859,"date":"2025-02-13T17:11:41","date_gmt":"2025-02-13T09:11:41","guid":{"rendered":"http:\/\/192.168.5.24\/?p=859"},"modified":"2025-02-13T17:11:43","modified_gmt":"2025-02-13T09:11:43","slug":"docker-compose%e5%88%9b%e5%bb%ba1%e4%b8%aahaproxy%e5%92%8c3%e4%b8%aaweb%e5%ae%b9%e5%99%a8%ef%bc%8c%e5%ae%9e%e7%8e%b0%e8%b4%9f%e8%bd%bd%e5%9d%87%e8%a1%a1","status":"publish","type":"post","link":"https:\/\/bigvip.dpdns.org\/?p=859","title":{"rendered":"docker-compose\u521b\u5efa1\u4e2ahaproxy\u548c3\u4e2aweb\u5bb9\u5668\uff0c\u5b9e\u73b0\u8d1f\u8f7d\u5747\u8861"},"content":{"rendered":"\n<pre class=\"wp-block-code\"><code><strong>1.\u521b\u5efa\u4e00\u4e2a\u5de5\u7a0b\u76ee\u5f55haproxy<\/strong>\n&#91;root@wen ~]# mkdir haproxypro\n&#91;root@wen ~]# cd haproxypro\/\n<strong>2.\u4e0b\u8f7dhaproxy\u955c\u50cf<\/strong>\n&#91;root@wen haproxypro]# docker pull haproxy:2.0.29-alpine\n<strong>3.\u57fa\u4e8e\u57fa\u7840\u955c\u50cf\u5236\u4f5cweb\u5e94\u7528\u955c\u50cf<\/strong>\n&#91;root@wen haproxypro]# cat Dockerfile\nFROM centos\nRUN rm \/etc\/yum.repos.d\/* &amp;&amp; yum clean all\nADD CentOS8-Base.repo \/etc\/yum.repos.d\/\nRUN yum -y install httpd\nADD index.html \/var\/www\/html\/\nCMD \/usr\/sbin\/httpd -D FOREGROUND\n&#91;root@wen haproxypro]# echo \"httpd v11111\"  >index.html\n&#91;root@wen haproxypro]# docker build -t centos-httpd:v1 .\n<strong>4.\u51c6\u5907haproxy.cfg\u914d\u7f6e\u6587\u4ef6<\/strong>\n&#91;root@wen haproxypro~]# cat haproxy.cfg \nglobal\nlog 127.0.0.1 local0 info \nmaxconn 256\nchroot <strong>\/usr\/local\/etc\/haproxy<\/strong>\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 weba:80 check inter 2000 rise 2 fall 2 \nserver server2 webb:80 check inter 2000 rise 2 fall 2 \nserver server3 webc: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\n\n<strong>5.\u521b\u5efadocker-compose.yml\u7f16\u6392\u6587\u4ef6<\/strong>\n&#91;root@wen haproxypro]# vi docker-compose.yml\nservices:\n weba:\n  image: centos-httpd:v1\n webb:\n  image: centos-httpd:v1\n webc:\n  image: centos-httpd:v1\n haproxy:\n  image: haproxy:2.0.29-alpine\n  volumes:\n    - .\/haproxy.cfg:\/usr\/local\/etc\/haproxy\/haproxy.cfg\n  links:\n    - weba\n    - webb\n    - webc\n  ports:\n    - \"80:80\"\n    - \"9999:9999\"\n\n<strong>6.\u542f\u52a8\u5e94\u7528<\/strong>\n&#91;root@wen haproxypro]# docker-compose up<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"111\" src=\"http:\/\/192.168.5.24\/wp-content\/uploads\/2025\/02\/image-3-1024x111.png\" alt=\"\" class=\"wp-image-866\" srcset=\"https:\/\/bigvip.dpdns.org\/wp-content\/uploads\/2025\/02\/image-3-1024x111.png 1024w, https:\/\/bigvip.dpdns.org\/wp-content\/uploads\/2025\/02\/image-3-300x33.png 300w, https:\/\/bigvip.dpdns.org\/wp-content\/uploads\/2025\/02\/image-3-768x83.png 768w, https:\/\/bigvip.dpdns.org\/wp-content\/uploads\/2025\/02\/image-3-1536x167.png 1536w, https:\/\/bigvip.dpdns.org\/wp-content\/uploads\/2025\/02\/image-3-816x89.png 816w, https:\/\/bigvip.dpdns.org\/wp-content\/uploads\/2025\/02\/image-3.png 1657w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>7.\u9a8c\u8bc1\u5bb9\u5668\u662f\u5426\u5168\u90e8\u542f\u52a8<\/strong><\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"61\" src=\"http:\/\/192.168.5.24\/wp-content\/uploads\/2025\/02\/image-4-1024x61.png\" alt=\"\" class=\"wp-image-867\" srcset=\"https:\/\/bigvip.dpdns.org\/wp-content\/uploads\/2025\/02\/image-4-1024x61.png 1024w, https:\/\/bigvip.dpdns.org\/wp-content\/uploads\/2025\/02\/image-4-300x18.png 300w, https:\/\/bigvip.dpdns.org\/wp-content\/uploads\/2025\/02\/image-4-768x46.png 768w, https:\/\/bigvip.dpdns.org\/wp-content\/uploads\/2025\/02\/image-4-1536x91.png 1536w, https:\/\/bigvip.dpdns.org\/wp-content\/uploads\/2025\/02\/image-4-816x48.png 816w, https:\/\/bigvip.dpdns.org\/wp-content\/uploads\/2025\/02\/image-4.png 1602w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>8.\u9a8c\u8bc1\u8d1f\u8f7d\u5747\u8861<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"288\" src=\"http:\/\/192.168.5.24\/wp-content\/uploads\/2025\/02\/image-6-1024x288.png\" alt=\"\" class=\"wp-image-869\" srcset=\"https:\/\/bigvip.dpdns.org\/wp-content\/uploads\/2025\/02\/image-6-1024x288.png 1024w, https:\/\/bigvip.dpdns.org\/wp-content\/uploads\/2025\/02\/image-6-300x84.png 300w, https:\/\/bigvip.dpdns.org\/wp-content\/uploads\/2025\/02\/image-6-768x216.png 768w, https:\/\/bigvip.dpdns.org\/wp-content\/uploads\/2025\/02\/image-6-1536x433.png 1536w, https:\/\/bigvip.dpdns.org\/wp-content\/uploads\/2025\/02\/image-6-816x230.png 816w, https:\/\/bigvip.dpdns.org\/wp-content\/uploads\/2025\/02\/image-6.png 1914w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>8.\u9a8c\u8bc1\u8d1f\u8f7d\u5747\u8861<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"aside","meta":{"footnotes":""},"categories":[20,31,36],"tags":[27,110,85],"class_list":["post-859","post","type-post","status-publish","format-aside","hentry","category-linux","category-web","category-36","tag-docker","tag-docker-compose","tag-haproxy","post_format-post-format-aside"],"_links":{"self":[{"href":"https:\/\/bigvip.dpdns.org\/index.php?rest_route=\/wp\/v2\/posts\/859","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=859"}],"version-history":[{"count":7,"href":"https:\/\/bigvip.dpdns.org\/index.php?rest_route=\/wp\/v2\/posts\/859\/revisions"}],"predecessor-version":[{"id":870,"href":"https:\/\/bigvip.dpdns.org\/index.php?rest_route=\/wp\/v2\/posts\/859\/revisions\/870"}],"wp:attachment":[{"href":"https:\/\/bigvip.dpdns.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=859"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/bigvip.dpdns.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=859"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/bigvip.dpdns.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=859"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}