OpenResty 实现项目的灰度发布
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 实现项目的灰度发布的更多相关文章
- Openresty+Lua+Redis灰度发布
灰度发布,简单来说,就是根据各种条件,让一部分用户使用旧版本,另一部分用户使用新版本.百度百科中解释:灰度发布是指在黑与白之间,能够平滑过渡的一种发布方式.AB test就是一种灰度发布方式,让一部分 ...
- 01 . OpenResty简介部署,优缺点,压测,适用场景及用Lua实现服务灰度发布
简介 OpenResty 是一个基于 Nginx 与 Lua 的高性能 Web 平台,其内部集成了大量精良的 Lua 库.第三方模块以及大多数的依赖项.用于方便地搭建能够处理超高并发.扩展性极高的动态 ...
- Nginx配之负载均衡、缓存、黑名单和灰度发布
一.Nginx安装(基于CentOS 6.5) 1.yum命令安装 yum install nginx –y(若不能安装,执行命令yum install epel-release) 2. 启动.停止和 ...
- Nginx配置之负载均衡、限流、缓存、黑名单和灰度发布
一.Nginx安装(基于CentOS 6.5) 1.yum命令安装 yum install nginx –y(若不能安装,执行命令yum install epel-release) 2. 启动.停止和 ...
- nginx+lua实现灰度发布/waf防火墙
nginx+lua 实现灰度发布 waf防火墙 课程链接:[课程]Nginx 与 Lua 实现灰度发布与 WAF 防火墙(完)_哔哩哔哩 (゜-゜)つロ 干杯~-bilibili 参考博客 Nginx ...
- Jenkins 学习笔记(三):我们的JAVA 项目是这么发布的
发布拓扑 1. 拓扑图 2. 流程说明: Git 插件从 Git Server 上面拉取源代码. Maven 插件将源代码安装我们设定的指令进行编译打包,存放于项目的 WorkSpace. Publi ...
- 使用Nginx实现灰度发布
灰度发布是指在黑与白之间,能够平滑过渡的一种发布方式.AB test就是一种灰度发布方式,让一部分用户继续用A,一部分用户开始用B,如果用户对B没有什么反对意见,那么逐步扩大范围,把所有用户都迁移到B ...
- springcloud灰度发布实现方案
Nepxion Discovery是一款对Spring Cloud Discovery服务注册发现.Ribbon负载均衡.Feign和RestTemplate调用.Hystrix或者阿里巴巴Senti ...
- 使用Nginx实现灰度发布(转)
灰度发布是指在黑与白之间,能够平滑过渡的一种发布方式.AB test就是一种灰度发布方式,让一部分用户继续用A,一部分用户开始用B,如果用户对B没有什么反对意见,那么逐步扩大范围,把所有用户都迁移到B ...
随机推荐
- 高级T-SQL进阶系列 (一)【下篇】:使用 CROSS JOIN 介绍高级T-SQL
[译注:此文为翻译,由于本人水平所限,疏漏在所难免,欢迎探讨指正] 原文链接:传送门. 性能考虑产生了笛卡尔积的这个CROSS JOIN操作符具有一些性能方面的问题需要考虑.因为SQL引擎需要将一个数 ...
- 树莓派4B踩坑指南 - (8)安装GO语言
下载 191129最新版本为go1.13.4.linux-armv6l.tar.gz go官网(点此访问)国内访问似乎不是很稳定,但下载速度还挺快,下载地址:(点此访问) 安装 解压后是一个名为go的 ...
- C — 小知识
老是记错int与void*之间的转换,所以记录一个,顺便用一下一些宏.预处理... int与void*的转换.打印变量名: #include <stdio.h> // 打印变量名 #def ...
- #P4770 [NOI2018]你的名字 的题解
题目背景 实力强大的小A 被选为了ION2018 的出题人,现在他需要解决题目的命名问题. 题目描述 小A 被选为了ION2018 的出题人,他精心准备了一道质量十分高的题目,且已经把除了题目命名以外 ...
- 06-常见的RAID技术
目录 06-常见的RAID技术 参考 RAID基本概念 RAID数据组织形式 RAID数据保护方式 RAID0 RAID1 RAID5 RAID6 混合RAID - RAID 10 06-常见的RAI ...
- linux服务器自动备份与删除postgres数据库数据
1.先创一个back.sh 文件,授权,然后在下面这个文件添加脚本 export PGPASSWORD='123456' #这是登录服务器密码cur_time=`date +%Y%m%d ...
- Just a Hook-HDU1698 区间染色+区间查询
题意: hook有一根长度为n的棒,可以将它看成有n段,一开始每段都是铜,hook可以选择一段区间改变棒的属性, 棒有三种属性:铜=1,银=2,金=3,最后输出棒每段的属性总和. 链接:http:// ...
- 洛谷P1198 [JSOI2008]最大数(线段树)
题目描述 现在请求你维护一个数列,要求提供以下两种操作: 1. 查询操作. 语法:Q L 功能:查询当前数列中末尾L个数中的最大的数,并输出这个数的值. 限制:LLL不超过当前数列的长度.(L> ...
- web-pc项目中index页面分析
先上HTML代码: <%@ page language="java" contentType="text/html; charset=UTF-8" pag ...
- android下创建文件夹和修改其权限的方法
原文:http://www.cnblogs.com/wanqieddy/archive/2011/12/28/2304906.html 由于工作的需要,今天研究了在android下创建文件夹和修改其权 ...