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. 2018 最新注册码【激活码】、在线激活 pycharm 完整方法(亲测有效)【2018.06.01 重大更新!!!!】

    2018-06-01修改如下: 原来方法的第二种还是有效的,操作如下 (1)更新hosts文件(可以直接下载,然后解压缩) host文件地址 hosts文件,在windows中的地址为: 替换host ...

  2. 几个原生js知识

    1.document.documentElement 返回根节点 html. 2.原生方法获取一个对象的某个样式的值. function getStyle(obj, attr) { if(obj.cu ...

  3. 安装插件报错error: Microsoft Visual C++ 14.0 is required. Get it with "Microsoft Visual C++

    起因:学到多线程greenlet模块时,greenlet模块死活装不上,以为pycharm坏掉了,浪费了一下午. #pip3 install greenlet from greenlet import ...

  4. Mysql基本用法-存储引擎-03

    看到存储引擎这个地方感到很多细节比较陌生,所以总结小记一些 为了适应各种不同的运行环境,MYSQL提供了多种不同的存储引擎(Storage Engine ),在应用程序开发这个层面上,开发者可以根据不 ...

  5. Linux进程内消息总线设计

    文章目录 Windows平台进程内消息总线 如果没有消息总线,会产生什么问题 死循环包含关系 高耦合.低内聚 消息总线 结构图 原理 生产者与总线的关系 总线与消费者的关系 Linux进程内消息总线设 ...

  6. Oracle忘记密码怎么办?

    1.打开cmd,输入sqlplus /nolog,回车:输入“conn / as sysdba”;输入“alter user sys identified by 新密码”,注意:新密码最好以字母开头, ...

  7. crm系统和e_store商场的比较总结

    e_store用了:Java.Servlet.JSP.Oracle.JQuery.Mybatis,tomcat技术 crm用了 :Java.JSP.Oracle.JQuery,Mybatis,spri ...

  8. 吴裕雄--天生自然PythonDjangoWeb企业开发:Django文档阅读简介

    Django是基于MVC模式的框架,虽然也被称为“MTV”的模式,但是大同小异.对我们来说,需要了解的是无论是MVC模式还是MTV模式,甚至是其他的什么模式,都是为了解耦.把一个软件系统划分为一层一层 ...

  9. B: 最小代价

    B: 最小代价 题解:先用最小生成树求联通所有点的最小代价ans 在求度为1的时候权值最大的点mx ans-mx就是答案 #include<iostream> #include<al ...

  10. vs2013 SQLite数据库增删改查

    代码:Database2.7z Database.h: #pragma once #include<string> #include<vector> #include<W ...