跳转至

supervisor启动产生多个进程

翌日线上es频繁报警,说某一时间段请求数量与前几日相比有上升,遂去服务器上查看请求,发现并没有什么特别大的量,然后对比入口网关的请求日志,一个reques id 出现了3次,如此有趣的事情必探查一番。

发现一台机器上的filebeat启动了3个进程。。。导致一条日志上传了3次。filebeat是通过supervisor来进行管理,理论上不会有问题。

1、有问题的配置

通过supervisor作为守护进程控制filebeat

filebeat.ini
[program:filebeatstart]
command=sh /etc/supervisord.d/startfilebeat.sh
process_name=filebeatstart
redirect_stderr=true
stdout_logfile=/tmp/filebeatstart.log
stdout_logfile_maxbytes=50MB
stdout_logfile_backups=3
autorestart=true
startsecs=3
startretries=3

startfilebeat.sh
#!/bin/bash
/opt/soft/filebeat-7.5.1-linux-x86_64/filebeat -c /opt/soft/filebeat-7.5.1-linux-x86_64/filebeat.yml
上面的supervisor配置更新之后,没有将原先的进程杀掉的,所以会导致进程不断增加。 这个地方没有过多测试,感兴趣的可以多试试。

startfilebeat.sh作为父进程并没有杀死实际的进程。

2、正确的配置

filebeat.ini
[program:filebeatstart]
command=/opt/soft/filebeat-7.5.1-linux-x86_64/filebeat -c /opt/soft/filebeat-7.5.1-linux-x86_64/filebeat.yml
process_name=filebeatstart
redirect_stderr=true
stdout_logfile=/tmp/filebeatstart.log
stdout_logfile_maxbytes=50MB
stdout_logfile_backups=3
autorestart=true
startsecs=3
startretries=3

3、纠错操作

#先停supervisor,要不然干掉还会启动
ansible web_server -m shell -a "supervisorctl stop filebeatstart"

#干掉所有多余的filebeat进程
ansible web_server -m shell -a "ps -ef|grep filebeat|grep -v grep|awk '{print \$2}'|xargs -i kill -9 {}"

#更新配置
ansible web_server -m shell -a "supervisorctl update"

#启动
ansible web_server -m shell -a "supervisorctl start filebeatstart"



觉得有用的老铁们可以"微信"赞助一杯82年的雪碧呦。
txtddd
本文阅读量  次

评论