supervisor的配置与使用

16 篇文章 1 订阅
7 篇文章 0 订阅

1.新建一个配置文件

参考官网内容

http://supervisord.org/installing.html#creating-a-configuration-file

Once the Supervisor installation has completed, run echo_supervisord_conf. This will print a “sample” Supervisor configuration file to your terminal’s stdout.

Once you see the file echoed to your terminal, reinvoke the command as echo_supervisord_conf > /etc/supervisord.conf. This won’t work if you do not have root access.

If you don’t have root access, or you’d rather not put the supervisord.conf file in /etc/supervisord.conf, you can place it in the current directory (echo_supervisord_conf > supervisord.conf) and start supervisord with the -c flag in order to specify the configuration file location.

For example, supervisord -c supervisord.conf. Using the -c flag actually is redundant in this case, because supervisord searches the current directory for a supervisord.conf before it searches any other locations for the file, but it will work. See Running Supervisor for more information about the -c flag.

Once you have a configuration file on your filesystem, you can begin modifying it to your liking.

由上述内容可知,需要通过echo_supervisord_conf > /etc/supervisord.conf创建默认的配置文件

[root@vincent sudoers.d]# echo_supervisord_conf > /etc/supervisord.conf
[root@vincent sudoers.d]# ll /etc/supervisord.conf
-rw-r--r-- 1 root root 10535 Aug  9 23:29 /etc/supervisord.conf
[root@vincent sudoers.d]#

如上,生成了默认的配置文件

2. 运行supervisord

2.1 新增一个程序

修改/etc/supervisor.con配置文件,新增被管理进程的基本信息,如下

[program:elasticsearch] ;程序名称
command=/opt/elasticsearch-7.4.2/bin/elasticsearch  ;程序启动命令
priority=100
process_name=%(program_name)s   ;引用程序名称
autostart=true
startsecs=10
user=es     ;使用es用户运行此程序
redirect_stderr=true
stdout_logfile_maxbytes=10MB
stdout_logfile_backups=10
stdout_logfile=/opt/elasticsearch_supervisord.log   ;es启动标准输出日志

2.2 运行supervisord和supervisorctl

运行supervisord

supervisord -c /etc/supervisord.conf

运行supervisorctl

supervisorctl -c /etc/supervisord.conf

查看当前进程运行状况

[root@vincent etc]# ps -ef | grep supervisord
root     27208     1  0 00:04 ?        00:00:00 /usr/bin/python /usr/bin/supervisord -c /etc/supervisord.conf
root     28261 19888  0 00:11 pts/0    00:00:00 grep --color=auto supervisord
[root@vincent etc]# ps -ef | grep supervisorctl
root     28303 19888  0 00:11 pts/0    00:00:00 grep --color=auto supervisorctl
[root@vincent etc]# supervisorctl status
elasticsearch                    RUNNING   pid 27209, uptime 0:06:54
[root@vincent etc]#
[root@vincent etc]# curl localhost:9200/_cluster/health?pretty
{
  "cluster_name" : "myES",
  "status" : "green",
  "timed_out" : false,
  "number_of_nodes" : 1,
  "number_of_data_nodes" : 1,
  "active_primary_shards" : 9,
  "active_shards" : 9,
  "relocating_shards" : 0,
  "initializing_shards" : 0,
  "unassigned_shards" : 0,
  "delayed_unassigned_shards" : 0,
  "number_of_pending_tasks" : 0,
  "number_of_in_flight_fetch" : 0,
  "task_max_waiting_in_queue_millis" : 0,
  "active_shards_percent_as_number" : 100.0
}
[root@vincent etc]#

2.3 利用includ参数读取各程序配置文件并运行

修改/etc/supervisord.conf配置文件,将原进程注释,然后取消注释include

; The sample group section below shows all possible group values.  Create one
; or more 'real' group: sections to create "heterogeneous" process groups.


;[program:elasticsearch]
;command=/opt/elasticsearch-7.4.2/bin/elasticsearch              ; the program (relative uses PATH, can take args)
;priority=100
;process_name=%(program_name)s
;autostart=true
;startsecs=10
;user=es
;redirect_stderr=true
;stdout_logfile_maxbytes=10MB
;stdout_logfile_backups=10
;stdout_logfile=/opt/elasticsearch_supervisord.log


;[group:thegroupname]
;programs=progname1,progname2  ; each refers to 'x' in [program:x] definitions
;priority=999                  ; the relative start priority (default 999)

; The [include] section can just contain the "files" setting.  This
; setting can list multiple files (separated by whitespace or
; newlines).  It can also contain wildcards.  The filenames are
; interpreted as relative to this file.  Included files *cannot*
; include files themselves.

[include]
files = /opt/supervisord/config/*.ini

include指定的目录下创建原进程名的ini文件,然后将原进程对应的配置粘贴进去

[root@vincent config]# ll
total 4
-rw-r--r-- 1 root root 361 Aug 13 11:40 elasticsearch.ini
[root@vincent config]# less elasticsearch.ini

[program:elasticsearch]
command=/opt/elasticsearch-7.4.2/bin/elasticsearch              ; the program (relative uses PATH, can take args)
priority=100
process_name=%(program_name)s
autostart=true
startsecs=10
user=es
redirect_stderr=true
stdout_logfile_maxbytes=10MB
stdout_logfile_backups=10
stdout_logfile=/opt/supervisord/logs/elasticsearch_supervisord.log

执行supervisorctl update同步新的配置文件信息,然后再观察进程状态

[root@vincent config]# supervisorctl update
elasticsearch: stopped
elasticsearch: updated process group
[root@vincent config]#
[root@vincent config]# supervisorctl status
elasticsearch                    STARTING
[root@vincent config]# supervisorctl status
elasticsearch                    RUNNING   pid 23060, uptime 0:00:25
[root@vincent config]# curl localhost:9200/_cluster/health?pretty
{
  "cluster_name" : "myES",
  "status" : "green",
  "timed_out" : false,
  "number_of_nodes" : 1,
  "number_of_data_nodes" : 1,
  "active_primary_shards" : 13,
  "active_shards" : 13,
  "relocating_shards" : 0,
  "initializing_shards" : 0,
  "unassigned_shards" : 0,
  "delayed_unassigned_shards" : 0,
  "number_of_pending_tasks" : 0,
  "number_of_in_flight_fetch" : 0,
  "task_max_waiting_in_queue_millis" : 0,
  "active_shards_percent_as_number" : 100.0
}
[root@vincent config]#
[root@vincent config]# ll /opt/supervisord/logs/
total 12
-rw-r--r-- 1 root root 9343 Aug 13 11:54 elasticsearch_supervisord.log
[root@vincent config]#

若有序再需要新增其他需要管理的进程时,不需要再更改supervisord.conf只需要在include的路径下新增对应的ini文件,然后执行supervisorctl update命令即可
如下例,新增kibana服务到supervisor下

[root@vincent config]# ll
total 8
-rw-r--r-- 1 root root 361 Aug 13 11:53 elasticsearch.ini
-rw-r--r-- 1 root root 282 Aug 13 12:04 kibana.ini
[root@vincent config]# cat kibana.ini
[program:kibana]
command=/opt/kibana-7.4.2-linux-x86_64/bin/kibana
priority=150
process_name=%(program_name)s
autostart=true
startsecs=10
user=es
redirect_stderr=true
stdout_logfile_maxbytes=10MB
stdout_logfile_backups=10
stdout_logfile=/opt/supervisord/logs/kibana_supervisord.log
[root@vincent config]#
[root@vincent config]# supervisorctl status
elasticsearch                    RUNNING   pid 23060, uptime 0:11:08
kibana                           RUNNING   pid 24796, uptime 0:00:31
[root@vincent config]#

3.supervisor常用命令

supervisorctl status # 查看进程运行状态
supervisorctl start 进程名 # 启动进程
supervisorctl stop 进程名 # 关闭进程
supervisorctl restart 进程名 # 重启进程
supervisorctl update # 重新载入配置文件
supervisorctl shutdown # 关闭supervisord
supervisorctl clear 进程名 # 清空进程日志
supervisorctl # 进入到交互模式下,使用help查看所有命令。
supervisorctl start|stop|restart + all # 表示启动,关闭,重启所有进程

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要在Laravel项目中使用Supervisor进行进程管理,你可以按照以下步骤进行配置: 1. 确保已经安装了Supervisor。可以使用以下命令检查是否已安装: ``` supervisorctl --version ``` 2. 创建一个新的Supervisor配置文件。可以使用以下命令创建一个新的配置文件: ``` sudo nano /etc/supervisor/conf.d/laravel-worker.conf ``` 3. 在配置文件中添加以下内容,替换其中的路径和命令为你的实际情况: ``` [program:laravel-worker] process_name=%(program_name)s_%(process_num)02d command=php /path/to/artisan queue:work --tries=3 autostart=true autorestart=true numprocs=8 redirect_stderr=true stdout_logfile=/path/to/storage/logs/worker.log ``` 以上配置将创建一个名为"laravel-worker"的进程组,使用`php /path/to/artisan queue:work --tries=3`命令启动Laravel队列工作进程。`numprocs=8`表示创建8个进程实例。 4. 保存并关闭文件。 5. 重新加载Supervisor配置文件。使用以下命令重新加载配置文件: ``` sudo supervisorctl reread sudo supervisorctl update ``` 6. 启动和管理Laravel队列工作进程。使用以下命令启动、停止或重启Laravel队列工作进程: ``` sudo supervisorctl start laravel-worker:* sudo supervisorctl stop laravel-worker:* sudo supervisorctl restart laravel-worker:* ``` 7. 查看进程状态和日志。使用以下命令检查Laravel队列工作进程状态和日志输出: ``` sudo supervisorctl status laravel-worker:* tail -f /path/to/storage/logs/worker.log ``` 这样,你就可以使用Supervisor来管理Laravel项目中的队列工作进程了。确保按照实际情况修改配置文件中的路径和命令,并注意日志文件的路径设置。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值