{"id":9444,"date":"2024-03-30T19:43:57","date_gmt":"2024-03-30T11:43:57","guid":{"rendered":"https:\/\/egonlin.com\/?p=9444"},"modified":"2024-03-30T19:43:57","modified_gmt":"2024-03-30T11:43:57","slug":"nginx%e6%b7%bb%e5%8a%a0nginx-sticky-module%e6%a8%a1%e5%9d%97%e6%ad%a5%e9%aa%a4","status":"publish","type":"post","link":"https:\/\/egonlin.com\/?p=9444","title":{"rendered":"nginx\u6dfb\u52a0nginx-sticky-module\u6a21\u5757\u6b65\u9aa4"},"content":{"rendered":"<p>\u5728\u5927\u591a\u6570\u60c5\u51b5\u4e0b\uff0c\u57fa\u4e8eYum\u7684\u7cfb\u7edf\uff08\u5982CentOS\u3001Fedora\u6216RHEL\uff09\u4e00\u822c\u6ca1\u6709\u63d0\u4f9b\u5305\u542b\u50cfnginx-sticky-module\u548cnginx_upstream_fair\u8fd9\u6837\u7b2c\u4e09\u65b9\u6a21\u5757\u7684Nginx\u9884\u7f16\u8bd1\u5305\u3002\u8fd9\u5c31\u610f\u5473\u7740\uff0c\u4f60\u4e0d\u80fd\u76f4\u63a5\u4f7f\u7528Yum\u6765\u5b89\u88c5\u5305\u542b\u8fd9\u4e9b\u6a21\u5757\u7684Nginx\u3002<\/p>\n<p>nginx-sticky-module\u6a21\u5757\u662fnginx\u5b9e\u73b0\u8d1f\u8f7d\u5747\u8861\u7684\u4e00\u79cd\u65b9\u6848,\u548cip_hash\u8d1f\u8f7d\u5747\u8861\u7b97\u6cd5\u4f1a\u6709\u533a\u522b\u7684<br \/>\nip_hash \u6839\u636e\u5ba2\u6237\u7aefip\u5c06\u8bf7\u6c42\u5206\u914d\u5230\u4e0d\u540c\u7684\u670d\u52a1\u5668\u4e0a.<br \/>\nsticky \u6839\u636e\u670d\u52a1\u5668\u4e2a\u5ba2\u6237\u7aef\u7684cookie,\u5ba2\u6237\u7aef\u518d\u6b21\u8bf7\u6c42\u662f\u4f1a\u5e26\u4e0a\u6b64cookie,nginx\u4f1a\u628a\u6709\u6b21cookie\u7684\u8bf7\u6c42\u8f6c\u53d1\u5230\u9881\u53d1cookie\u7684\u670d\u52a1\u5668\u4e0a.<br \/>\n\u5b89\u88c5Sticky<\/p>\n<p>1\u3001\u4e0b\u8f7dsticky<\/p>\n<pre><code># \u521b\u5efa\u76ee\u5f55\nmkdir \/usr\/local\/nginx\/module\ncd \/usr\/local\/nginx\/module\n#\u4e0b\u8f7dsticky\nwget https:\/\/bitbucket.org\/nginx-goodies\/nginx-sticky-module-ng\/get\/master.tar.gz\ntar xf master.tar.gz\n#\u89e3\u538b\ntar -zxvf master.tar.gz<\/code><\/pre>\n<p>2\u3001\u7f16\u8bd1nginx<\/p>\n<pre><code># \u8fdb\u5165nginx\u5b89\u88c5\u76ee\u5f55\ncd \/usr\/local\/nginx-1.9.9\n.\/configure --prefix=\/usr\/local\/nginx-1.9.9 \\\n--sbin-path=\/usr\/local\/nginx\/sbin\/nginx \\\n--conf-path=\/usr\/local\/nginx\/conf\/nginx.conf \\\n--pid-path=\/usr\/local\/nginx\/run\/nginx.pid \\\n--error-log-path=\/usr\/local\/nginx\/logs\/error.log \\\n--http-log-path=\/usr\/local\/nginx\/logs\/access.log \\\n--with-pcre \\\n--user=nginx \\\n--group=nginx \\\n--with-stream \\\n--with-threads \\\n--with-file-aio \\\n--with-http_v2_module \\\n--with-http_ssl_module \\\n--with-http_realip_module \\\n--with-http_gzip_static_module \\\n--with-http_stub_status_module \\\n--add-module=\/usr\/local\/nginx\/module\/nginx-sticky-module            #\u5728\u6b64\u8f7d\u5165sticky\u6a21\u5757\nmake\n#\u66f4\u65b0\u68c0\u6d4b\nmake upgrade <\/code><\/pre>\n<p>3\u3001\u67e5\u770b\u6a21\u5757\u662f\u5426\u88ab\u8f7d\u5165<\/p>\n<pre><code>cd \/usr\/local\/nginx-1.9.9\n.\/sbin\/nginx -V<\/code><\/pre>\n<p>\u5982\u4e0b\u56fe\u8868\u8868\u793a\u6dfb\u52a0\u6210\u529f<br \/>\n<div class='fancybox-wrapper lazyload-container-unload' data-fancybox='post-images' href='https:\/\/egonlin.com\/wp-content\/uploads\/2024\/03\/image-1711798926909.png'><img class=\"lazyload lazyload-style-2\" src=\"data:image\/svg+xml;base64,PCEtLUFyZ29uTG9hZGluZy0tPgo8c3ZnIHdpZHRoPSIxIiBoZWlnaHQ9IjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgc3Ryb2tlPSIjZmZmZmZmMDAiPjxnPjwvZz4KPC9zdmc+\"  data-original=\"https:\/\/egonlin.com\/wp-content\/uploads\/2024\/03\/image-1711798926909.png\" src=\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB\/AAffA0nNPuCLAAAAAElFTkSuQmCC\" alt=\"file\" \/><\/div><br \/>\n4\u3001\u4f7f\u7528<\/p>\n<pre><code>upstream backend {\n        sticky name=ngx_cookie expires=6h;\n        server 192.168.31.240:8080 weight=3 max_fails=3 fail_timeout=10s;\n        server 192.168.31.241:8080 weight=3 max_fails=3 fail_timeout=10s;\n        server 192.168.31.242:8080 weight=6 max_fails=3 fail_timeout=10s;\n        server 192.168.31.243:8080;\n        server 192.168.31.244:8080 down;\n}<\/code><\/pre>\n<p>name: cookie\u7684\u540d\u79f0<br \/>\nexpire: \u6709\u6548\u671f<br \/>\n5\u3001nginx \u542f\u52a8 \u505c\u6b62 \u91cd\u542f\u547d\u4ee4<\/p>\n<pre><code>\/usr\/local\/nginx-1.9.9\/sbin\/nginx -s start\n\/usr\/local\/nginx1.9.9\/sbin\/nginx -s stop\n\/usr\/local\/nginx1.9.9\/sbin\/nginx -s reload<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u5728\u5927\u591a\u6570\u60c5\u51b5\u4e0b\uff0c\u57fa\u4e8eYum\u7684\u7cfb\u7edf\uff08\u5982CentOS\u3001Fedora\u6216RHEL\uff09\u4e00\u822c\u6ca1\u6709\u63d0\u4f9b\u5305\u542b\u50cfnginx-sti [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[],"_links":{"self":[{"href":"https:\/\/egonlin.com\/index.php?rest_route=\/wp\/v2\/posts\/9444"}],"collection":[{"href":"https:\/\/egonlin.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/egonlin.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/egonlin.com\/index.php?rest_route=\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/egonlin.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=9444"}],"version-history":[{"count":1,"href":"https:\/\/egonlin.com\/index.php?rest_route=\/wp\/v2\/posts\/9444\/revisions"}],"predecessor-version":[{"id":9446,"href":"https:\/\/egonlin.com\/index.php?rest_route=\/wp\/v2\/posts\/9444\/revisions\/9446"}],"wp:attachment":[{"href":"https:\/\/egonlin.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=9444"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/egonlin.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=9444"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/egonlin.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=9444"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}