1、安装 openresty 依赖模块:

[root@Centos opt]# yum -y install pcre-devel openssl openssl-devel postgresql-devel

2、编译安装 openresty:

[root@Centos opt]# tar -zxvf openresty-1.15.8.2.tar.gz
...(略去内容)...
[root@Centos opt]# cd openresty-1.15.8.2/
[root@Centos openresty-1.15.8.2]# ll
总用量
drwxrwxr-x. hacker 11月 : build
drwxrwxr-x. hacker 8月 : bundle
-rwxrwxr-x. hacker 8月 : configure
-rw-rw-r--. hacker 8月 : COPYRIGHT
-rw-r--r--. root root 11月 : Makefile
drwxrwxr-x. hacker 8月 : patches
-rw-rw-r--. hacker 8月 : README.markdown
-rw-rw-r--. hacker 8月 : README-windows.txt
drwxrwxr-x. hacker 8月 : util
[root@Centos openresty-1.15.8.2]# ./configure --prefix=/usr/local/openresty --with-luajit --without-http_redis2_module --with-http_iconv_module --with-http_postgres_module
...(略去内容)...
[root@Centos openresty-1.15.8.2]# gmake && gmake install
...(略去内容)...

3、编辑 nginx.conf 文件,编辑后内容为:

http {
include mime.types;
default_type application/octet-stream; sendfile on;
keepalive_timeout ; lua_shared_dict ups_zone 1m; # 定义upstream共享内存空间 upstream web-cluster {
server 127.0.0.1:;
server 127.0.0.1:;
} upstream web- {
server 127.0.0.1:;
} upstream web- {
server 127.0.0.1:;
} server {
listen ;
server_name localhost;
#charset koi8-r; #access_log logs/host.access.log main; location /forward {
default_type text/html;
content_by_lua_block {
local host = ngx.req.get_uri_args()["host"]
local key = "switchKey"
ngx.shared.ups_zone:set(key, host)
local forward_ip = ngx.shared.ups_zone:get(key)
ngx.say("Successfully, forwarded host is: ", forward_ip)
}
} location ~ /web/(.*) {
set_by_lua_block $my_ups {
local key = ngx.shared.ups_zone:get("switchKey")
if key == nil or key == "default" then
return "web-cluster"
else
local port = string.sub(key, -)
if port == "" then
return "web-8087"
elseif port == "" then
return "web-8088"
end
end } proxy_pass http://$my_ups/$1; } }
}

4、测试是否生效:

(1)默认负载均衡模式:

[root@Centos conf]# curl http://127.0.0.1/forward?host=default
Successfully, forwarded host is: default
[root@Centos conf]# curl http://127.0.0.1/web/lua
server
[root@Centos conf]# curl http://127.0.0.1/web/lua
server
[root@Centos conf]# curl http://127.0.0.1/web/lua
server
[root@Centos conf]# curl http://127.0.0.1/web/lua
server
[root@Centos conf]# curl http://127.0.0.1/web/lua
server
[root@Centos conf]# curl http://127.0.0.1/web/lua
server
[root@Centos conf]# curl http://127.0.0.1/web/lua
server
[root@Centos conf]# curl http://127.0.0.1/web/lua
server
[root@Centos conf]#

(2)将所有请求转移到 8087 server:

[root@Centos conf]# curl http://127.0.0.1/forward?host=127.0.0.1:8087
Successfully, forwarded host is: 127.0.0.1:
[root@Centos conf]# curl http://127.0.0.1/web/lua
server
[root@Centos conf]# curl http://127.0.0.1/web/lua
server
[root@Centos conf]# curl http://127.0.0.1/web/lua
server
[root@Centos conf]# curl http://127.0.0.1/web/lua
server
[root@Centos conf]# curl http://127.0.0.1/web/lua
server
[root@Centos conf]# curl http://127.0.0.1/web/lua
server
[root@Centos conf]# curl http://127.0.0.1/web/lua
server
[root@Centos conf]#

(3)将所有请求转移到 8088 server:

[root@Centos conf]# curl http://127.0.0.1/forward?host=127.0.0.1:8088
Successfully, forwarded host is: 127.0.0.1:
[root@Centos conf]# curl http://127.0.0.1/web/lua
server
[root@Centos conf]# curl http://127.0.0.1/web/lua
server
[root@Centos conf]# curl http://127.0.0.1/web/lua
server
[root@Centos conf]# curl http://127.0.0.1/web/lua
server
[root@Centos conf]# curl http://127.0.0.1/web/lua
server
[root@Centos conf]# curl http://127.0.0.1/web/lua
server
[root@Centos conf]# curl http://127.0.0.1/web/lua
server
[root@Centos conf]#

参考书籍:《OpenResty最佳实践》PDF版,《OpenResty完全开发指南》

OpenResty 实现项目的灰度发布的更多相关文章

  1. Openresty+Lua+Redis灰度发布

    灰度发布,简单来说,就是根据各种条件,让一部分用户使用旧版本,另一部分用户使用新版本.百度百科中解释:灰度发布是指在黑与白之间,能够平滑过渡的一种发布方式.AB test就是一种灰度发布方式,让一部分 ...

  2. 01 . OpenResty简介部署,优缺点,压测,适用场景及用Lua实现服务灰度发布

    简介 OpenResty 是一个基于 Nginx 与 Lua 的高性能 Web 平台,其内部集成了大量精良的 Lua 库.第三方模块以及大多数的依赖项.用于方便地搭建能够处理超高并发.扩展性极高的动态 ...

  3. Nginx配之负载均衡、缓存、黑名单和灰度发布

    一.Nginx安装(基于CentOS 6.5) 1.yum命令安装 yum install nginx –y(若不能安装,执行命令yum install epel-release) 2. 启动.停止和 ...

  4. Nginx配置之负载均衡、限流、缓存、黑名单和灰度发布

    一.Nginx安装(基于CentOS 6.5) 1.yum命令安装 yum install nginx –y(若不能安装,执行命令yum install epel-release) 2. 启动.停止和 ...

  5. nginx+lua实现灰度发布/waf防火墙

    nginx+lua 实现灰度发布 waf防火墙 课程链接:[课程]Nginx 与 Lua 实现灰度发布与 WAF 防火墙(完)_哔哩哔哩 (゜-゜)つロ 干杯~-bilibili 参考博客 Nginx ...

  6. Jenkins 学习笔记(三):我们的JAVA 项目是这么发布的

    发布拓扑 1. 拓扑图 2. 流程说明: Git 插件从 Git Server 上面拉取源代码. Maven 插件将源代码安装我们设定的指令进行编译打包,存放于项目的 WorkSpace. Publi ...

  7. 使用Nginx实现灰度发布

    灰度发布是指在黑与白之间,能够平滑过渡的一种发布方式.AB test就是一种灰度发布方式,让一部分用户继续用A,一部分用户开始用B,如果用户对B没有什么反对意见,那么逐步扩大范围,把所有用户都迁移到B ...

  8. springcloud灰度发布实现方案

    Nepxion Discovery是一款对Spring Cloud Discovery服务注册发现.Ribbon负载均衡.Feign和RestTemplate调用.Hystrix或者阿里巴巴Senti ...

  9. 使用Nginx实现灰度发布(转)

    灰度发布是指在黑与白之间,能够平滑过渡的一种发布方式.AB test就是一种灰度发布方式,让一部分用户继续用A,一部分用户开始用B,如果用户对B没有什么反对意见,那么逐步扩大范围,把所有用户都迁移到B ...

随机推荐

  1. 测试Nginx中location的优先级!(重点)

    location [=|~|~*|^~] /uri/ { … } = 开头表示精确匹配 ~ 开头表示区分大小写的正则匹配 ~* 开头表示不区分大小写的正则匹配 ^~ 开头表示uri以某个常规字符串开头 ...

  2. Centos6.X安装桌面

    1.前置环境yum -y groupinstall 'X Window System'2.桌面安装 yum -y groupinstall 'Desktop' 3.语言包yum -y groupins ...

  3. Spark操作MySQL,Hive并写入MySQL数据库

    最近一个项目,需要操作近70亿数据进行统计分析.如果存入MySQL,很难读取如此大的数据,即使使用搜索引擎,也是非常慢.经过调研决定借助我们公司大数据平台结合Spark技术完成这么大数据量的统计分析. ...

  4. [读书]The Man Who Solved the Market

    出乎个人意料的是,西蒙斯是从FICC类品种起步的,包括量化投资方法获得第一次重大突破也是在FICC品种上. FICC市场的深度不够,所以文艺复兴科技实现规模扩张是股票策略成功之后的事情,很靠后. 虽然 ...

  5. Python 爬取 热词并进行分类数据分析-[云图制作+数据导入]

    日期:2020.01.28 博客期:136 星期二 [本博客的代码如若要使用,请在下方评论区留言,之后再用(就是跟我说一声)] 所有相关跳转: a.[简单准备] b.[云图制作+数据导入](本期博客) ...

  6. python nohup linux 后台运行输出

    遇到问题 nohup python flush.py & 这样运行,生成了nohup.out文件,但是内容始终是空的,试了半天也不行.浪费了不少时间.原因 python的输出又缓冲,导致out ...

  7. 「学习笔记」FFT 之优化——NTT

    目录 「学习笔记」FFT 之优化--NTT 前言 引入 快速数论变换--NTT 一些引申问题及解决方法 三模数 NTT 拆系数 FFT (MTT) 「学习笔记」FFT 之优化--NTT 前言 \(NT ...

  8. c# 分页 PaginatedList<TResult>

    using System; using System.Collections.Generic; using System.Linq; namespace Microestc.PaginatedList ...

  9. [转]JSP自定义标签

    原文链接 当jsp的内置标签和jstl标签库内的标签都满足不了需求,这时候就需要开发者自定义标签. 自定义标签 下面我们先来开发一个自定义标签,然后再说它的原理吧! 自定义标签的开发步骤 步骤一 编写 ...

  10. 从零构建以太坊(Ethereum)智能合约到项目实战——第23章 从零构建和部署去中心化投票App,decentralization Voting Dapp

    P90 .1-从零构建和部署去中心化投票App-01 P91 .2-从零构建和部署去中心化投票App-02 P92 .3-从零构建和部署去中心化投票App-03 参考博文:http://liyuech ...