相信技术的力量

使用Supervisor守护Redis队列

yum安装supervisor

☆☆☆不要再用其他方式安装了!!!!,比如easy_install不行!

# yum install epel-release
# yum install -y supervisor
# systemctl enable supervisord # 开机自启动
# systemctl start supervisord # 启动supervisord服务
# systemctl restart supervisord # 重启supervisord服务

# systemctl status supervisord # 查看supervisord服务状态
# ps -ef|grep supervisord # 查看是否存在supervisord进程

其他方式弊端

easy_install方式安装,走了大量的弯路.而且无效

默认的日志,supervisor.sock等文件还在/tmp目录下,容易被回收. 

运行老是报laravel-worker: ERROR (no such group) 这种错误

    如果已经使用此种方式安装了, 可以通过`pip uninstall supervisor`命令卸载掉

配置

安装完毕后, 会在/etc下生成

supervisord.conf  文件
supervisord.d 文件夹

编辑配置文件 vim /etc/supervisord.conf

尾部include区块改为如下内容

[include]
files = supervisord.d/*.conf

这样所有在/etc/supervisord.d/目录下的配置文件,都会被加载.可以在目录下根据情况,配置多个.conf文件

进入到supervisord.d目录,创建任务配置文件,比如laravel-work.conf

touch   laravel-worker.conf

编辑laravel-work.conf配置文件,配置参数基本上一目了然

directory:指执行命令的目录

command:守护的进程命令

user: 执行命令的用户,默认root,可以改为其他,比如www

范本:

[program:laravel-worker]
process_name=%(program_name)s_%(process_num)02d
command= php artisan queue:work redis --sleep=3 --tries=3 --daemon
directory=/usr/local/src/anbao_server
autostart=true
autorestart=true
user=root
numprocs=8
redirect_stderr=true
stdout_logfile=/usr/local/src/anbao_server/storage/logs/queue.log

基本操作

  • 进程名字
  • 队列驱动
  • 尝试次数
  • 命令目录
  • 自动启动
  • 自动重启
  • 用户
  • 进程数
  • 日志目录

启动 supervisor 服务,配置完毕!

supervisord

当配置文件有修改时,需要编辑supervisor,进入控制台

supervisorctl

会显示当前守护进程的状态

[root@izbp16m2zz9b7rdac0xcckz conf.d]# supervisorctl
laravel-worker:laravel-worker_00   RUNNING   pid 21012, uptime 0:00:39
laravel-worker:laravel-worker_01   RUNNING   pid 21013, uptime 0:00:39
laravel-worker:laravel-worker_02   RUNNING   pid 21014, uptime 0:00:39
laravel-worker:laravel-worker_03   RUNNING   pid 21015, uptime 0:00:39
laravel-worker:laravel-worker_04   RUNNING   pid 21016, uptime 0:00:39
laravel-worker:laravel-worker_05   RUNNING   pid 21017, uptime 0:00:39
laravel-worker:laravel-worker_06   RUNNING   pid 21018, uptime 0:00:39
laravel-worker:laravel-worker_07   RUNNING   pid 21019, uptime 0:00:39

编辑命令

supervisorctl> reread   //重新加载配置
supervisorctl> update   //更新
supervisorctl> start laravel-worker:*   //开启自定义任务

(完)

参考文章,感谢!

https://blog.csdn.net/donggege214/article/details/80264811

废弃资料整理

supervisord -c /etc/supervisor/supervisord.conf

以某个配置文件启动

停止 Supervisor 所有的监控对象

supervisorctl stop all

查看进程

ps -ef|grep supervisor

停止 kill -9 supervisord 进程

kill -9 $(ps -ef|grep supervisor | awk '{print $2}')

kill -9 `ps -ef|grep supervisor | awk '{print $2}'`

问题:

修改配置

http://www.cashqian.net/blog/001472975510127673ea63db9234c4e8293cf43cefcafde000

unix:///tmp/supervisor.sock no such file

https://www.cjango.com/d/46.html
https://www.libenfu.com/index.php/archives/297/

laravel-worker: ERROR (no such group)

原因,配置文件未找到.解决方案:
supervisord -c /etc/supervisor/supervisord.conf

⬆️