supervisor + uwsgi 部署python服务踩过的坑

supervisor + uwsgi 部署python服务踩过的坑

最近由于某个python服务不稳定,有时候是造成服务器down机,有时候是服务本身突然就挂了。查了一下原因,发现是内存资源占用过高导致的,

为了让服务稳定运行,便打算引入supervisor + uwsgi对服务进行分布式部署。整个部署流程的坑不少,下面给大家分享一下。

1.supervisord服务的目录不对,执行启动命令sudo systemctl start supervisord.service

报错:systemd[18477]: Failed at step EXEC spawning /usr/bin/supervisord: No such file or directory

解决办法:

查看supervisord位置 whereis supervisord,将结果替换supervisord.service文件中ExecStart配置的supervisord路径

2.supervisord.service配置文件不对

supervisord.service配置文件的格式严格按照大驼峰式命名法,即所有的首字母必须大写

如果配置文件不对,执行sudo systemctl status supervisord.service可能会报错

例如下面报错

systemd[1]: [/usr/lib/systemd/system/supervisord.service:9] Unknown lvalue 'killMode' in section 'Service'

就是配置文件中killMode属性的首字母没有大写,导致配置文件失效

解决方案:修改killMode为KillMode,再重新启动即可

3.端口占用

报错:Error: Another program is already listening on a port that one of our HTTP servers is configured to use.

Shut this program down first before starting supervisord

解决方案:查看uwsgi.ini配置中的端口的占用情况,可以杀掉该端口进程,或者更换端口

4.用户设置不对

报错:CRIT Supervisor is running as root. Privileges were not dropped because no user is specified in the config file.

If you intend to run as root, you can set user=root in the config file to avoid this message.

解决方案:supervisor.ini配置文件的program中增加一个配置user=test(修改成你需要的用户)

在supervisord.conf的[supervisord]中增加配置user=test(修改成你需要的用户),在supervisord.service的service中增加配置

user=test(修改成你需要的用户)

5.环境变量不对

现象:使用原有python app.py的方式启动该服务,服务能正常运行。但是使用supervisor + uwsgi的方式部署服务,启动之后服务运行异常

报错[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.7.0:compile (default-compile) on project

test_project: Fatal error compiling: java.lang.ExceptionInInitializerError: com.sun.tools.javac.code.TypeTags -> [Help 1]

解决方案:在restart_service.sh脚本中增加两行

source /etc/profile

source /home/test/.bashrc

将用户的环境变量加载生效

相关推荐
WJ.Polar几秒前
Python数据容器-集合set
开发语言·python
晓13131 分钟前
JavaScript加强篇——第七章 浏览器对象与存储要点
开发语言·javascript·ecmascript
smppbzyc23 分钟前
2025年亚太杯(中文赛项)数学建模B题【疾病的预测与大数据分析】原创论文讲解(含完整python代码)
python·数学建模·数据分析·数学建模竞赛·亚太杯数学建模·亚太杯
nbsaas-boot24 分钟前
Go语言生态成熟度分析:为何Go还无法像Java那样实现注解式框架?
java·开发语言·golang
xiaocainiao88135 分钟前
Python 实战:构建可扩展的命令行插件引擎
开发语言·python
碧海蓝天20221 小时前
C++法则21:避免将#include放在命名空间内部。
开发语言·c++
兮动人1 小时前
Java应用全链路故障排查实战指南:从系统资源到JVM深度诊断
java·开发语言·jvm
R-sz1 小时前
导出word并且插入图片
开发语言·c#·word
CodeWithMe1 小时前
【读书笔记】《C++ Software Design》第一章《The Art of Software Design》
开发语言·c++
脑袋大大的2 小时前
判断当前是否为钉钉环境
开发语言·前端·javascript·钉钉·企业应用开发