nginx-upsync-module模块安装

这篇教程介绍了如何在持续集成环境中,利用nginx-upsync-module进行自动化部署和弹性伸缩。首先,需要下载匹配的nginx及consul安装包,然后安装依赖并启动nginx和consul。在测试模式下,可以以dev模式启动。最后,文章提到了nginx的配置文件及其相关操作命令。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

**

持续集成、自动化部署、弹性伸缩教程 http://edu.youkuaiyun.com/course/detail/6452

**

1:下载对应安装包

nginx-upsync-module对nginx的版本有相关要求
我们这里采用的是1.8x的版本
这里写图片描述

wget http://nginx.org/download/nginx-1.8.0.tar.gz
wget https://releases.hashicorp.com/consul/0.9.2/consul_0.9.2_linux_amd64.zip

下载完成后解压如下:
这里写图片描述

2:安装对应安装包

安装nginx依赖包,编译安装nginx并且启动

yum install zlib pcre pcre-devel openssl openssl-devel    zlib-devel git
cd nginx-1.8.0

./configure   --prefix=/usr/local/nginx     --with-pcre  --with-http_stub_status_module --with-http_ssl_module --with-http_gzip_static_module --with-http_realip_module --with-http_sub_module  --add-module=/root/nginx-upsync-module-nginx-upsync-1.8.x

make && make install 
/usr/local/nginx/sbin/nginx

安装consul并启动
由于我们采用的是测试模式,所以dev模式启动就行了

cd consul/
cp consul   /usr/local/bin
nohup   consul agent -advertise=192.168.150.10   -client=0.0.0.0 -dev  &

nginx配置文件如下:

user  root;
worker_processes  2;
error_log  logs/error.log warn;

events {
    worker_connections  4096;
    multi_accept on;
    use epoll;
}   


http {
    default_type  application/octet-stream;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '

    access_log  logs/access.log  main;
    sendfile        on;
    tcp_nodelay     on;
    keepalive_timeout 10;
    client_body_timeout 10; 
    reset_timedout_connection on;
    send_timeout 10;

  charset UTF-8;
  gzip on;
  gzip_disable "msie6";
  gzip_proxied any;
  gzip_min_length 1000;
  gzip_comp_level 6;
  gzip_types ext/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;
  open_file_cache max=100000 inactive=20s;
  open_file_cache_valid 30s; 
  open_file_cache_min_uses 2;
  open_file_cache_errors on;
  proxy_buffer_size 16k; 
  proxy_buffers 4 64k;
  proxy_busy_buffers_size 128k;
  proxy_temp_file_write_size 128k;
  include /usr/local/nginx/conf/conf.d/*;
  fastcgi_intercept_errors on;



upstream hellowh.war {
        server 127.0.0.1:11111;
        upsync 192.168.150.10:8500/v1/kv/upstreams/hellowh.war/  upsync_timeout=6m upsync_interval=500ms upsync_type=consul strong_dependency=off;
        upsync_dump_path /usr/local/nginx/conf/servers/hellowh.war.conf;
        }

server {
        listen       80 ;
        server_name  test01.th.com;
        charset utf8;
        location /HelloWH {
                proxy_set_header Host $host;
                proxy_set_header X-Real-IP $remote_addr;
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                proxy_pass http://hellowh.war/HelloWH;

       }        

        access_log /usr/local/nginx/logs/access-upsync.log;
        location /stub-status {
                stub_status on;
        }       
        location = /upstream_show {
            upstream_show;
        }   

  }     


}

操作命令:

添加一个后端服务器
# default: weight=1 max_fails=2 fail_timeout=10 down=0 backup=0;

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

示例:
curl -X PUT -d '{"weight":1, "max_fails":2, "fail_timeout":10}' http://192.168.150.10:8500/v1/kv/upstreams/hellowh.war/192.168.140.195:8082
删除一个后端服务器
curl -X DELETE http://$consul_ip:$port/v1/kv/upstreams/$upstream_name/$backend_ip:$backend_port
示例:
curl -X DELETE  http://192.168.150.10:8500/v1/kv/upstreams/hellowh.war/192.168.140.195:8082
修改权重
#default: weight=1 max_fails=2 fail_timeout=10 down=0 backup=0;

curl -X PUT -d '{"weight":2, "max_fails":2, "fail_timeout":10}' http://$consul_ip:$port/v1/kv/$dir1/$upstream_name/$backend_ip:$backend_port

示例:
curl -X PUT -d '{"weight":10, "max_fails":20, "fail_timeout":11}' http://192.168.150.10:8500/v1/kv/upstreams/hellowh.war/192.168.140.195:8082

停止后端提供服务,使后端服务停止提供服务,但是没被删除
curl -X PUT -d '{"weight":2, "max_fails":2, "fail_timeout":10, "down":1}' http://$consul_ip:$port/v1/kv/$dir1/$upstream_name/$backend_ip:$backend_port

示例
curl -X PUT -d '{"weight":10, "max_fails":20, "fail_timeout":11,"down":1 }' http://192.168.150.10:8500/v1/kv/upstreams/hellowh.war/192.168.140.195:8082
consul   CHECK操作:
curl http://$consul_ip:$port/v1/kv/upstreams/$upstream_name?recurse
curl  http://192.168.150.10:8500/v1/kv/upstreams/hellowh.war/192.168.140.195:8082
示例
查看upstream信息,nginx配置文件里面定义的路径查看既可以

这里写图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值