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. Linux kali安装或更新之后出现乱码

    打开终端,输入以下命令,之后重启. apt-get install ttf-wqy-zenhei

  2. 洛谷P1009 阶乘之和 题解

    想看原题请点击这里:传送门 看一下原题: 题目描述 用高精度计算出S=!+!+!+…+n! (n≤) 其中“!”表示阶乘,例如:!=****××××. 输入格式 一个正整数N. 输出格式 一个正整数S ...

  3. JavaScript - 编译性还是解释性?

    疑问 在JS的变量和声明式函数的提升看到了"预编译/预处理/预解释"中"预编译"这个字眼,产生了一个疑问:JS是熟知的解释性语言,但JS能被编译吗? 参考 ht ...

  4. 在iOS项目中,这样才能完美的修改项目名称

    https://www.cnblogs.com/liangyi-cn/p/8657474.html 前言: 在iOS开发中,有时候想改一下项目的名字,这会遇到很多麻烦. 直接改项目名的话,Xcode不 ...

  5. Atom 必装插件

    Atom 必装插件 转载请注明出处. https://blog.csdn.net/Nick_php/article/details/54020956 主题 atom-material-ui 字体配色 ...

  6. Python数据类型-4 列表

    列表 列表是Python中最基本也是最常用的数据结构之一.列表中的每个元素都被分配一个数字作为索引,用来表示该元素在列表内所排在的位置.第一个元素的索引是0,第二个索引是1,依此类推. Python的 ...

  7. centos6.9下 svn 1.7.10版本 编译安装

    svn安装推荐文章: 1.    http://blog.51cto.com/myhat/786950 2.    https://blog.csdn.net/test1280/article/det ...

  8. WCF服务调用方式

    WCF服务调用通过两种常用的方式:一种是借助代码生成工具SvcUtil.exe或者添加服务引用的方式,一种是通过ChannelFactory直接创建服务代理对象进行服务调用.

  9. Springboot + redis + 注解 + 拦截器来实现接口幂等性校验

    Springboot + redis + 注解 + 拦截器来实现接口幂等性校验   1. SpringBoot 整合篇 2. 手写一套迷你版HTTP服务器 3. 记住:永远不要在MySQL中使用UTF ...

  10. CSS - 去除图片img底侧空白缝隙

    1. 图片底部有空隙 <!DOCTYPE html> <html lang="en"> <head> <meta charset=&quo ...