Nginx-Stream-UpSync-Module 是基于nginx四层TCP协议的弹性扩缩容方案,实现性能无损的扩容缩容:
当前模块支持etcd 和 consul,相关配置如下:
nginx-etcd:
stream { upstream test { # fake server otherwise ngx_stream_upstream will report error when startup server 127.0.0.1:11111; # all backend server will pull from etcd when startup and will delete fake server upsync 127.0.0.1:8500/v2/keys/upstreams/test upsync_timeout=6m upsync_interval=500ms upsync_type=etcd strong_dependency=off; upsync_dump_path /usr/local/nginx/conf/servers/servers_test.conf; } upstream bar { server 127.0.0.1:8090 weight=1, fail_timeout=10, max_fails=3; } server { listen 12345; proxy_connect_timeout 1s; proxy_timeout 3s; proxy_pass test; } server { listen 2345; upstream_show } server { listen 127.0.0.1:9091; proxy_responses 1; proxy_timeout 20s; proxy_pass bar; } }
nginx-consul:
stream { upstream test { # fake server otherwise ngx_stream_upstream will report error when startup server 127.0.0.1:11111; # all backend server will pull from consul when startup and will delete fake server upsync 127.0.0.1:8500/v1/kv/upstreams/test upsync_timeout=6m upsync_interval=500ms upsync_type=consul strong_dependency=off; upsync_dump_path /usr/local/nginx/conf/servers/servers_test.conf; } upstream bar { server 127.0.0.1:8090 weight=1, fail_timeout=10, max_fails=3; } server { listen 12345; proxy_connect_timeout 1s; proxy_timeout 3s; proxy_pass test; } server { listen 2345; upstream_show } server { listen 127.0.0.1:9091; proxy_responses 1; proxy_timeout 20s; proxy_pass bar; } }
相关设计文档可参考:https://github.com/weibocom/nginx-upsync-module/tree/master/doc;
设计原理一致。