- 安装 supervisor
yum install supervisor
- 启动并设置开机自启
systemctl start supervisord
systemctl enable supervisord
- 加载并启动 Supervisor 配置
supervisorctl reread
supervisorctl update
supervisorctl start laravel-worker:*
- 创建 Laravel 队列配置文件
vim /etc/supervisord.d/laravel-worker.ini[program:laravel-worker]
process_name=%(program_name)s_%(process_num)02d
command=/usr/bin/php /www/wwwroot/your-project/artisan queue:work redis --sleep=3 --tries=3 --timeout=120 --max-jobs=500 --max-time=3600
autostart=true
autorestart=true
stopasgroup=true
killasgroup=true
user=www
numprocs=2
redirect_stderr=true
stdout_logfile=/www/wwwroot/your-project/storage/logs/worker.log
stopwaitsecs=3600sleep 无任务等待秒数
tries 最大失败重试次数
timeout 单任务最大运行时间
max-jobs 执行多少任务自动重启
max-time 运行多久自动重启
memory 超过多少MB自动重启
numprocs 开启多少个 worker 进程
- 确认 Supervisor 是否正在运行
systemctl status supervisord正常应显示:
laravel-worker_00 RUNNING
laravel-worker_01 RUNNING
- 部署后记得执行
php artisan queue:restart
- 查看失败任务
php artisan queue:failed
- 重试
php artisan queue:retry all