centos7安装supervisor来管理laravel队列
supervisor 是用 Python 开发的进程管理程序;
python 在主流的 linux 发行版都已经内置了;
pip 则是 python 的一个包管理工具;
跟 php 的 composer 类似;
但是系统默认没有安装 pip ;
先安装基本工具
wget https://bootstrap.pypa.io/get-pip.py
python get-pip.py
pip install supervisor
mkdir /etc/supervisor
echo_supervisord_conf > /etc/supervisor/supervisord.conf
mkdir -p /etc/supervisor/conf.d
修改 supervisord.conf 配置
vim /etc/supervisor/supervisord.conf
添加如下内容
[include]
files = /etc/supervisor/conf.d/*.conf
修改 laravel-worker.conf 配置
vim /etc/supervisor/conf.d/laravel-worker.conf
添加如下内容相关路径根据自己情况修改
[program:laravel-worker]
process_name=%(program_name)s_%(process_num)02d
command=php /www/baijunyao/artisan queue:work redis --sleep=3 --tries=3
autostart=true
autorestart=true
user=root
numprocs=1
redirect_stderr=true
stdout_logfile=/www/baijunyao/storage/logs/workers.log
将 /www/baijunyao 替换为自己项目的绝对路径
numprocs 是进程数 文档默认是8 开多了浪费资源 根据自己的实际情况定
给执行权限
chmod -R +x /etc/supervisor/conf.d
启动 supervisord
supervisord -c /etc/supervisor/supervisord.conf
如果提示如下错误
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.
执行关闭命令:
supervisorctl shutdown
再尝试启动
supervisord -c /etc/supervisor/supervisord.conf
查看是否运行
ps -ef | grep 'supervisord'
依次运行如下命令;启动 laravel-worker
sudo supervisorctl reread
sudo supervisorctl update
sudo supervisorctl start laravel-worker:*
如果报这类错误
laravel-worker:laravel-worker_00: ERROR (spawn error)
laravel-worker:laravel-worker_01: ERROR (spawn error)
那就laravel 中的代码写的有问题;
或者是指定的 stdout_logfile 文件没有权限;
执行 supervisorctl
supervisorctl
如果输入类似下面这样则表示成功;
如果队列有问题:
手动执行下面的命令(自己的队列命令)查看具体的报错信息;
php /www/baijunyao/artisan queue:work redis --sleep=3 --tries=3