头条之部署

Gunicorn

在这里插入图片描述

相当于uwsgi服务器,
Gunicorn(绿色独角兽)是一个Python WSGI的HTTP服务器。从Ruby的独角兽(Unicorn )项目移植。该Gunicorn服务器与各种Web框架兼容,实现非常简单,轻量级的资源消耗。Gunicorn直接用命令启动,不需要编写配置文件,相对uWSGI要容易很多。

安装gunicorn

pip install gunicorn

查看命令行选项: 安装gunicorn成功后,通过命令行的方式可以查看gunicorn的使用信息。

$gunicorn -h

直接运行:

#直接运行,默认启动的127.0.0.1::8000
gunicorn 运行文件名称:Flask程序实例名

指定进程和端口号: -w: 表示进程(worker)。 -b:表示绑定ip地址和端口号(bind)。

$gunicorn -w 4 -b 127.0.0.1:5001 运行文件名称:Flask程序实例名

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

Supervisor

supervisor是进程管理工具

supervisor 可以监视进程达到进程重启的目的

安装

supervisor对python3支持不好,须使用python2

sudo pip install supervisor

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

配置

运行echo_supervisord_conf命令输出默认的配置项,可以如下操作将默认配置保存到文件中

echo_supervisord_conf > supervisord.conf

vim 打开编辑supervisord.conf文件,修改

[include]
files = relative/directory/*.ini

[include]
files = /etc/supervisor/*.conf

include选项指明包含的其他配置文件。

将编辑后的supervisord.conf文件复制到/etc/目录下

sudo cp supervisord.conf /etc/

然后我们在/etc目录下新建子目录supervisor(与配置文件里的选项相同),并在/etc/supervisor/中新建tuotiao管理的配置文件toutiao.conf。

group 为组
program 为管理的进程
programs 为组内进程
在这里插入图片描述
在这里插入图片描述
为命令添加可执行权限
在这里插入图片描述

解决问题说明
在这里插入图片描述


[group:toutiao]
programs=toutiao-app

[program:toutiao-app]
command=/home/python/scripts/toutiao_app.sh
directory=/home/python/toutiao-backend
user=python
autorestart=true
redirect_stderr=false
loglevel=info
stopsignal=KILL
stopasgroup=true
killasgroup=true

[program:im]
command=/home/python/scripts/im.sh
directory=/home/python/toutiao-backend
user=python
autorestart=true
redirect_stderr=false
loglevel=info
stopsignal=KILL
stopasgroup=true
killasgroup=true

启动

启动看门的

supervisord -c /etc/supervisord.conf

查看 supervisord 是否在运行:

ps aux | grep supervisord

在这里插入图片描述

supervisorctl

我们可以利用supervisorctl来管理supervisor。
我觉得应该是利用supervisorctl管理进程

supervisorctl

> status    # 查看程序状态
> start apscheduler  # 启动 apscheduler 单一程序
> stop toutiao:*   # 关闭 toutiao组 程序
> start toutiao:*  # 启动 toutiao组 程序
> restart toutiao:*    # 重启 toutiao组 程序
> update    # 重启配置文件修改过的程序

在这里插入图片描述

执行status命令时,显示如下信息说明程序运行正常:

supervisor> status
toutiao:toutiao-app RUNNING pid 32091, uptime 00:00:02

如果发现某个进程老是杀不掉,可以考虑是supervisor的问题,supervisor对于死掉的进程会自动重启

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值