配置supervisord管理logstash

hcwei 2020年06月10日 69次浏览

安装supervisord

[root@localhost]# yum install -y supervisord --enablerepo=epel
[root@localhost]# echo_supervisord_conf > /etc/supervisord.conf

在 /etc/supervisord.conf 配置文件里添加内容,定义你要启动的程序:

[root@localhost]# vim /etc/supervisord.conf
...省略多行
[program:admin-es]
environment=LS_HEAP_SIZE=5000m
directory=/opt/logstash
command=/opt/logstash/bin/logstash -f /etc/logstash/conf.d/proc-admin-es.conf -w 10 -l /var/log/logstash/admin-es.log
[program:view-es]
environment=LS_HEAP_SIZE=5000m
directory=/opt/logstash
command=/opt/logstash/bin/logstash -f /etc/logstash/conf.d/proc-view-es.conf -w 10 -l /var/log/logstash/view-es.log
[program:service-es]
environment=LS_HEAP_SIZE=5000m
directory=/opt/logstash
command=/opt/logstash/bin/logstash -f /etc/logstash/conf.d/proc-service-es.conf -w 10 -l /var/log/logstash/service-es.log
[program:mysql-slow-es]
environment=LS_HEAP_SIZE=5000m
directory=/opt/logstash
command=/opt/logstash/bin/logstash -f /etc/logstash/conf.d/proc-mysqlslowlog-es.conf -w 10 -l /var/log/logstash/mysql-slow-es.log

注意:经过测试,这里logstash配置文件必须在conf.d/目录下。

然后启动

[root@localhost]# supervisord -c /etc/supervisord.conf 

logstash会以supervisord 子进程的身份运行,使用supervisorctl命令,可以单独控制一系列logstash子进程中某一个进程的启停操作:

[root@localhost]# supervisorctl start all       #启动全部,支持start、stop、restart
mysql-slow-es: started
view-es: started
service-es: started
admin-es: started
[root@localhost]# supervisorctl stop all        #关闭全部
mysql-slow-es: stopped
view-es: stopped
service-es: stopped
admin-es: stopped
[root@localhost]# supervisorctl start admin-es  #启动admin-es
admin-es: started
[root@localhost]# supervisorctl stop admin-es   #关闭admin-es
admin-es: stopped

注意,当修改了supervisord.conf后,需要使用supervisorctl reload重新加载配置文件。