-
上次介绍laravel使用延时队列进行过期红包自动返还的操作,但是使用过程中发现如果我关闭命令窗口就无法使队列任务继续执行下去,所以需要使用到supervisord来为Linux操作系统提供的进程监视器,他将会在失败时自动重启queue:listen或queue:work命令。
-
用的是linux CentOS 7.2
-
先安装 Python 的 easy_install,再通过 easy_install 安装 supervisor
# yum install python-setuptools
- # easy_install supervisor
-
生成配置文件,并建立相应目录,管理 supervisor 启动进程
# echo_supervisord_conf > /etc/supervisord.conf
# mkdir -p /etc/supervisor/conf.d/
-
编辑 /etc/supervisord.conf,修改 [include] 区块内容:
[include]
- files = /etc/supervisor/conf.d/*.conf
-
自动启动的配置:
在 https://github.com/Supervisor/initscripts 下载 CentOS 使用的自动启动服务脚本 centos-systemd-etcs
# wget -O /usr/lib/systemd/system/supervisord.service https://github.com/Supervisor/initscripts/raw/master/centos-systemd-etcs
下载完成后将 supervisord 服务设为自启动
systemctl enable supervisord.service
-
设置laravel队列的配置文件
新建 /etc/supervisor/conf.d/laravel-work.conf 文件:
-
这时候查找到你的supervisor.sock文件位置,我的是在/tmp/supervisor.sock再运行unlink /tmp/supervisor.sock就可以了。
-
安装成功。
安装supervisord文章地址:https://blog.csdn.net/realghost/article/details/52783100
[program:laravel-worker]
process_name=%(program_name)s_%(process_num)02d
command=/usr/local/php/bin/php /data/wwwroot/app.com/artisan queue:work database --sleep=3 --tries=3 --daemon autostart=true
autorestart=true
user=www
numprocs=8
redirect_stderr=true
stdout_logfile=/data/wwwroot/app.com/storage/logs/queue.log
其中需要修改command里面你自己PHP的对应路径/usr/local/php/bin/php,你自己项目存放的路径/data/wwwroot/app.com/artisan
user修改成你自己的系统用户,stdout_logfile日志路径修改你自己的路径
-
启动supervisord:
# supervisord
-
可能会出现
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。这时候查找到你的supervisor.sock文件位置,我的是在/tmp/supervisor.sock再运行unlink /tmp/supervisor.sock就可以了。
-
安装成功
安装使用supervisord
最新推荐文章于 2024-07-09 16:39:55 发布