{"id":9447,"date":"2024-03-30T19:53:44","date_gmt":"2024-03-30T11:53:44","guid":{"rendered":"https:\/\/egonlin.com\/?p=9447"},"modified":"2024-03-30T19:53:44","modified_gmt":"2024-03-30T11:53:44","slug":"nginx%e8%b4%9f%e8%bd%bd%e5%9d%87%e8%a1%a1fair%e6%a8%a1%e5%9d%97%e5%ae%89%e8%a3%85%e5%92%8c%e9%85%8d%e7%bd%ae","status":"publish","type":"post","link":"https:\/\/egonlin.com\/?p=9447","title":{"rendered":"nginx\u8d1f\u8f7d\u5747\u8861fair\u6a21\u5757\u5b89\u88c5\u548c\u914d\u7f6e"},"content":{"rendered":"<p>yum\u5b89\u88c5\u7684nginx\u662f\u4e0d\u5e26nginx-upstream-fair\u6a21\u5757\u7684\uff0c\u6240\u4ee5\u5728\u8d1f\u8f7d\u5747\u8861\u7684\u7b56\u7565\u4e2d\u4f7f\u7528fair\u4f1a\u62a5\u9519\u3002<\/p>\n<p>1\u3001\u5b89\u88c5nginx\u7684\u4f9d\u8d56\u5305<\/p>\n<pre><code>yum -y install gcc gcc-c++ make libtool zlib zlib-devel openssl openssl-devel pcre pcre-devel<\/code><\/pre>\n<p>2\u3001\u67e5\u770b\u539fnginx\u7248\u672c\u4fe1\u606f<\/p>\n<pre><code>#\/usr\/sbin\/nginx \u9ed8\u8ba4yun\u5b89\u88c5\u7684nginx\u6267\u884c\u884c\u6587\u8def\u5f84\n#-V\u5927\u5199\u7684v\u662f\u8be6\u7ec6\u7684\u7248\u672c\u548c\u914d\u7f6e\u4fe1\u606f\n\n\/usr\/sbin\/nginx -V\nnginx version: nginx\/1.18.0\nbuilt by gcc 4.8.5 20150623 (Red Hat 4.8.5-39) (GCC) \nbuilt with OpenSSL 1.0.2k-fips  26 Jan 2017\nTLS SNI support enabled\nconfigure arguments: --prefix=\/etc\/nginx --sbin-path=\/usr\/sbin\/nginx --modules-path=\/usr\/lib64\/nginx\/modules --conf-path=\/etc\/nginx\/nginx.conf --error-log-path=\/var\/log\/nginx\/error.log --http-log-path=\/var\/log\/nginx\/access.log --pid-path=\/var\/run\/nginx.pid --lock-path=\/var\/run\/nginx.lock --http-client-body-temp-path=\/var\/cache\/nginx\/client_temp --http-proxy-temp-path=\/var\/cache\/nginx\/proxy_temp --http-fastcgi-temp-path=\/var\/cache\/nginx\/fastcgi_temp --http-uwsgi-temp-path=\/var\/cache\/nginx\/uwsgi_temp --http-scgi-temp-path=\/var\/cache\/nginx\/scgi_temp --user=nginx --group=nginx --with-compat --with-file-aio --with-threads --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_mp4_module --with-http_random_index_module --with-http_realip_module --with-http_secure_link_module --with-http_slice_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-http_v2_module --with-mail --with-mail_ssl_module --with-stream --with-stream_realip_module --with-stream_ssl_module --with-stream_ssl_preread_module --with-cc-opt=&#039;-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -fPIC&#039; --with-ld-opt=&#039;-Wl,-z,relro -Wl,-z,now -pie&#039;<\/code><\/pre>\n<p>3\u3001 \u53bb\u4e0b\u8f7dnginx\u548cfair<br \/>\n\u53bbnginx\u5b98\u7f51\u627e\u5230\u5bf9\u5e94\u7684nginx\u7248\u672c\uff0c\u6211\u8fd9\u91cc\u662f1.18.0\uff0c\u6240\u4ee5\u76f4\u63a5\u4e0b\u8f7d<br \/>\n<a href=\"http:\/\/nginx.org\/download\/nginx-1.18.0.tar.gz\">http:\/\/nginx.org\/download\/nginx-1.18.0.tar.gz<\/a><br \/>\n\u53bbnginx\u6e90\u7801\u6a21\u5757https:\/\/www.nginx.com\/resources\/wiki\/modules\/fair_balancer\/\u4e0b\u8f7dnginx-upstream-fair\u6a21\u5757\u3002<br \/>\n\u5c06\u4e0b\u8f7d\u7684nginx\u548cfair\u6a21\u5757\u89e3\u538b\u5230\u672c\u5730\u76ee\u5f55\u3002\u8fd9\u91cc\u76f4\u63a5\u653e\u5230\/home\u76ee\u5f55\u4e0b\u4e86<\/p>\n<pre><code>[root@localhost home]# pwd\n\/home\n[root@localhost home]# ll\ntotal 1028\n-rw-r--r--. 1 root root   10073 Dec 19 13:23 gnosek-nginx-upstream-fair-a18b409.tar.gz\ndrwxr-xr-x. 9 1001 1001     186 Dec 19 13:29 nginx-1.18.0\n-rw-r--r--. 1 root root 1039530 Dec 19 13:21 nginx-1.18.0.tar.gz\ndrwxrwxr-x. 2 root root      89 Apr  8  2012 nginx-upstream-fair<\/code><\/pre>\n<p>4\u3001\u914d\u7f6efair\u6a21\u5757<br \/>\n\u8fdb\u5165nginx\u6e90\u7801\u76ee\u5f55\uff0c\u4f7f\u7528\u524d\u9762\u7b2c2\u6b65\u67e5\u51fa\u6765\u7684\u914d\u7f6e\u4fe1\u606fconfigure arguments:\uff0c\u5728\u540e\u9762\u6dfb\u52a0&#8211;add-module=\/home\/nginx-upstream-fair\u3002\u8fd9\u91cc\u662f\u4f60\u89e3\u538b\u7684nginx-upstream-fair\u8def\u5f84<\/p>\n<pre><code>.\/configure --prefix=\/etc\/nginx --sbin-path=\/usr\/sbin\/nginx --modules-path=\/usr\/lib64\/nginx\/modules --conf-path=\/etc\/nginx\/nginx.conf --error-log-path=\/var\/log\/nginx\/error.log --http-log-path=\/var\/log\/nginx\/access.log --pid-path=\/var\/run\/nginx.pid --lock-path=\/var\/run\/nginx.lock --http-client-body-temp-path=\/var\/cache\/nginx\/client_temp --http-proxy-temp-path=\/var\/cache\/nginx\/proxy_temp --http-fastcgi-temp-path=\/var\/cache\/nginx\/fastcgi_temp --http-uwsgi-temp-path=\/var\/cache\/nginx\/uwsgi_temp --http-scgi-temp-path=\/var\/cache\/nginx\/scgi_temp --user=nginx --group=nginx --with-compat --with-file-aio --with-threads --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_mp4_module --with-http_random_index_module --with-http_realip_module --with-http_secure_link_module --with-http_slice_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-http_v2_module --with-mail --with-mail_ssl_module --with-stream --with-stream_realip_module --with-stream_ssl_module --with-stream_ssl_preread_module --with-cc-opt=&#039;-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -fPIC&#039; --with-ld-opt=&#039;-Wl,-z,relro -Wl,-z,now -pie&#039; --add-module=\/home\/nginx-upstream-fair<\/code><\/pre>\n<p>5\u3001\u7f16\u8bd1<br \/>\n\u76f4\u63a5\u4f7f\u7528make\u7f16\u8bd1\uff0c\u4e0d\u8981\u52a0make install\u3002\u540e\u9762\u624b\u52a8\u53bb\u66ff\u6362\u5c31\u597d\u3002<\/p>\n<p>\u5982\u679c\u51fa\u73b0\u9519\u8bef\uff1a ngx_http_upstream_srv_conf_t\u2019 has no member named \u2018default_port<\/p>\n<pre><code>\/home\/nginx-upstream-fair\/ngx_http_upstream_fair_module.c: In function \u2018ngx_http_upstream_init_fair_rr\u2019:\n\/home\/nginx-upstream-fair\/ngx_http_upstream_fair_module.c:543:28: error: \u2018ngx_http_upstream_srv_conf_t\u2019 has no member named \u2018default_port\u2019\n     if (us-&gt;port == 0 &amp;&amp; us-&gt;default_port == 0) {\n                            ^\n\/home\/nginx-upstream-fair\/ngx_http_upstream_fair_module.c:553:51: error: \u2018ngx_http_upstream_srv_conf_t\u2019 has no member named \u2018default_port\u2019\n     u.port = (in_port_t) (us-&gt;port ? us-&gt;port : us-&gt;default_port);<\/code><\/pre>\n<p>\u627e\u5230nginx\u7684\u6e90\u7801 src\/http\/ngx_http_upstream.h\u6587\u4ef6\u627e\u5230ngx_http_upstream_srv_conf_s\u7ed3\u6784\u6dfb\u52a0in_port_t default_port;<\/p>\n<pre><code> struct ngx_http_upstream_srv_conf_s {\n    ngx_http_upstream_peer_t         peer;\n    void                           **srv_conf;\n\n    ngx_array_t                     *servers;  \/* ngx_http_upstream_server_t *\/\n\n    ngx_uint_t                       flags;\n    ngx_str_t                        host;\n    u_char                          *file_name;\n    ngx_uint_t                       line;\n    in_port_t                        port;\n    in_port_t                        default_port;\n    ngx_uint_t                       no_port;  \/* unsigned no_port:1 *\/\n\n#if (NGX_HTTP_UPSTREAM_ZONE)\n    ngx_shm_zone_t                  *shm_zone;\n#endif\n};<\/code><\/pre>\n<p>\u4fee\u6539\u4fdd\u5b58\u540e\uff0c\u518d\u56de\u5230\u4e4b\u524d\u7ee7\u7eedmake<br \/>\n6\u3001\u7528\u65b0\u7f16\u8bd1\u7684nginx\u6587\u4ef6\u8986\u76d6\u4e4b\u524d\u7684<br \/>\n\u7f16\u8bd1\u597d\u7684\u6587\u4ef6\u4f1a\u5728nginx\u6e90\u7801\u76ee\u5f55\u4e2d\u7684objs\u4e0b\u3002<\/p>\n<pre><code>mv \/usr\/sbin\/nginx \/usr\/sbin\/nginx_bak  # \u5907\u4efd\u539f\u6765\u7684\ncp \/home\/nginx-1.18.0\/objs\/nginx \/usr\/sbin\/ginx\nsystemctl start nginx<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>yum\u5b89\u88c5\u7684nginx\u662f\u4e0d\u5e26nginx-upstream-fair\u6a21\u5757\u7684\uff0c\u6240\u4ee5\u5728\u8d1f\u8f7d\u5747\u8861\u7684\u7b56\u7565\u4e2d\u4f7f\u7528fair\u4f1a [&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\/9447"}],"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=9447"}],"version-history":[{"count":1,"href":"https:\/\/egonlin.com\/index.php?rest_route=\/wp\/v2\/posts\/9447\/revisions"}],"predecessor-version":[{"id":9448,"href":"https:\/\/egonlin.com\/index.php?rest_route=\/wp\/v2\/posts\/9447\/revisions\/9448"}],"wp:attachment":[{"href":"https:\/\/egonlin.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=9447"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/egonlin.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=9447"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/egonlin.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=9447"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}