consul_nginx_uprsync动态负载均衡
consul_nginx_uprsync动态负载均衡
环境准备: 原理描述: 将Nginx的负载均衡后端服务器配置信息写入consul的接口中,upsync插件通过读取consul的配置,然后持久化到nginx的一个配置文件,nginx通过读取这个配置文件来进行负载均衡 1. 重新编译安装tengine2.2.3将upsync这个插件 关键插件:--add-module=/usr/local/src/nginx-upsync-module-nginx-upsync-1.8.x ./configure --prefix=/usr/local/tengine-2.2.3_upsync --with-ld-opt=-Wl,-rpath, --user=daemon --group=daemon --with-http_ssl_module --with-http_realip_module --with-http_addition_module --with-http_xslt_module --with-http_sub_module --with-http_stub_status_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gzip_static_module --with-http_geoip_module --with-http_secure_link_module --with-http_degradation_module --with-mail_ssl_module --with-http_sysguard_module --with-http_concat_module --with-pcre=/usr/local/lab/pcre-8.34 --with-zlib=/usr/local/lab/zlib-1.2.11 --add-module=/usr/local/lab/ngx_cache_purge-2.3 --with-jemalloc --with-http_upstream_check_module --with-http_lua_module --with-luajit-lib=/usr/local/lib/ --with-luajit-inc=/usr/local/include/luajit-2.0/ --with-lua-inc=/usr/local/include/luajit-2.0/ --with-lua-lib=/usr/local/lib/ --with-openssl=/usr/local/lab/openssl-1.1.0i --add-module=/usr/local/ngx_http_geoip2_module-3.2 --add-module=/usr/local/src/nginx-upsync-module-nginx-upsync-1.8.x 2.启动consul consul agent -dev -ui -node=consul-dev -client=10.11.0.210 Nginx的配置: upstream itmayiedu{ server 127.0.0.1:11111; upsync 10.11.0.210:8500/v1/kv/upstreams/itmayiedu upsync_timeout=6m upsync_interval=500ms upsync_type=consul strong_dependency=off; upsync_dump_path /usr/local/tengine-2.2.3_upsync/conf/vhost.d/itmayiedu; } server { listen 80 default_server; server_name localhost; location / { proxy_pass http://itmayiedu; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; add_header real $upstream_addr; } # 其中一台后端的配置
读取到的持久化配置文件
通过接口控制后端服务器配置
注意是put方式
最终在consul中显示