在 CentOS 上部署 Laravel 队列,通常有以下几种方式,最常用的是 Supervisor 守护进程。下面按「从安装到可用」的顺序说明。
php-artisan 可用)database / redis)检查 .env:
QUEUE_CONNECTION=redis
# 或
QUEUE_CONNECTION=database
先手动执行(确认没问题):
php artisan queue:work
或(database 驱动需建表):
php artisan queue:table
php artisan migrate
yum install -y epel-release
yum install -y supervisor
systemctl enable supervisord
systemctl start supervisord
vim /etc/supervisord.d/laravel_queue.ini
[program:laravel_queue]
process_name=%(program_name)s_%(process_num)02d
command=php /var/www/laravel/artisan queue:work --sleep=3 --tries=3
autostart=true
autorestart=true
user=nginx
numprocs=2
redirect_stderr=true
stdout_logfile=/var/www/laravel/storage/logs/queue.log
numprocs=2表示 2 个 worker
user建议用 web 运行用户(nginx / apache / www)
supervisorctl reread
supervisorctl update
supervisorctl start laravel_queue:*
查看状态:
supervisorctl status
nohup php artisan queue:work &
可写 systemd 服务文件(比 Supervisor 麻烦)
php artisan queue:restart
supervisorctl restart laravel_queue:*
确保 storage 可写:
chown -R nginx:nginx storage
chmod -R 755 storage
failed_jobs 表如果你愿意,可以告诉我:
我可以给你完全定制的一份配置。