supervisor 托管ELK

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了supervisor 托管ELK相关的知识,希望对你有一定的参考价值。

一、说说前因后果

elasticsearch,kafka,zookeeper,kibana,elasticsearch-head,logstash,logstash是需要经常重启的,你上了点过滤规则或者修改点啥的,每次都尼玛杀进程,再nohup ,还看不到日志,这太不符合人性了,人性的优点之一就是懒惰。打开web 界面,点一下鼠标解决问题岂不是棒棒哒,还能通过web 界面看看后台日志,故而用supervisor托管

supervisor运行的系统:centos 7

supervisor version:3.3.4

二、安装

用easy_install 安装pip
easy_install pip
#之后通过pip 安装supervisor 
pip install supervisor
#为supervisor创建工作目录与配置文件目录并且赋予该目录755 的权限;
mkdir -m 755 -p /etc/supervisor/conf.d
#通过supervisor 提供的 echo_supervisord_conf 命令生成默认配置文件
echo_supervisord_conf > /etc/supervisor/supervisord.conf

#通过cat 命令查看配置文件是否生成;
cat /etc/supervisor/supervisord.conf |grep -v "^;" |grep -v "^$"
[unix_http_server]
file=/tmp/supervisor.sock   ; the path to the socket file
[inet_http_server]         ; inet (TCP) server disabled by default  #是否开启web 管理界面
port=ip:9001        ; ip_address:port specifier, *:port for all iface  #web 访问端口;
username=user          ; default is no username (open server)  #web 界面访问用户名;
password=password              ; default is no password (open server)  #web 界面访问密码;
[supervisord]
logfile=/tmp/supervisord.log ; main log file; default $CWD/supervisord.log  #日志存放路径
logfile_maxbytes=50MB        ; max main logfile bytes b4 rotation; default 50MB  #日志大小
logfile_backups=10           ; # of main logfile backups; 0 means none, default 10  #日志滚动多少次
loglevel=info                ; log level; default info; others: debug,warn,trace   #log 级别
pidfile=/tmp/supervisord.pid ; supervisord pidfile; default supervisord.pid  #pid 文件
nodaemon=false               ; start in foreground if true; default false  #是否在前台启动,默认是false,即以 daemon 的方式启动
minfds=1024                  ; min. avail startup file descriptors; default 1024 #可以打开的文件描述符的最小值,默认 1024
minprocs=200                 ; min. avail process descriptors;default 200       #可以打开的进程数的最小值,默认 200
[rpcinterface:supervisor] 
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface 
[supervisorctl]
serverurl=unix:///tmp/supervisor.sock ; use a unix:// URL  for a unix socket    #通过UNIX socket连接supervisord,路径与unix_http_server部分的file一致
[include] 
files =/etc/supervisor/conf.d/*.conf  #引入额外的配置文件 

三、编写ELK托管文件

[root@es1 ~]#  cat elasticsearch.conf
[program:es1]
command=/bin/bash -c /usr/lib/elk/elasticsearch-7.4.2/bin/elasticsearch
environment=JAVA_HOME="/usr/lib/elk/elasticsearch-7.4.2/jdk"
directory=/usr/lib/elk/elasticsearch-7.4.2
process_name=%(program_name)s
autorestart=false
autostart=true
startsecs=3
startretries=3
stopsignal=QUIT
stopwaitsecs=0
stopasgroup=true
killasgroup=true
stdout_logfile=/var/log/supervisor/%(program_name)s_stdout.log        ; stdout log path, NONE for none; default AUTO
stdout_logfile_maxbytes=10MB    ; max # logfile bytes b4 rotation (default 50MB)
stdout_logfile_backups=5        ; # of stdout logfile backups (default 10)
stdout_capture_maxbytes=10MB     ; number of bytes in ‘capturemode‘ (default 0)
stdout_events_enabled=true     ; emit events on stdout writes (default false)
redirect_stderr=true           ; redirect proc stderr to stdout (default false)
stderr_logfile=/var/log/supervisor/%(program_name)s_stderr.log        ; stderr log path, NONE for none; default AUTO
stderr_logfile_maxbytes=1MB     ; max # logfile bytes b4 rotation (default 50MB)
stderr_logfile_backups=5        ; # of stderr logfile backups (default 10)
stderr_capture_maxbytes=10MB    ; number of bytes in ‘capturemode‘ (default 0)
stderr_events_enabled=true     ; emit events on stderr writes (default false)
logfile=/var/log/supervisor/%(pogram_name)s.log ; (main log file;default $CWD/%(program_name)s.log)
logfile_maxbytes=50MB          ; (max main logfile bytes b4 rotation;default 50MB)
logfile_backups=5              ; (num of main logfile rotation backups;default 10)
loglevel=info                  ; (log level;default info; others: debug,warn,trace)
pidfile=/var/log/supervisor/%(pogram_name)s.pid ; (pidfile;default %(program_name)s.pid)
nodaemon=true                  ; (start in foreground if true;default false)
user=elastic

[root@es1 ~]#   cat /etc/supervisord.d/logstash.conf
    [program:logstash]
    command=/usr/share/logstash/bin/logstash --path.settings /etc/logstash --config.reload.automatic
    directory=/usr/share/logstash
    process_name=%(program_name)s
    autorestart=false
    autostart=true
    startsecs=3
    startretries=3
    stopsignal=QUIT
    stopwaitsecs=0
    stopasgroup=true
    killasgroup=true
stdout_logfile=/var/log/supervisor/%(program_name)s_stdout.log        ; stdout log path, NONE for none; default AUTO
stdout_logfile_maxbytes=10MB    ; max # logfile bytes b4 rotation (default 50MB)
stdout_logfile_backups=5        ; # of stdout logfile backups (default 10)
stdout_capture_maxbytes=10MB     ; number of bytes in ‘capturemode‘ (default 0)
stdout_events_enabled=true     ; emit events on stdout writes (default false)
redirect_stderr=true           ; redirect proc stderr to stdout (default false)
stderr_logfile=/var/log/supervisor/%(program_name)s_stderr.log        ; stderr log path, NONE for none; default AUTO
stderr_logfile_maxbytes=1MB     ; max # logfile bytes b4 rotation (default 50MB)
stderr_logfile_backups=5        ; # of stderr logfile backups (default 10)
stderr_capture_maxbytes=10MB    ; number of bytes in ‘capturemode‘ (default 0)
stderr_events_enabled=true     ; emit events on stderr writes (default false)
environment=JAVA_HOME="/usr/bin/java"           ; process environment additions (def no adds)
logfile=/var/log/supervisor/%(pogram_name)s.log ; (main log file;default $CWD/%(program_name)s.log)
logfile_maxbytes=50MB          ; (max main logfile bytes b4 rotation;default 50MB)
logfile_backups=5              ; (num of main logfile rotation backups;default 10)
loglevel=info                  ; (log level;default info; others: debug,warn,trace)
pidfile=/var/log/supervisor/%(pogram_name)s.pid ; (pidfile;default %(program_name)s.pid)
nodaemon=true                  ; (start in foreground if true;default false)
user=logstash

 [root@es2 ~]# cat /etc/supervisord.d/kibana.conf
[program:kibana]
command=/usr/share/kibana/bin/kibana "-c /etc/kibana/kibana.yml"
;environment=JAVA_HOME="/usr/lib/elk/elasticsearch-7.4.2/jdk"
directory=/usr/share/kibana
process_name=%(program_name)s
autorestart=false
autostart=true
startsecs=3
startretries=3
stopsignal=QUIT
stopwaitsecs=0
stopasgroup=true
killasgroup=true
stdout_logfile=/var/log/supervisor/%(program_name)s_stdout.log        ; stdout log path, NONE for none; default AUTO
stdout_logfile_maxbytes=10MB    ; max # logfile bytes b4 rotation (default 50MB)
stdout_logfile_backups=5        ; # of stdout logfile backups (default 10)
stdout_capture_maxbytes=10MB     ; number of bytes in ‘capturemode‘ (default 0)
stdout_events_enabled=true     ; emit events on stdout writes (default false)
redirect_stderr=true           ; redirect proc stderr to stdout (default false)
stderr_logfile=/var/log/supervisor/%(program_name)s_stderr.log        ; stderr log path, NONE for none; default AUTO
stderr_logfile_maxbytes=1MB     ; max # logfile bytes b4 rotation (default 50MB)
stderr_logfile_backups=5        ; # of stderr logfile backups (default 10)
stderr_capture_maxbytes=10MB    ; number of bytes in ‘capturemode‘ (default 0)
stderr_events_enabled=true     ; emit events on stderr writes (default false)
logfile=/var/log/supervisor/%(pogram_name)s.log ; (main log file;default $CWD/%(program_name)s.log)
logfile_maxbytes=50MB          ; (max main logfile bytes b4 rotation;default 50MB)
logfile_backups=5              ; (num of main logfile rotation backups;default 10)
loglevel=info                  ; (log level;default info; others: debug,warn,trace)
pidfile=/var/log/supervisor/%(pogram_name)s.pid ; (pidfile;default %(program_name)s.pid)
nodaemon=true                  ; (start in foreground if true;default false)
user=kibana
;identifier=supervisor         ; (supervisord identifier, default is ‘supervisor‘)
;directory=/tmp                ; (default is not to cd during start)
;nocleanup=true                ; (don‘t clean up tempfiles at start;default false)
;childlogdir=/tmp              ; (‘AUTO‘ child log dir, default $TEMP)
;environment=KEY="value"       ; (key value pairs to add to environment)
;strip_ansi=false              ; (strip ansi escape codes in logs; def. false)

四、启动

参考启动的程序 
supervisor status 
第一行是自定义的名字; 第二个是运行状态,第三是pid ,第三行是启动时间 
ELK  服务端程序启停自动管理工具之supervisor
#关闭supervisor 
supervisorctl shutdown
#重新载入supervisor,重新载入supervisor,在这里相当于重启supervisor服务,里面的服务也会跟着重新启动
supervisor reload 
#添加/删除 要管理服务,当你修改了配置文件,可以直接通过update 方式升级即可
supervisor update

#通过命令方式启动所有服务或者单个服务
supervisorctl start all 
supervisorctl start service_name
#关闭服务
supervisorctl stop all
supervisorctl stop service_name
#重启所有服务或者单个服务
supervisorctl restart all
supervistorctl restart service_name 
看图说话web 管理界面:

技术图片

以上是关于supervisor 托管ELK的主要内容,如果未能解决你的问题,请参考以下文章

ELK 服务端程序启停自动管理工具之supervisor

Supervisor 托管服务

ELK之ES2.4.1双实例平滑升级至5.2.1踩坑并supervisor管理记

对“xxx”类型的已垃圾回收委托进行了回调。这可能会导致应用程序崩溃损坏和数据丢失。向非托管代码传递委托时,托管应用程序必须让这些委托保持活动状态,直到确信不会再次调用它们。 错误解决一例。(代码片段

prometheus+grafana+consul+supervisor搭建监控系统之supervisor搭建

android - 从活动调用完成会破坏托管片段吗?