{"id":42904,"date":"2024-10-04T08:41:46","date_gmt":"2024-10-04T00:41:46","guid":{"rendered":"https:\/\/server.hk\/cnblog\/42904\/"},"modified":"2024-10-04T08:41:46","modified_gmt":"2024-10-04T00:41:46","slug":"centos-7-2-%e9%83%a8%e7%bd%b2-haproxy-1-7-2","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/42904\/","title":{"rendered":"CentOS 7.2 \u90e8\u7f72 Haproxy 1.7.2"},"content":{"rendered":"<h1 id=\"centos-7-2-%e9%83%a8%e7%bd%b2-haproxy-1-7-2-OMUgndqDtW\">CentOS 7.2 \u90e8\u7f72 Haproxy 1.7.2<\/h1>\n<p>\u5728\u7576\u4eca\u7684\u7db2\u7d61\u74b0\u5883\u4e2d\uff0c\u8ca0\u8f09\u5747\u8861\u5668\u626e\u6f14\u8457\u81f3\u95dc\u91cd\u8981\u7684\u89d2\u8272\u3002Haproxy \u662f\u4e00\u6b3e\u5ee3\u6cdb\u4f7f\u7528\u7684\u958b\u6e90\u8ca0\u8f09\u5747\u8861\u5668\uff0c\u80fd\u5920\u6709\u6548\u5730\u5206\u914d\u6d41\u91cf\uff0c\u63d0\u5347\u61c9\u7528\u7a0b\u5e8f\u7684\u53ef\u7528\u6027\u548c\u6027\u80fd\u3002\u672c\u6587\u5c07\u4ecb\u7d39\u5982\u4f55\u5728 CentOS 7.2 \u4e0a\u90e8\u7f72 Haproxy 1.7.2\uff0c\u4e26\u63d0\u4f9b\u8a73\u7d30\u7684\u6b65\u9a5f\u548c\u793a\u4f8b\u3002<\/p>\n<h2 id=\"%e5%89%8d%e6%9c%9f%e6%ba%96%e5%82%99-OMUgndqDtW\">\u524d\u671f\u6e96\u5099<\/h2>\n<p>\u5728\u958b\u59cb\u4e4b\u524d\uff0c\u78ba\u4fdd\u4f60\u7684 CentOS 7.2 \u7cfb\u7d71\u5df2\u7d93\u66f4\u65b0\u5230\u6700\u65b0\u7248\u672c\u3002\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u9032\u884c\u66f4\u65b0\uff1a<\/p>\n<pre><code>sudo yum update -y<\/code><\/pre>\n<p>\u63a5\u4e0b\u4f86\uff0c\u5b89\u88dd EPEL\uff08Extra Packages for Enterprise Linux\uff09\u5eab\uff0c\u56e0\u70ba Haproxy \u53ef\u80fd\u9700\u8981\u5f9e\u9019\u500b\u5eab\u4e2d\u7372\u53d6\u4f9d\u8cf4\u5305\uff1a<\/p>\n<pre><code>sudo yum install epel-release -y<\/code><\/pre>\n<h2 id=\"%e5%ae%89%e8%a3%9d-haproxy-OMUgndqDtW\">\u5b89\u88dd Haproxy<\/h2>\n<p>\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u5b89\u88dd Haproxy 1.7.2\uff1a<\/p>\n<pre><code>sudo yum install haproxy-1.7.2 -y<\/code><\/pre>\n<p>\u5b89\u88dd\u5b8c\u6210\u5f8c\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u6aa2\u67e5 Haproxy \u7684\u7248\u672c\uff1a<\/p>\n<pre><code>haproxy -v<\/code><\/pre>\n<h2 id=\"%e9%85%8d%e7%bd%ae-haproxy-OMUgndqDtW\">\u914d\u7f6e Haproxy<\/h2>\n<p>Haproxy \u7684\u914d\u7f6e\u6587\u4ef6\u4f4d\u65bc \/etc\/haproxy\/haproxy.cfg\u3002\u4f7f\u7528\u6587\u672c\u7de8\u8f2f\u5668\u6253\u958b\u8a72\u6587\u4ef6\uff1a<\/p>\n<pre><code>sudo vi \/etc\/haproxy\/haproxy.cfg<\/code><\/pre>\n<p>\u4ee5\u4e0b\u662f\u4e00\u500b\u57fa\u672c\u7684 Haproxy \u914d\u7f6e\u793a\u4f8b\uff1a<\/p>\n<pre><code>global\n    log \/dev\/log local0\n    maxconn 2000\n    user haproxy\n    group haproxy\n    daemon\n\ndefaults\n    log global\n    mode http\n    option httplog\n    option dontlognull\n    timeout connect 5000ms\n    timeout client 50000ms\n    timeout server 50000ms\n\nfrontend http_front\n    bind *:80\n    acl is_websocket hdr(Upgrade) -i WebSocket\n    use_backend websocket_back if is_websocket\n    default_backend web_back\n\nbackend web_back\n    server web1 192.168.1.10:80 check\n    server web2 192.168.1.11:80 check\n\nbackend websocket_back\n    server ws1 192.168.1.12:80 check\n<\/code><\/pre>\n<p>\u5728\u9019\u500b\u914d\u7f6e\u4e2d\uff0c\u6211\u5011\u5b9a\u7fa9\u4e86\u4e00\u500b\u524d\u7aef\uff08frontend\uff09\u548c\u5169\u500b\u5f8c\u7aef\uff08backend\uff09\u3002\u524d\u7aef\u76e3\u807d 80 \u7aef\u53e3\uff0c\u4e26\u6839\u64da\u8acb\u6c42\u7684\u985e\u578b\u5c07\u6d41\u91cf\u5206\u914d\u5230\u4e0d\u540c\u7684\u5f8c\u7aef\u670d\u52d9\u5668\u3002<\/p>\n<h2 id=\"%e5%95%9f%e5%8b%95-haproxy-OMUgndqDtW\">\u555f\u52d5 Haproxy<\/h2>\n<p>\u914d\u7f6e\u5b8c\u6210\u5f8c\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u555f\u52d5 Haproxy\uff1a<\/p>\n<pre><code>sudo systemctl start haproxy<\/code><\/pre>\n<p>\u70ba\u4e86\u78ba\u4fdd Haproxy \u5728\u7cfb\u7d71\u555f\u52d5\u6642\u81ea\u52d5\u555f\u52d5\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n<pre><code>sudo systemctl enable haproxy<\/code><\/pre>\n<h2 id=\"%e6%aa%a2%e6%9f%a5-haproxy-%e7%8b%80%e6%85%8b-OMUgndqDtW\">\u6aa2\u67e5 Haproxy \u72c0\u614b<\/h2>\n<p>\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u6aa2\u67e5 Haproxy \u7684\u904b\u884c\u72c0\u614b\uff1a<\/p>\n<pre><code>sudo systemctl status haproxy<\/code><\/pre>\n<p>\u5982\u679c\u4e00\u5207\u6b63\u5e38\uff0c\u60a8\u61c9\u8a72\u6703\u770b\u5230 Haproxy \u6b63\u5728\u904b\u884c\u7684\u6d88\u606f\u3002<\/p>\n<h2 id=\"%e7%b8%bd%e7%b5%90-OMUgndqDtW\">\u7e3d\u7d50<\/h2>\n<p>\u672c\u6587\u4ecb\u7d39\u4e86\u5982\u4f55\u5728 CentOS 7.2 \u4e0a\u90e8\u7f72 Haproxy 1.7.2\uff0c\u5f9e\u5b89\u88dd\u5230\u914d\u7f6e\u518d\u5230\u555f\u52d5\u7684\u5b8c\u6574\u904e\u7a0b\u3002Haproxy \u662f\u4e00\u500b\u5f37\u5927\u7684\u5de5\u5177\uff0c\u53ef\u4ee5\u5e6b\u52a9\u60a8\u5be6\u73fe\u9ad8\u53ef\u7528\u6027\u548c\u8ca0\u8f09\u5747\u8861\u3002\u5982\u679c\u60a8\u9700\u8981\u66f4\u591a\u7684\u8cc7\u6e90\u6216\u670d\u52d9\uff0c\u8acb\u8003\u616e\u4f7f\u7528\u6211\u5011\u7684 <a href=\"https:\/\/server.hk\">\u9999\u6e2fVPS<\/a> \u89e3\u6c7a\u65b9\u6848\uff0c\u70ba\u60a8\u7684\u61c9\u7528\u63d0\u4f9b\u7a69\u5b9a\u7684\u652f\u6301\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Learn how to deploy HAProxy 1.7.2 on CentOS 7.2 for efficient load balancing and high availability in your server environment. Step-by-step guide included.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4924],"tags":[],"class_list":["post-42904","post","type-post","status-publish","format-standard","hentry","category-setup-tutorials"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/42904","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=42904"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/42904\/revisions"}],"predecessor-version":[{"id":42905,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/42904\/revisions\/42905"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=42904"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=42904"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=42904"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}