如何使用nginx模拟进行蓝绿部署


这篇“如何使用nginx模拟进行蓝绿部署”文章的知识点大部分人都不太理解,所以小编给大家总结了以下内容,内容详细,步骤清晰,具有一定的借鉴价值,希望大家阅读完这篇文章能有所收获,下面我们一起来看看这篇“如何使用nginx模拟进行蓝绿部署”文章吧。蓝绿部署蓝绿部署的重点在于如下特点1. 蓝色版本和绿色版本同时存在2. 实际运行的环境为蓝或则绿,只能为其中之一,通过开关控制优点和缺点分析:优点在于它的速度和回滚。而缺点也显而易见。可以快速回滚是因为有两套环境同时存在的缘故,所以复杂度和需要的资源会增多,因为其有两套环境。
另外虽然速度有所提高,但是在实现的过程中,开关的控制,无论多快的切换速度,如果不结合其他的技术,还是无法做到完全无缝切换。模拟蓝绿部署接下来我们使用nginx的upstream来简单模拟一下蓝绿部署的场景。具体场景如下, 当前活跃的是蓝色版本,通过调整nginx设定,将绿色版本设定为当前活跃版本。事前准备事前在7001/7002两个端口分别启动两个服务,用于显示不同信息,为了演示方便,使用tornado做了一个镜像,通过docker容器启动时传递的参数不同用 香港云主机于显示服务的不同。执行日志启动nginxnginx代码段准备如下nginx代码段将其添加到nginx的/etc/nginx/conf.d/default.conf中, 模拟方式很简单,通过down来表示流量为零(nginx中无法将weight设置为零),开始的时候100%的流量都发到蓝色版本。修改default.conf的方法可以通过在容器中安装vim达到效果,也可以在本地修改然后通过docker cp传入,或者直接sed修改都可。如果在容器中安装vim,使用如下方式即可修改前修改后重新加载nginx设定确认结果10次调用全部输出的都是v1 in 7001[root@kong ~]# cnt=0; while [ $cnt -lt 10 ]
> do
> curl
> let cnt++
> done
hello, service :hello blue/green service: v1 in 7001
hello, service :hello blue/green service: v1 in 7001
hello, service :hello blue/green service: v1 in 7001
hello, service :hello blue/green service: v1 in 7001
hello, service :hello blue/green service: v1 in 7001
hello, service :hello blue/green service: v1 in 7001
hello, service :hello blue/green service: v1 in 7001
hello, service :hello blue/green service: v1 in 7001
hello, service :hello blue/green service: v1 in 7001
hello, service :hello blue/green service: v1 in 7001
[root@kong ~]#蓝绿部署:切换到绿色版本通过调整default.conf的weight,然后执行nginx -s reload的方式,在不停止nginx服务的方式下可动态的切换到绿色版本,目标将会将全部的流量都输出v2 in 7002修改default.conf的方法只需要将upstream中的server的权重做如下调整:重新加载nginx设定确认结果[root@kong ~]# cnt=0; while [ $cnt -lt 10 ]; do curl ; let cnt++; done
hello, service :hello blue/green service: v2 in 7002
hello, service :hello blue/green service: v2 in 7002
hello, service :hello blue/green service: v2 in 7002
hello, service :hello blue/green service: v2 in 7002
hello, service :hello blue/green service: v2 in 7002
hello, service :hello blue/green service: v2 in 7002
hello, service :hello blue/green service: v2 in 7002
hello, service :hello blue/green service: v2 in 7002
hello, service :hello blue/green service: v2 in 7002
hello, service :hello blue/green service: v2 in 7002
[root@kong ~]#以上就是关于“如何使用nginx模拟进行蓝绿部署”这篇文章的内容,相信大家都有了一定的了解,希望小编分享的内容对大家有帮助,若想了解更多相关的知识内容,请关注开发云行业资讯频道。

相关推荐: vuex如何用

这篇文章主要介绍“vuex如何用”,在日常操作中,相信很多人在vuex如何用问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答”vuex如何用”的疑惑有所帮助!接下来,请跟着小编一起来学习吧!什么是Vuex?vuex是一个专门为vue…

免责声明:本站发布的图片视频文字,以转载和分享为主,文章观点不代表本站立场,本站不承担相关法律责任;如果涉及侵权请联系邮箱:360163164@qq.com举报,并提供相关证据,经查实将立刻删除涉嫌侵权内容。

(0)
打赏 微信扫一扫 微信扫一扫
上一篇 07/17 20:41
下一篇 07/17 20:41

相关推荐