\u52a8\u6001\u8d1f\u8f7d\u5747\u8861<\/strong><\/span><\/div>\n\u914d\u7f6eNginx\u56db\u5c42\u9759\u6001\u8d1f\u8f7d\u5747\u8861\u540e\uff0c\u91cd\u542fNginx\u65f6\uff0cWorker\u8fdb\u7a0b\u4e00\u76f4\u4e0d\u9000\u51fa\uff0c\u4f1a\u62a5\u9519\uff0c\u5982\u4e0b\u6240\u793a\u3002<\/p>\n
\r\nnginx: worker process is shutting down; \r\n<\/pre>\n\u8fd9\u662f\u56e0\u4e3aWorker\u8fdb\u7a0b\u7ef4\u6301\u7684\u957f\u8fde\u63a5\u4e00\u76f4\u5728\u4f7f\u7528\uff0c\u6240\u4ee5\u65e0\u6cd5\u9000\u51fa\uff0c\u53ea\u80fd\u6740\u6389\u8fdb\u7a0b\u3002\u53ef\u4ee5\u4f7f\u7528Nginx\u7684\u56db\u5c42\u52a8\u6001\u8d1f\u8f7d\u5747\u8861\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\u3002<\/p>\n
\u4f7f\u7528Nginx\u7684\u56db\u5c42\u52a8\u6001\u8d1f\u8f7d\u5747\u8861\u6709\u4e24\u79cd\u65b9\u6848\uff1a\u4f7f\u7528\u5546\u4e1a\u7248\u7684Nginx\u548c\u4f7f\u7528\u5f00\u6e90\u7684nginx-stream-upsync-module\u6a21\u5757\u3002\u6ce8\u610f\uff1a\u56db\u5c42\u52a8\u6001\u8d1f\u8f7d\u5747\u8861\u53ef\u4ee5\u4f7f\u7528nginx-stream-upsync-module\u6a21\u5757\uff0c\u4e03\u5c42\u52a8\u6001\u8d1f\u8f7d\u5747\u8861\u53ef\u4ee5\u4f7f\u7528nginx-upsync-module\u6a21\u5757\u3002<\/p>\n
\u4f7f\u7528\u5982\u4e0b\u547d\u4ee4\u4e3aNginx\u6dfb\u52a0nginx-stream-upsync-module\u6a21\u5757\u548cnginx-upsync-module\u6a21\u5757\uff0c\u6b64\u65f6\uff0cNginx\u4f1a\u540c\u65f6\u652f\u6301\u56db\u5c42\u52a8\u6001\u8d1f\u8f7d\u5747\u8861\u548cHTTP\u4e03\u5c42\u52a8\u6001\u8d1f\u8f7d\u5747\u8861\u3002<\/p>\n
\r\ngit clone https:\/\/github.com\/xiaokai-wang\/nginx-stream-upsync-module.git \r\ngit clone https:\/\/github.com\/weibocom\/nginx-upsync-module.git \r\ngit clone https:\/\/github.com\/CallMeFoxie\/nginx-upsync.git \r\ncp -r nginx-stream-upsync-module\/* nginx-upsync\/nginx-stream-upsync-module\/ \r\ncp -r nginx-upsync-module\/* nginx-upsync\/nginx-upsync-module\/ \r\n \r\n.\/configure --prefix=\/usr\/local\/nginx-1.17.2 --with-openssl=\/usr\/local\/src\/openssl-1.0.2s --with-pcre=\/usr\/local\/src\/pcre-8.43 --with-zlib=\/usr\/local\/src\/zlib-1.2.11 --with-http_realip_module --with-http_stub_status_module --with-http_ssl_module --with-http_flv_module --with-http_gzip_static_module --with-cc-opt=-O3 --with-stream --add-module=\/usr\/local\/src\/nginx-upsync --with-http_ssl_module\r\n<\/pre>\n\u914d\u7f6e\u56db\u5c42\u8d1f\u8f7d\u5747\u8861<\/strong><\/span><\/div>\n\u914d\u7f6eHTTP\u8d1f\u8f7d\u5747\u8861\u65f6\uff0c\u90fd\u662f\u914d\u7f6e\u5728http\u6307\u4ee4\u4e0b\uff0c\u914d\u7f6e\u56db\u5c42\u8d1f\u8f7d\u5747\u8861\uff0c\u5219\u662f\u5728stream\u6307\u4ee4\u4e0b\uff0c\u7ed3\u6784\u5982\u4e0b\u6240\u793a\uff0c<\/p>\n
\r\nstream { \r\n upstream mysql_backend { \r\n ...... \r\n } \r\n server { \r\n ...... \r\n } \r\n} \r\n<\/pre>\n\u914d\u7f6eupstream<\/strong><\/span><\/div>\n\r\nupstream mysql_backend { \r\n server 127.0.0.1:1111; #\u5360\u4f4dserver \r\n upsync 192.168.175.100:8500\/v1\/kv\/upstreams\/mysql_backend upsync_timeout=6m upsync_interval=500ms upsync_type=consul strong_dependency=off; \r\n upsync_dump_path \/usr\/local\/nginx-1.17.2\/conf\/mysql_backend.conf; \r\n} \r\n<\/pre>\nupsync\u6307\u4ee4\u6307\u5b9a\u4ececonsul\u54ea\u4e2a\u8def\u5f84\u62c9\u53d6\u4e0a\u6e38\u670d\u52a1\u5668\u914d\u7f6e;<\/p>\n
upsync_timeout\u914d\u7f6e\u4ececonsul\u62c9\u53d6\u4e0a\u6e38\u670d\u52a1\u5668\u914d\u7f6e\u7684\u8d85\u65f6\u65f6\u95f4;<\/p>\n
upsync_interval\u914d\u7f6e\u4ececonsul\u62c9\u53d6\u4e0a\u6e38\u670d\u52a1\u5668\u914d\u7f6e\u7684\u95f4\u9694\u65f6\u95f4;<\/p>\n
upsync_type\u6307\u5b9a\u4f7f\u7528consul\u914d\u7f6e\u670d\u52a1\u5668;<\/p>\n
strong_dependency\u914d\u7f6enginx\u5728\u542f\u52a8\u65f6\u662f\u5426\u5f3a\u5236\u4f9d\u8d56\u914d\u7f6e\u670d\u52a1\u5668\uff0c\u5982\u679c\u914d\u7f6e\u4e3aon\uff0c\u5219\u62c9\u53d6\u914d\u7f6e\u5931\u8d25\u65f6Nginx\u542f\u52a8\u540c\u6837\u5931\u8d25\u3002<\/p>\n
upsync_dump_path\u6307\u5b9a\u4ececonsul\u62c9\u53d6\u7684\u4e0a\u6e38\u670d\u52a1\u5668\u540e\u6301\u4e45\u5316\u5230\u7684\u4f4d\u7f6e\uff0c\u8fd9\u6837\u5373\u4f7fconsul\u670d\u52a1\u5668\u51fa\u73b0\u95ee\u9898\uff0c\u672c\u5730\u8fd8\u6709\u4e00\u4e2a\u5907\u4efd<\/p>\n
\u914d\u7f6eserver<\/strong><\/span><\/div>\n\r\nserver { \r\n #\u76d1\u542c\u7aef\u53e3\uff0c\u9ed8\u8ba4\u4f7f\u7528\u7684\u662ftcp\u534f\u8bae\uff0c\u5982\u679c\u9700\u8981UDP\u534f\u8bae\uff0c\u5219\u914d\u7f6e\u6210listen 3307 udp; \r\n listen 3307; \r\n #\u5931\u8d25\u91cd\u8bd5 \r\n proxy_next_upstream on; \r\n proxy_next_upstream_timeout 0; \r\n proxy_next_upstream_tries 0; \r\n #\u8d85\u65f6\u914d\u7f6e \r\n #\u914d\u7f6e\u4e0e\u4e0a\u6e38\u670d\u52a1\u5668\u8fde\u63a5\u8d85\u65f6\u65f6\u95f4\uff0c\u9ed8\u8ba460s \r\n proxy_connect_timeout 1s; \r\n #\u914d\u7f6e\u4e0e\u5ba2\u6237\u7aef\u4e0a\u6e38\u670d\u52a1\u5668\u8fde\u63a5\u7684\u4e24\u6b21\u6210\u529f\u8bfb\/\u5199\u64cd\u4f5c\u7684\u8d85\u65f6\u65f6\u95f4\uff0c\u5982\u679c\u8d85\u65f6\uff0c\u5c06\u81ea\u52a8\u65ad\u5f00\u8fde\u63a5 \r\n #\u5373\u8fde\u63a5\u5b58\u6d3b\u65f6\u95f4\uff0c\u901a\u8fc7\u5b83\u53ef\u4ee5\u91ca\u653e\u4e0d\u6d3b\u8dc3\u7684\u8fde\u63a5\uff0c\u9ed8\u8ba410\u5206\u949f \r\n proxy_timeout 1m; \r\n #\u9650\u901f\u914d\u7f6e \r\n #\u4ece\u5ba2\u6237\u7aef\u8bfb\u6570\u636e\u7684\u901f\u7387\uff0c\u5355\u4f4d\u4e3a\u6bcf\u79d2\u5b57\u8282\u6570\uff0c\u9ed8\u8ba4\u4e3a0\uff0c\u4e0d\u9650\u901f \r\n proxy_upload_rate 0; \r\n #\u4ece\u4e0a\u6e38\u670d\u52a1\u5668\u8bfb\u6570\u636e\u7684\u901f\u7387\uff0c\u5355\u4f4d\u4e3a\u6bcf\u79d2\u5b57\u8282\u6570\uff0c\u9ed8\u8ba4\u4e3a0\uff0c\u4e0d\u9650\u901f \r\n proxy_download_rate 0; \r\n #\u4e0a\u6e38\u670d\u52a1\u5668 \r\n proxy_pass mysql_backend; \r\n} \r\n<\/pre>\n\u4eceConsul\u6dfb\u52a0\u4e0a\u6e38\u670d\u52a1\u5668<\/strong><\/span><\/div>\n\r\ncurl -X PUT -d \"{\\\"weight\\\":1, \\\"max_fails\\\":2, \\\"fail_timeout\\\":10}\" http:\/\/192.168.175.100:8500\/v1\/kv\/upstreams\/mysql_backend\/192.168.175.201:3306 \r\ncurl -X PUT -d \"{\\\"weight\\\":1, \\\"max_fails\\\":2, \\\"fail_timeout\\\":10}\" http:\/\/192.168.175.100:8500\/v1\/kv\/upstreams\/mysql_backend\/192.168.175.202:3306 \r\n<\/pre>\n\u4eceConsul\u5220\u9664\u4e0a\u6e38\u670d\u52a1\u5668<\/strong><\/span><\/div>\n\r\ncurl -X DELETE http:\/\/192.168.175.100:8500\/v1\/kv\/upstreams\/mysql_backend\/192.168.175.202:3306\r\n<\/pre>\n\u914d\u7f6eupstream_show<\/strong><\/span><\/div>\n\r\nserver { \r\n listen 13307; \r\n upstream_show; \r\n} \r\n<\/pre>\n\u914d\u7f6eupstream_show\u6307\u4ee4\u540e\uff0c\u53ef\u4ee5\u901a\u8fc7curl http:\/\/192.168.175.100:13307\/upstream_show\u67e5\u770b\u5f53\u524d\u52a8\u6001\u8d1f\u8f7d\u5747\u8861\u4e0a\u6e38\u670d\u52a1\u5668\u5217\u8868\u3002<\/p>\n
Nginx\u5b8c\u6574\u914d\u7f6e<\/strong><\/span><\/div>\nNginx\u7684\u5b8c\u6574\u914d\u7f6e\u5982\u4e0b\uff1a<\/p>\n
\r\nuser hadoop hadoop; \r\nworker_processes auto; \r\n \r\nerror_log logs\/error.log; \r\n#error_log logs\/error.log notice; \r\n#error_log logs\/error.log info; \r\n \r\n#pid logs\/nginx.pid; \r\n \r\n \r\nevents { \r\n use epoll; \r\n worker_connections 1024; \r\n} \r\n \r\nstream { \r\n upstream mysql_backend { \r\n server 127.0.0.1:1111; #\u5360\u4f4dserver \r\n upsync 192.168.175.100:8500\/v1\/kv\/upstreams\/mysql_backend upsync_timeout=6m upsync_interval=500ms upsync_type=consul strong_dependency=off; \r\n upsync_dump_path \/usr\/local\/nginx-1.17.2\/conf\/mysql_backend.conf; \r\n } \r\n server { \r\n #\u76d1\u542c\u7aef\u53e3\uff0c\u9ed8\u8ba4\u4f7f\u7528\u7684\u662ftcp\u534f\u8bae\uff0c\u5982\u679c\u9700\u8981UDP\u534f\u8bae\uff0c\u5219\u914d\u7f6e\u6210listen 3307 udp; \r\n listen 3307; \r\n #\u5931\u8d25\u91cd\u8bd5 \r\n proxy_next_upstream on; \r\n proxy_next_upstream_timeout 0; \r\n proxy_next_upstream_tries 0; \r\n #\u8d85\u65f6\u914d\u7f6e \r\n #\u914d\u7f6e\u4e0e\u4e0a\u6e38\u670d\u52a1\u5668\u8fde\u63a5\u8d85\u65f6\u65f6\u95f4\uff0c\u9ed8\u8ba460s \r\n proxy_connect_timeout 1s; \r\n #\u914d\u7f6e\u4e0e\u5ba2\u6237\u7aef\u4e0a\u6e38\u670d\u52a1\u5668\u8fde\u63a5\u7684\u4e24\u6b21\u6210\u529f\u8bfb\/\u5199\u64cd\u4f5c\u7684\u8d85\u65f6\u65f6\u95f4\uff0c\u5982\u679c\u8d85\u65f6\uff0c\u5c06\u81ea\u52a8\u65ad\u5f00\u8fde\u63a5 \r\n #\u5373\u8fde\u63a5\u5b58\u6d3b\u65f6\u95f4\uff0c\u901a\u8fc7\u5b83\u53ef\u4ee5\u91ca\u653e\u4e0d\u6d3b\u8dc3\u7684\u8fde\u63a5\uff0c\u9ed8\u8ba410\u5206\u949f \r\n proxy_timeout 1m; \r\n #\u9650\u901f\u914d\u7f6e \r\n #\u4ece\u5ba2\u6237\u7aef\u8bfb\u6570\u636e\u7684\u901f\u7387\uff0c\u5355\u4f4d\u4e3a\u6bcf\u79d2\u5b57\u8282\u6570\uff0c\u9ed8\u8ba4\u4e3a0\uff0c\u4e0d\u9650\u901f \r\n proxy_upload_rate 0; \r\n #\u4ece\u4e0a\u6e38\u670d\u52a1\u5668\u8bfb\u6570\u636e\u7684\u901f\u7387\uff0c\u5355\u4f4d\u4e3a\u6bcf\u79d2\u5b57\u8282\u6570\uff0c\u9ed8\u8ba4\u4e3a0\uff0c\u4e0d\u9650\u901f \r\n proxy_download_rate 0; \r\n #\u4e0a\u6e38\u670d\u52a1\u5668 \r\n proxy_pass mysql_backend; \r\n } \r\n server { \r\n listen 13307; \r\n upstream_show; \r\n } \r\n} \r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"Nginx\u7684\u56db\u5c42\u9759\u6001\u8d1f\u8f7d\u5747\u8861\u9700\u8981\u542f\u7528ngx_stream_core_module\u6a21\u5757\uff0c\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0cngx_st […]<\/p>\n","protected":false},"author":668,"featured_media":7290,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-201360","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-thread"],"acf":[],"_links":{"self":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/201360","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/users\/668"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=201360"}],"version-history":[{"count":3,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/201360\/revisions"}],"predecessor-version":[{"id":201363,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/201360\/revisions\/201363"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/7290"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=201360"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=201360"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=201360"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}