consul + upsync + nginx 동적 부하 균형 실현

consul + upsync + nginx 동적 부하 균형 실현
원리:
 upstream   Nginx    ,      upstream  nginx    。

  :1、         

        2、  nginx  reload

        3、    ,         。 Apollo    ,     upsync  

nginx 지원 upsync 설치:
테스트: nginx version: nginx / 1.12.2 가능
--add-module=/tmp/nginx-upsync-module
cd /tmp/
git clone https://github.com/weibocom/nginx-upsync-module.git

./configure --prefix=/data1/nginx/release/{{dir_date}} --conf-path=/data1/nginx/release/{{dir_date}}/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --user=nginx --group=nginx --with-http_ssl_module --with-http_v2_module --with-http_dav_module --with-http_stub_status_module --with-threads --with-file-aio --with-stream --with-stream_ssl_module --add-module=/tmp/nginx-upsync-module

설치 설정 consul
mkdir /data1/consul
cd /data1/consul
wget https://releases.hashicorp.com/consul/1.7.3/consul_1.7.3_linux_amd64.zip
unzip consul_1.7.3_linux_amd64.zip

##   consul  ##    
consul agent --server --bind=172.16.2.128 --data-dir=/tmp/consule -bootstrap-expect=1 -node=nginx-lb -client 0.0.0.0 -ui

upstream 정보 추가
##     upstream  
curl -X PUT http://172.16.2.128:8500/v1/kv/upstreams/test/172.16.2.129:8086

nginx 프로필 설정
upstream test_server {  
    server 127.0.0.1:11111;
    upsync 172.16.2.128:8500/v1/kv/upstreams/test upsync_timeout=6m upsync_interval=500ms upsync_type=consul strong_dependency=off;
    upsync_dump_path /data1/nginx/current/consul/test.ppdapi.com.conf;
}

server {
    listen 80;
    server_name   test.ppdai.com;

    index default.htm index.html index.htm default.html;
    gzip on;

    location / {
        proxy_pass       http://test_server;
    }

}

consul 의 일상 관리
upsync 모듈 학습:https://github.com/weibocom/nginx-upsync-module#upsync_timeout
    :
curl -X PUT http://172.16.2.128:8500/v1/kv/upstreams/test/172.16.2.129:8086
    :
curl -X DELETE http://172.16.2.128:8500/v1/kv/upstreams/test/172.16.2.129:8086
    :
http://172.16.2.128:8500/v1/kv/upstreams/test/172.16.2.129:8081
json:{"weight":1, "max_fails":2, "fail_timeout":10}
curl -X PUT -d '{"weight":1, "max_fails":2, "fail_timeout":10}' http://$consul_ip:$port/v1/kv/$dir1/$upstream_name/$backend_ip:$backend_port

경매 대출 consul 설정 정보 참조
##xxx.ppdapi.com###

upstream xxx_server {  
    server 127.0.0.1:11111;
    upsync 10.0.24.251:8500/v1/kv/upstreams/xxx upsync_timeout=6m upsync_interval=500ms upsync_type=consul strong_dependency=off;
    upsync_dump_path /data/nginx/conf/xxx.ppdapi.com.conf;

    check interval=3000 rise=2 fall=5 timeout=1000 type=http;
    check_http_send "HEAD http://xxx.ppdapi.com/hs HTTP/1.0\r
\r
"; check_http_expect_alive http_2xx http_3xx ; } server { listen 80; server_name xxx.ppdapi.com; server_tokens off; proxy_hide_header X-Powered-By; proxy_hide_header X-AspNet-Version; index default.htm index.html index.htm default.html; gzip on; location / { proxy_pass http://xxx_server; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } }

좋은 웹페이지 즐겨찾기