consul_nginx_uprsync动态负载均衡

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中显示

posted @ 2019-05-23 10:52 reblue520 阅读( ...) 评论( ...) 编辑 收藏
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值