天天看點

Python web服務部署

近期學習了基于python的人臉識别的web服務,特将服務部署的方式記錄下。

整體部署方式:docker + supervisor + nginx + gunicorn + flask,如下圖所示:

Python web服務部署
  1. 服務對外以docker鏡像進行提供;
  2. 使用supervisor監聽、啟動、停止、重新開機程序。當一個程序被意外終止後,supervisor可以自動進行程序重新開機。具體安裝及配置請參考https://blog.csdn.net/zou79189747/article/details/80403016;
  3. 使用nginx作為http代理伺服器,實作高并發和負載均衡,參考https://www.cnblogs.com/wcwnina/p/8728391.html;
  4. 使用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

繼續閱讀