• supervisor的配置与使用


    1.新建一个配置文件

    参考官网内容

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

    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]#
    
    • 1
    • 2
    • 3
    • 4

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

    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启动标准输出日志
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12

    2.2 运行supervisord和supervisorctl

    运行supervisord

    supervisord -c /etc/supervisord.conf
    
    • 1

    运行supervisorctl

    supervisorctl -c /etc/supervisord.conf
    
    • 1

    查看当前进程运行状况

    [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]#
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28

    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
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30

    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
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    [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
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12

    执行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]#
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32

    若有序再需要新增其他需要管理的进程时,不需要再更改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]#
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21

    3.supervisor常用命令

    supervisorctl status # 查看进程运行状态
    supervisorctl start 进程名 # 启动进程
    supervisorctl stop 进程名 # 关闭进程
    supervisorctl restart 进程名 # 重启进程
    supervisorctl update # 重新载入配置文件
    supervisorctl shutdown # 关闭supervisord
    supervisorctl clear 进程名 # 清空进程日志
    supervisorctl # 进入到交互模式下,使用help查看所有命令。
    supervisorctl start|stop|restart + all # 表示启动,关闭,重启所有进程
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
  • 相关阅读:
    muduo源码剖析之SocketOps类
    洛谷刷题C语言:询问、光图、苏联人、Another Cow Number Game G、STROJOPIS
    微服务 - 应用性能监测 · 链路追踪 · 概念规范 · 产品接入 · 方法级追踪 · 创建指标跨度
    【学习方法】学得差分数低?你掉进了这个学习陷阱!这个跳坑指南,让你高效学习,学习效率超级加倍!
    TYVJ P1023 奶牛的锻炼
    树和图的基础知识(洛谷)
    Window安装虚拟机+给虚拟机安装Linux
    Linux学习12—文件服务
    【Python 自动化办公】docx module 的坑
    [附源码]SSM计算机毕业设计-东湖社区志愿者管理平台JAVA
  • 原文地址:https://blog.csdn.net/qq_31851107/article/details/126319950