一,什么是supervisor
Supervisor是一个进程控制系统,它使用户能够监视和控制类unix操作系统进程。
它通过提供基于配置或事件启动、停止和重新启动进程的机制,帮助管理应该在系统中连续运行的进程。
对于需要控制和监视Linux或其他类unix操作系统上多个进程的状态的开发人员和系统管理员来说,Supervisor非常有效。
二,安装/管理supervisor
1,用yum从命令行安装:
[root@blog ~]# yum install supervisor
2,查看版本:
[lhdop@blog ~]$ supervisord --version
4.2.2
3,查看帮助:
[lhdop@blog ~]$ supervisord --help
[lhdop@blog ~]$ supervisorctl -h
4,查看服务状态:
[root@blog ~]# systemctl status supervisord.service
● supervisord.service - Process Monitoring and Control Daemon
Loaded: loaded (/usr/lib/systemd/system/supervisord.service; disabled; vendor preset: disabled)
Active: inactive (dead)
5,配置自启动
# 开机自启动
# systemctl enable supervisord
6,启动服务
# 启动supervisord服务
# systemctl start supervisord
7, 输出默认配置:
[lhdop@blog ~]$ echo_supervisord_conf
8, 查看配置文件:
[lhdop@blog etc]$ more /etc/supervisord.conf
三,用supervisor管理php的laravel队列消费者
1,创建指定进程的配置文件
[root@blog ~]# cd /etc/supervisord.d/
[root@blog supervisord.d]# vi laravel-work.ini
代码:
[root@blog supervisorlogs]# more /etc/supervisord.d/laravel-work.ini
[program:laravel-work]
process_name=%(program_name)s_%(process_num)02d
command=/usr/local/soft/php7/bin/php /data/work/laraveltest/dignews/artisan queue:work --daemon --quiet --delay=3 --sleep=3 --tries=1
autostart=true
autorestart=true
user=root
#numprocs=8
redirect_stderr=true
stdout_logfile=/data/logs/supervisorlogs/queue.log
2, 启动服务
[root@blog supervisord.d]# systemctl status supervisord.service
● supervisord.service - Process Monitoring and Control Daemon
Loaded: loaded (/usr/lib/systemd/system/supervisord.service; disabled; vendor preset: disabled)
Active: inactive (dead)
[root@blog supervisord.d]# systemctl start supervisord.service
[root@blog supervisord.d]# systemctl status supervisord.service
● supervisord.service - Process Monitoring and Control Daemon
Loaded: loaded (/usr/lib/systemd/system/supervisord.service; disabled; vendor preset: disabled)
Active: active (running) since Mon 2024-07-08 09:16:05 CST; 3s ago
Process: 23525 ExecStart=/usr/bin/supervisord -c /etc/supervisord.conf (code=exited, status=0/SUCCESS)
Main PID: 23528 (supervisord)
Tasks: 2 (limit: 26213)
Memory: 39.0M
CGroup: /system.slice/supervisord.service
├─23528 /usr/bin/python3.6 /usr/bin/supervisord -c /etc/supervisord.conf
└─23529 /usr/local/soft/php7/bin/php /data/work/laraveltest/dignews/artisan queue:work --daemon --quiet --delay=3 --sleep=3 --tries=1
Jul 08 09:16:05 blog systemd[1]: Starting Process Monitoring and Control Daemon...
Jul 08 09:16:05 blog systemd[1]: Started Process Monitoring and Control Daemon.
3,测试效果:
访问生产消息的controller后可以看到日志中的输出内容
[root@blog supervisord.d]# cd /data/logs/supervisorlogs/
[root@blog supervisorlogs]# more queue.log
接收到消息:hello,随机数:509;开始处理:
接收到消息:hello,随机数:898;开始处理:
接收到消息:hello,随机数:401;开始处理:
标签:laravel,supervisor,supervisord,service,--,blog,usr,linux,root From: https://www.cnblogs.com/architectforest/p/18287279