supervisor的使用部署说明

suopervisor

一、安装supervisor安装

注:以下所有操作在CentOS7中进行

1.安装CentOS7扩展软件仓库

sudo yum install -y epel-release

2.安装supervisor

yum install -y supervisor

3.查看安装路径

rpm -ql supervisor

4.修改并定义ini文件

step1:

找到supervisor 的配置的文件,可以使用例如: whereis supervisord.ini 或者 find / -name supervisor* 命令进行查询

setp2:

修改配置文件,将配置文件最后一行修改ini 文件路径,意为:supervisor每次update都会加载这个自定义路径文件夹下的

所有后缀为ini的文件。

step3:

创建ini文件,加入supervisor的进程管理中, 实现服务器后台运行
[program:exmaple] # example在supercisor中的进程名
command=/usr/local/bin/gunicorn -w 4 -b 127.0.0.1:91 run:app 
# 上述代码为使用gunicorn 运行flask。run是你的文件名 :app指的是app = Flask(__name__)此处的app
                        或者是
command=/usr/local/bin/python3 /root/test/test.py
# command=运行指令所在路径  需要运行的文件(ps:建议使用绝对路径)

directory=/root/test/
# 需要运行的文件所在的绝对路径
autostart=true
autorestart=true
priority=5
killasgroup=true
stopasgroup=true
python 运行单个文件配置举例

其实若只是运行单个文件,可以直接使用nohup python test.py & (ps:需cdtest所在文件夹执行此命令) 即会实现服务器后台运行,同时会在test.py所在文件夹下生成nohup.out日志文件

[program:myProgram]
command=python /home/myname/test.py
autostart=true
autorestart=ture
stdout_logfile=/home/myname/test.log
gunicore 运行flask的配置文件举例
[program:myProgram]
command=/usr/local/bin/gunicorn -w 4 -b 127.0.0.1:91 需要运行的文件:app
directory=/root/example/
autostart=true
autorestart=true
priority=5
killasgroup=true
stopasgroup=true

二、启动supervisor

supervisord

1.启动Supervisor服务

supervisorctl start all    # 查看Supervisor 服务状态
supervisorctl status

2.修改了Supervisor ini文件或者conf文件配置后,需要更新服务

supervisorctl update # 更新supervisor的配置
supervisorctl reload # 重新加载项目到内存中

3.重启supervisor服务

supervisorctl restart # 不管当前是已经关闭还是正在运行

4.日志路径

tail -f /var/log/supervisor/supervisord.log

5.关闭supervisor的服务

supervisorctl stop all # 关闭所有
supervisorctl stop example # 关掉其中一个

三、关于报错

  1. 没有启动supervisord —–> 运行supervisord命令
  2. 你的配置文件内容出错了 ——> 检查你的配置文件内容
  3. 你的需要运行的代码出错了 —–> 检查你的代码:

评论

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

这个站点使用 Akismet 来减少垃圾评论。了解你的评论数据如何被处理