您的位置:首页 > 运维架构 > Nginx

006_nginx动态upstream和安全检查模块

2017-08-16 18:58 260 查看
一、参考Tengine http://tengine.taobao.org/document_cn/http_dyups_cn.html

ngx_http_dyups_module

Description

This module can be used to update your upstream-list without reloadding Nginx.

TODO:

It can not work with common `nginx_upstream_check_module`.

Compilation

The module is not compiled into Tengine by default. It can be enabled with '--with-http_dyups_module'
configuration parameter, and enabled lua support with '--with-http_dyups_lua_api'.
But it can not be compiled as a '.so'.

二、配置

在http块中引用如下的配置=>
http {
dyups_upstream_conf upstream/ngconf_dyups.conf;
include upstream/ngconf_dyups.conf;      #假如已经include进来的话就不需要include了;eg: include upstream/*.conf;
}

cat upstream/ngconf_dyups.conf

server {
listen 8866;
location / {
dyups_interface;      #you should add the directive dyups_interface into your config file to active this feature
}
}


三、restful interface常用操作。
<1>curl -H "host: dyhost" 127.0.0.1:8866/detail #获取所有的upstream和他们的后端server

xxx-svr-backend
server 10.103.101.169:8080
server 10.103.104.207:8080

xxx-admin-backend
server 10.103.105.81:9001
server 10.103.105.80:9001

xxx-admin.alta.jyall.me.alta1-hg-xxx-admin
server 10.103.105.81:9001
server 10.103.105.80:9001

xxx.alta.jyall.me.alta1-hg-xxx-proxy
server 10.103.101.169:8080
server 10.103.104.207:8080


<2>curl -H "host: dyhost" 127.0.0.1:8866/list #获取upstream的名称列表

xxx-svr-backend
xxx-admin-backend
xxx-admin.alta.jyall.me.alta1-hg-xxx-admin
xxx.alta.jyall.me.alta1-hg-xxx-proxy


<3>curl -H "host: dyhost" 127.0.0.1:8866/upstream/xxx-svr-backend #根据upstream的名字找出它后端的server列表

server 10.103.101.169:8080
server 10.103.104.207:8080


<4>添加或更新一个upstream

curl -d "server 127.0.0.1:8089;server 127.0.0.1:8088;" 127.0.0.1:8866/upstream/arun_test

curl -d "server 127.0.0.1:9000;server 127.0.0.1:8088;" 127.0.0.1:8866/upstream/arun_test

curl -H "host: dyhost" 127.0.0.1:8866/upstream/arun_test

server 127.0.0.1:9000
server 127.0.0.1:8088

<5>curl 127.0.0.1:8866/detail

arun_test
server 127.0.0.1:9000
server 127.0.0.1:8088


<6>curl -i -X DELETE 127.0.0.1:8866/upstream/arun_test #动态删除upstream

HTTP/1.1 200 OK
Date: Wed, 16 Aug 2017 12:05:58 GMT
Content-Length: 7
Connection: keep-alive

success


curl 127.0.0.1:8866/detail再次查看"arun_test"的upstream已经被删除了。

-------------------------------------------------------------------------ngx_http_upstream_check_module--------------------------------------------------------------------------------

四、upstream检查模块。

p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; line-height: 19.0px; font: 13.0px "Helvetica Neue" }
http://tengine.taobao.org/document_cn/http_upstream_check_cn.html
p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; line-height: 19.0px; font: 13.0px "Helvetica Neue" }
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: