{"id":215,"date":"2026-01-23T06:56:21","date_gmt":"2026-01-23T06:56:21","guid":{"rendered":"https:\/\/blog.gpst.net.cn:4008\/?p=215"},"modified":"2026-01-28T06:24:15","modified_gmt":"2026-01-28T06:24:15","slug":"haproxy%e7%bc%96%e8%af%91%e5%ae%89%e8%a3%85%e4%b8%8e%e5%b9%b3%e6%bb%91%e9%87%8d%e5%90%af%e7%9a%84bash-shell%e8%84%9a%e6%9c%ac","status":"publish","type":"post","link":"https:\/\/opshub.com.cn\/?p=215","title":{"rendered":"HAProxy\u7f16\u8bd1\u5b89\u88c5\u4e0e\u5e73\u6ed1\u91cd\u542f\u7684bash shell\u811a\u672c"},"content":{"rendered":"\n<pre class=\"wp-block-code\"><code>#!\/bin\/bash\nset -euo pipefail\n\n# \u7f16\u8bd1HAProxy\necho \"\u5f00\u59cb\u7f16\u8bd1HAProxy...\"\nif ! make PREFIX=\/opt\/haproxy TARGET=linux-glibc ARCH=x86_64 USE_OPENSSL=1 ADDLIB=-lz; then\n    echo \"ERROR: HAProxy\u7f16\u8bd1\u5931\u8d25\uff01\" &gt;&amp;2\n    exit 1\nfi\n\n# \u5b89\u88c5HAProxy\necho \"\u5f00\u59cb\u5b89\u88c5HAProxy...\"\nif ! make PREFIX=\/opt\/haproxy install; then\n    echo \"ERROR: HAProxy\u5b89\u88c5\u5931\u8d25\uff01\" &gt;&amp;2\n    exit 1\nfi\n\n# \u6821\u9a8c\u914d\u7f6e\u6587\u4ef6\necho \"\u6821\u9a8cHAProxy\u914d\u7f6e\u6587\u4ef6...\"\nif \/opt\/haproxy\/sbin\/haproxy -f \/opt\/haproxy\/conf\/hy.conf -c; then\n    # \u83b7\u53d6\u8fd0\u884c\u4e2d\u7684HAProxy\u8fdb\u7a0bPID\n    hapid=\"$(ps -ef | grep -E \"&#091;\/]opt\/haproxy\/sbin\/haproxy.*hy.conf\" | awk '{print $2}')\"\n    \n    if &#091;&#091; -n \"$hapid\" ]]; then\n        echo \"\u53d1\u73b0\u8fd0\u884c\u4e2d\u7684HAProxy\u8fdb\u7a0b\uff1a$hapid\uff0c\u5f00\u59cb\u5e73\u6ed1\u91cd\u542f...\"\n        pid_array=($hapid)\n        for pid in \"${pid_array&#091;@]}\"; do\n            if &#091;&#091; \"$pid\" -gt \"1024\" ]]; then\n                \/opt\/haproxy\/sbin\/haproxy -f \/opt\/haproxy\/conf\/hy.conf -dr -dV -D -sf $pid\n                sleep 1\n            fi\n        done\n        sleep 2\n    else\n        echo \"\u672a\u53d1\u73b0\u8fd0\u884c\u4e2d\u7684HAProxy\u8fdb\u7a0b\uff0c\u76f4\u63a5\u542f\u52a8...\"\n        \/opt\/haproxy\/sbin\/haproxy -f \/opt\/haproxy\/conf\/hy.conf -dr -dV -D\n    fi\n\n    # \u9a8c\u8bc1\u8fdb\u7a0b\u72b6\u6001\n    echo \"\u5f53\u524dHAProxy\u8fdb\u7a0b\u72b6\u6001\uff1a\"\n    ps -ef | grep -E \"&#091;\/]opt\/haproxy\/sbin\/haproxy.*hy.conf\"\nelse\n    echo \"ERROR: HAProxy\u914d\u7f6e\u6587\u4ef6 \/opt\/haproxy\/conf\/hy.conf \u6821\u9a8c\u5931\u8d25\uff01\" &gt;&amp;2\n    exit 1\nfi\n\necho \"HAProxy\u7f16\u8bd1\u5b89\u88c5\/\u91cd\u542f\u5b8c\u6210\uff01\"<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9],"tags":[],"class_list":["post-215","post","type-post","status-publish","format-standard","hentry","category-9"],"_links":{"self":[{"href":"https:\/\/opshub.com.cn\/index.php?rest_route=\/wp\/v2\/posts\/215","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/opshub.com.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/opshub.com.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/opshub.com.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/opshub.com.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=215"}],"version-history":[{"count":2,"href":"https:\/\/opshub.com.cn\/index.php?rest_route=\/wp\/v2\/posts\/215\/revisions"}],"predecessor-version":[{"id":650,"href":"https:\/\/opshub.com.cn\/index.php?rest_route=\/wp\/v2\/posts\/215\/revisions\/650"}],"wp:attachment":[{"href":"https:\/\/opshub.com.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=215"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/opshub.com.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=215"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/opshub.com.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=215"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}