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 ...
随机推荐
- 安装PHP解析环境!
较新版本(如5.6)的PHP已经自带FPM(fastCGI process manager,FastCGI进程管理器)模块,用来对PHP解析实例进行管理,优化解析效率,因此在配置PHP编译选项时应添加 ...
- CentOS7虚拟机优化
CentOS7: 将网卡配置重点关注的地方为: [root@master ~]# cat /etc/sysconfig/network-scripts/ifcfg-ens33 BOOTPROTO=st ...
- Mybatis的逆向工程以及Example的实例函数及详解
Mybatis-generator是Mybatis的逆向工程 (根据数据库中的表生成java代码) Mybatis的逆向工程会生成实例及实例对应的example,example用于添加条件,相当于w ...
- npm安装包时报错:Error: EPERM: operation not permitted, rename
解决方法:先执行 npm cache clean -force在安装需要的包.
- java记录3--抽象
1.由来 利用抽象类是i为了更好的对类加以分类,例如各种植物有具体名字,也有“植物”这个抽象的词对所有具体植物进行归类. 2.抽象类通常用来作为一个类族的最顶层的父类(表示该类族所有事物的共性), 用 ...
- 【PAT甲级】1022 Digital Library (30 分)(模拟)
题意: 输入一个正整数N(<=10000),接下来输入N组数据,ID,书名,作者,关键词,出版社,出版年份. 然后输入一个正整数M(<=1000),接下来输入查询的数据,递增输出ID,若没 ...
- AWS-DDNS
1. DDNS 2. 在 Linux 实例上设置动态 DNS 2.1 Ubuntu 2.2 Amazon Linux 2 2.3 Arch Linux 2.4 其他Linux系统 3. 更多相关 1. ...
- Linux centosVMware zabbix主动模式和被动模式、添加监控主机、添加自定义模板、处理图形中的乱码、自动发现
一.主动模式和被动模式 主动或者被动是相对客户端来讲的 被动模式,服务端会主动连接客户端获取监控项目数据,客户端被动地接受连接,并把监控信息传递给服务端 主动模式,客户端会主动把监控数据汇报给服务端, ...
- 使用package.json安装模块
node.js模块的安装可以使用npm安装,如下: $ npm install <Module Name> 每个项目的根目录下面,一般都需要一个package.json文件,定义了这个项目 ...
- rhel7 系统服务——unit(单元)
Linux内核版本从3.10后开始使用systemd管理服务,这也是系统开机后的第一个服务.systemd通过unit单元文件来管理服务. 它保存了服务.设备.挂载点和操作系统其他信息的配置文件,并能 ...