somepeople

nginx动态增删upstream

server:192.168.159.128

node-1:192.168.159.130

node-2:192.168.159.133

1.安装依赖包

yum install wget git openssl openssl-devel gcc pcre pcre-devel jemalloc jemalloc-devel

2.下载安装包

wget http://tengine.taobao.org/download/tengine-2.3.2.tar.gz
git clone git://github.com/vozlt/nginx-module-vts.git
3.安装
  mkdir /software/servers/nginx/
  tar xf tengine-2.3.2.tar.gz -C /software/servers/
  cd /software/servers/tengine-2.3.2
  编译安装nginx:
  ./configure  --prefix=/software/servers/nginx --add-module=./modules/ngx_http_upstream_dyups_module --with-http_v2_module --with-jemalloc --with-http_ssl_module --with-http_v2_module --with-http_stub_status_module --add-module=./modules/ngx_http_upstream_vnswrr_module --add-module=./modules/nginx-module-vts/
  make && make install
  mkdir /software/servers/nginx/conf/vhost
4.修改配置
  vim /software/servers/nginx/conf/nginx.conf
  
http {
    include       mime.types;
    default_type  application/octet-stream;

    #access_log  "pipe:rollback logs/access_log interval=1d baknum=7 maxsize=2G"  main;

    sendfile        on;

    keepalive_timeout  65;
    vhost_traffic_status_zone;
    include vhost/upstream.conf;加载初始持久配置
    server {
        listen       80;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;
        #access_log  "pipe:rollback logs/host.access_log interval=1d baknum=7 maxsize=2G"  main;

        location / {
         set $web "t1"; 
         proxy_set_header Host $host;
         proxy_pass http://$web;
        }

        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

    }

      server {
        listen 8081;
        location / {
            dyups_interface;
            access_log   logs/dumps.log;
            allow 127.0.0.1;
            deny all;
        }
    }

}

 

  vim /software/servers/nginx/conf/vhost/upstream.conf
  upstream t1{
    server 192.168.159.130:80;
  }
  
动态添加
curl -d "server 192.168.159.130:80;server 192.168.159.133:80;" 127.0.0.1:8081/upstream/t1
 
动态删除
curl -i -X DELETE 127.0.0.1:8081/upstream/t1
 

posted on 2021-02-24 11:07  Hello_Thanos  阅读(439)  评论(0编辑  收藏  举报

导航