nginx + consul
安装 consul
unzip consul_1.9.2_linux_amd64.zip
mv consul /usr/local/sbin/consul
consul agent -dev -ui -node=consul-dev -client=x.x.x.x
nginx 添加 upsync 模块
./configure —prefix= …. —add-module=/usr/local/src/nginx-upsync-module-2.1.2
nginx upstream配置段
upstream webs {
server 127.0.0.1:11111;
upsync 20.0.0.197:8500/v1/kv/nginx_197/upstreams/webs upsync_timeout=6m upsync_interval=500ms upsync_type=consul strong_dependency=off;
upsync_dump_path /apps/nginx/conf/upsync/webs.conf;
}
server {
listen 1080;
location / {
proxy_pass http://webs;
}
}
向 consul 添加 kv 值
curl -X PUT http://20.0.0.197:8500/v1/kv/nginx_197/upstreams/webs/20.0.0.212:1081
curl -X PUT curl -X PUT -d ‘{“weight”:10,”max_fails”:2,”fail_timeout”:10}’ http://20.0.0.197:8500/v1/kv/nginx_197/upstreams/webs/20.0.0.212:1082
nginx 生成的配置文件
cat /apps/nginx/conf/upsync/webs.conf
server 20.0.0.212:1082 weight=10 max_fails=2 fail_timeout=10s;
server 20.0.0.212:1081 weight=1 max_fails=2 fail_timeout=10s;
