Project: Tengine (Orchestration & Management / Service Proxy)
File: ngx_http_upstream_dyups_module.md

This module can be used to update your upstream-list without reloadding Nginx. file: conf/nginx.conf `ATTENTION`: You MUST use nginx variable to do proxy_pass daemon off; error_log logs/error.log debug; events { } http { include conf/upstream.conf; server { listen 8080; location / { proxy_pass http://$host; } } server { listen 8088; location / { return 200 "8088"; } } server { listen 8089; location / { return 200 "8089"; } } server { listen 8081; location / { dyups_interface; } } } If your original config looks like this: proxypass http://upstreamname; please replace it with: set $ups upstream_name; proxy_pass http://$ups; `$ups` can be any valid nginx variable. file: conf/upstream.conf upstream host1 { server 127.0.0.1:8088; } upstream host2 { server 127.0.0.1:8089; } Only install dyups module ```bash $ ./configure --add-module=./modules/ngxhttpupstreamdyupsmodule $ ./configure --add-dynamic-module=./modules/ngxhttpupstreamdyupsmodule ``` Install dyups module with lua-nginx-module and upstream check module upstream check module: To make upstream check module work well with dyups module, you should use `./modules/ngxhttpupstreamcheckmodule`. lua-nginx-module: To enable , you MUST put `--add-module=./modules/ngxhttpluamodule` in front of `--add-module=./modules/ngxhttpupstreamdyups_module` in the `./configure` command. ```bash $ ./configure --add-module=./modules/ngxhttpupstreamcheckmodule --add-module=./modules/ngxhttpluamodule --add-module=./modules/ngxhttpupstreamdyups_module ``` Syntax: dyups_interface Default: `none` Context: `loc` This directive set the interface location where you can add or delete the upstream list. See the section of Interface for detail. Syntax: dyups_read_msg_timeout `time` Default: `1s` Context: `main` This directive set the interval of workers readding the commands from share memory. Syntax: dyups_shm_zone_size `size` Default: `2MB` Context: `main` This directive set the size of share memory which used to store the commands. Syntax: dyups_upstream_conf `path` Default: `none` Context: `main` This directive has been deprecated Syntax: dyups_trylock `on | off` Default: `off` Context: `main` You will get a better prefomance but it maybe not stable, and you will get a '409' when the update request conflicts with others. Syntax: dyups_read_msg_log `on | off` Default: `off` Context: `main` You can enable / disable log of workers readding the commands from share memory. The log looks like: ``` 2017/02/28 15:37:53

56806#0: [dyups] has 0 upstreams, 1 static, 0 deleted, all 1 ``` `/detail` get all upstreams and their servers `/list` get the list of upstreams `/upstream/name` find the upstream by it's name `/upstream/name` update one upstream `body` commands; `body` server ip:port; `/upstream/name` delete one upstream Call the interface, when you get the return code is `HTTPINTERNALSERVER_ERROR 500`, you need to reload nginx to make the Nginx work at a good state. If you got `HTTP_CONFLICT 409`, you need resend the same commands again latter. The /list and /detail interface will return `HTTPNOCONTENT 204` when there is no upstream. Other code means you should modify your commands and call the interface again. `ATTENTION`: You also need a `third-party` to generate the new config and dump it to Nginx'conf directory. ```bash curl -H "host: dyhost" 127.0.0.1:8080 <html> <head><title>502 Bad Gateway</title></head> <body bgcolor="white"> <center><h1>502 Bad Gateway</h1></center> <hr><center>nginx/1.3.13</center> </body> </html> curl -d "server 127.0.0.1:8089;server 127.0.0.1:8088;" 127.0.0.1:8081/upstream/dyhost success curl -H "host: dyhost" 127.0.0.1:8080 8089 curl -H "host: dyhost" 127.0.0.1:8080 8088 curl 127.0.0.1:8081/detail host1 server 127.0.0.1:8088 weight=1 maxconns=0 maxfails=1 fail_timeout=10 backup=0 down=0 host2 server 127.0.0.1:8089 weight=1 maxconns=0 maxfails=1 fail_timeout=10 backup=0 down=0 dyhost server 127.0.0.1:8089 weight=1 maxconns=0 maxfails=1 fail_timeout=10 backup=0 down=0 server 127.0.0.1:8088 weight=1 maxconns=0 maxfails=1 fail_timeout=10 backup=0 down=0 curl -i -X DELETE 127.0.0.1:8081/upstream/dyhost success curl 127.0.0.1:8081/detail host1 server 127.0.0.1:8088 weight=1 maxconns=0 maxfails=1 fail_timeout=10 backup=0 down=0 host2 server 127.0.0.1:8089 weight=1 maxconns=0 maxfails=1 fail_timeout=10 backup=0 down=0 ``` ```c extern ngxflagt ngxhttpdyupsapienable; ngxintt ngxdyupsupdateupstream(ngxstrt *name, ngxbuf_t *buf, ngxstrt *rv); ngxintt ngxdyupsdeleteupstream(ngxstrt *name, ngxstr_t *rv); extern ngxdyupsaddupstreamfilterpt ngxdyupsaddupstreamtopfilter; extern ngxdyupsdelupstreamfilterpt ngxdyupsdelupstreamtopfilter; ``` NOTICE: you should add the directive `dyups_interface` into your config file to active this feature ```lua contentbylua ' local dyups = require "ngx.dyups" local status, rv = dyups.update("test", [[server 127.0.0.1:8088;]]); ngx.print(status, rv) if status ~= ngx.HTTP_OK then ngx.print(status, rv) return end ngx.print("update success") status, rv = dyups.delete("test") if status ~= ngx.HTTP_OK then ngx.print(status, rv) return end ngx.print("delete success") '; ``` : You can use `lua-upstream-nginx-module` to get more detail infomation of upstream. : To make upstream check module work well with dyups module, you should use `./modules/ngxhttpupstreamcheckmodule`.