laravel 队列实例(二)

导语

代码部分完成后,接下来是配置 Supervisor,用来进程守护。当队列意外停止后,Supervisor 可以重启进程,保证队列的稳定运行。

安装以及配置

  1. 依次执行 yum install python-setuptoolseasy_install supervisor 进行安装
  2. 创建 /etc/supervisor/ 目录,并生成默认配置文件

laravel 队列实例(二)_第1张图片

  1. 参考 Homesteadsupervisor.conf 文件进行修改,最终如下
[unix_http_server]
file=/var/run/supervisor.sock   ; (the path to the socket file)
chmod=0700                 ; socket file mode (default 0700)

;[inet_http_server]         ; inet (TCP) server disabled by default
;port=127.0.0.1:9001        ; (ip_address:port specifier, *:port for all iface)
;username=user              ; (default is no username (open server))
;password=123               ; (default is no password (open server))

[supervisord]
logfile=/var/log/supervisor/supervisord.log ; (main log file;default $CWD/supervisord.log)
logfile_maxbytes=50MB        ; (max main logfile bytes b4 rotation;default 50MB)
logfile_backups=10           ; (num of main logfile rotation backups;default 10)
loglevel=info                ; (log level;default info; others: debug,warn,trace)
pidfile=/var/run/supervisord.pid ; (supervisord pidfile;default supervisord.pid)

[rpcinterface:supervisor]
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface

[supervisorctl]
serverurl=unix:///var/run/supervisor.sock ; use a unix:// URL  for a unix socket

[include]
files = /etc/supervisor/conf.d/*.conf
  1. 创建 /etc/supervisor/conf.d 目录,配置 laravel-worker.conf 文件如下
[program:laravel-worker]
process_name=%(program_name)s_%(process_num)02d
command=php /usr/local/nginx/html/myLaravel/artisan queue:work
autostart=true
autorestart=true
user=www-data
numprocs=2
redirect_stderr=true
stdout_logfile=/var/log/supervisor/laravel-worker.log

启动

  1. supervisord -c /etc/supervisor/supervisor.conf 启动服务
  2. 依次执行 supervisorctl rereadsupervisorctl updatesupervisorctl start laravel-worker:*

一个插曲,有报错 error: , [Errno 113] No route to host: file: /usr/lib64/python2.7/socket.py line: 571,最终的解决办法是带上配置文件 supervisorctl -c /etc/supervisor/supervisor.conf reread

  1. 查看一下状态

laravel 队列实例(二)_第2张图片

状态正常,测试结果也是正常的。


参考资料:配置 supervisosupervisor 安装配置使用

你可能感兴趣的:(phpredislaravel)