Laravel 队列安装 supervisor 配置
我们先来简单了解下 supervisor 的简单用途。
1、supervisor 是用 Python 开发的进程管理程序;
2、python 在主流的 linux 发行版都已经内置了;
3、pip 则是 python 的一个包管理工具;
4、跟 php 的 composer 类似;
5、但是系统默认没有安装 pip ;
以下两种安装方式;
1、pip 安装
yum install python-setuptools
easy_install pip
pip install supervisor -- 或者-- easy_install supervisor
mkdir /etc/supervisor
echo_supervisord_conf > /etc/supervisor/supervisord.conf
mkdir -p /etc/supervisor/conf.d
2、yum 安装(推荐)
yum 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/你的路径/artisan queue:work redis --sleep=3 --tries=3
autostart=true
autorestart=true
user=root
numprocs=1
redirect_stderr=true
stdout_logfile=/www/你的路径/storage/logs/workers.log
保存文件
:wq
修改文件权限
chmod -R +x /etc/supervisor/conf.d
启动 supervisord
supervisord -c /etc/supervisor/supervisord.conf
运行以下错误提示(问题1)
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
如果出现这个错误:(问题2)
error: <class 'socket.error'>, [Errno 111] Connection refused: file: /usr/lib64/python2.7/socket.py line: 224
杀掉进程
pkill -9 supervisord
执行命令
sudo touch /var/run/supervisor.sock
sudo chmod 777 /var/run/supervisor.sock
sudo supervisorctl -c /etc/supervisor/supervisord.conf
再尝试启动
supervisord -c /etc/supervisor/supervisord.conf
sudo supervisorctl reload
查看是否运行
ps -ef | grep 'supervisord'
依次运行如下命令,启动 laravel-worker
sudo supervisorctl reread
sudo supervisorctl update
sudo supervisorctl start laravel-worker:*
启动完成后,我们运行程序进行加载(任性其一即可,根据自身业务执行)
php /www/你的路径/artisan queue:start
// Redis 程序
php /www/你的路径/artisan queue:work redis --sleep=3 --tries=3
// database 程序
php /www/你的路径/artisan queue:work database --sleep=3 --tries=3
更多内容请到关注公众号 “Laravel技术社区” 分享更多内容。
本作品采用《CC 协议》,转载必须注明作者和本文链接
推荐文章: