nginx-upsync-module基于 Nginx 實(shí)現(xiàn)動(dòng)態(tài)配置的模塊
nginx-upsync-module 是微博開源的一個(gè)基于 Nginx 實(shí)現(xiàn)動(dòng)態(tài)配置的模塊,通過拉取 Consul 或 etcd (及其它)的上游數(shù)據(jù),實(shí)現(xiàn)無需重新加載 Nginx ,動(dòng)態(tài)修改后端服務(wù)器屬性(weight,max_fails,down ...)。
修改配置文件并重新啟動(dòng) Nginx 可能并不總是很方便。 例如,當(dāng)遇到大流量和高負(fù)載,重啟 Nginx 并在此時(shí)重新加載配置會(huì)進(jìn)一步增加系統(tǒng)負(fù)載,并可能暫時(shí)降低性能。使用 nginx-upsync-module 模塊則可以在不影響性能的情況下,更加平滑的擴(kuò)展和收縮。
nginx-consul:
http {
upstream test {
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;
include /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 8080;
location = /proxy_test {
proxy_pass http://test;
}
location = /bar {
proxy_pass http://bar;
}
location = /upstream_show {
upstream_show;
}
}
}
nginx-etcd:
http {
upstream test {
upsync 127.0.0.1:2379/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;
include /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 8080;
location = /proxy_test {
proxy_pass http://test;
}
location = /bar {
proxy_pass http://bar;
}
location = /upstream_show {
upstream_show;
}
}
}評(píng)論
圖片
表情
