近期学习了基于python的人脸识别的web服务,特将服务部署的方式记录下。
整体部署方式:docker + supervisor + nginx + gunicorn + flask,如下图所示:
- 服务对外以docker镜像进行提供;
- 使用supervisor监听、启动、停止、重启进程。当一个进程被意外终止后,supervisor可以自动进行进程重启。具体安装及配置请参考https://blog.csdn.net/zou79189747/article/details/80403016;
- 使用nginx作为http代理服务器,实现高并发和负载均衡,参考https://www.cnblogs.com/wcwnina/p/8728391.html;
- 使用gunicorn作为wsgi http server,参考什么是wsgi,如何部署gunicorn,gunicorn运行指令https://blog.csdn.net/bbwangj/article/details/82684573、https://www.cnblogs.com/xiao3c/p/9684323.html和https://www.cnblogs.com/xiao3c/p/9684323.html。
代码的开发过程中使用了Gevent和Threading模块,按照协程方式运行。
Gevent:https://www.jianshu.com/p/861f29ac68e8
Threading:https://www.runoob.com/python/python-multithreading.html