tengine dyups模块动态更新upstream

2020-02-18  本文已影响0人  飘风云间

目标

测试tengine 动态upstream的功能,为后续动态升级提供服务支持
该功能实时修改内存数据,无需reload

环境

安装步骤

安装基础环境

jemalloc-4.4.0.tar.bz2

 wget https://github.com/jemalloc/jemalloc/releases/download/4.4.0/jemalloc-4.4.0.tar.bz2
yum install bzip2
tar xjf jemalloc-4.4.0.tar.bz2
cd jemalloc-4.4.0
./configure
make && make install
echo '/usr/local/lib' > /etc/ld.so.conf.d/local.conf
ldconfig
yum install gcc openssl-devel gd-devel pcre-devel libxml2-devel libxslt-devel GeoIP-devel perl-devel lua-devel -y

tengine安装

wget http://tengine.taobao.org/download/tengine-2.1.2.tar.gz
tar -zxvf tengine-2.1.2.tar.gz 
cd tengine-2.1.2
./configure --prefix=/root/web/nginx/tengine --enable-mods-static=all --with-http_upstream_check_module --with-http_v2_module --with-http_dyups_module --with-http_dyups_lua_api --with-http_sysguard_module

make && make install

tengine 配置

nginx.conf

user  nobody;
worker_processes  2;
error_log  logs/error.log  debug;
pid        logs/nginx.pid;
events {
    worker_connections  1024;
}
http {
    include       mime.types;
    default_type  application/octet-stream;
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';
    access_log  logs/access.log  main;
    sendfile        on;
    tcp_nopush     on;
    keepalive_timeout  65;
    gzip  on;
    dyups_upstream_conf  vhost/upstream.conf;
    include vhost/upstream.conf;
    server {
        listen   80;
        location / {
            proxy_pass http://java;
        }
    }
    server {
        listen 8081;
        location / {
            dyups_interface;
        }
    }
}

在nginx.conf同级目录下创建vhost/upstream.conf文件

upstream java1 {
    server 127.0.0.1:7079;
}

upstream java2 {
    server 127.0.0.1:7080;
}

upstream java {
    server 127.0.0.1:7079;
    server 127.0.0.1:7080;
}

启动nginx

./sbin/nginx

配置文件修改后重载

./sbin/nginx -s reload

upstream测试

查看upstream list

curl 127.0.0.1:8081/list

res

java2
java
java1

查看upstream 明细

curl 127.0.0.1:8081/detail

res

java2
server 127.0.0.1:7080

java
server 127.0.0.1:7079
server 127.0.0.1:7080

java1
server 127.0.0.1:8088

修改指定upstream

curl -d "server 127.0.0.1:7079;" 127.0.0.1:8081/upstream/java1

res

success

查看修改后的效果

curl 127.0.0.1:8081/upstream/java1

res

server 127.0.0.1:7079
上一篇下一篇

猜你喜欢

热点阅读