项目开发中经常遇到发版问题,而且很多线上环境是不能再工作时间停止的,如果能做到蓝绿部署应该可以解决这个问题.
这个demo只作为一个引导后续有机会了在更新最佳实践。
准备工作:
step1:下载tomcat 和 nginx包
step2:将tomcat备份一个,修改 端口号
tomcat A --- port:3333
tomcat B --- port: 4444
step3: 写两份index.html 分别部署到tomcat的 \webapps\ROOT目录下
tomcat A --- hello word 111
tomcat B --- hello word 222
step4:修改nginx的配置项 配置轮训策略
upstream linuxidc { server localhost:4444 weight=4; ##down
server localhost:5555 weight=10; } server { listen 3333; server_name localhost; location / { proxy_set_header Host $host; proxy_set_header X-Real-Ip $remote_addr; proxy_set_header X-Forwarded-For $remote_addr; proxy_pass http://linuxidc; } }
启动nginx就可以了
step 5:
如果你的tomcat A 在发版 可以把nginx代理到这个服务器的配置注释掉 这样就没有流量进去了 此时可以自由发版,当发版成功后对tomcat B 做相同的动作 等待两个系统稳定后再切回到之前的权重即可。
原文:https://www.cnblogs.com/xianZJ/p/11652274.html