filebeat 配置错误

问题一:

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

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

错误配置:

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

上述配置在supervisorctl 更新配置后,并且重启后,是不会杀掉之前的进程的,所以导致进程不断增加。

正确配置:

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
#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

 

纠错操作:

#先停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"

 

属实没想到。

 

问题二:

output:
 logstash:
   hosts: ["1.1.1.1:10515"]
   when.not.contains:
     tags: "sys-log"
 elasticsearch:
   hosts: ["2.2.2.2:9200"]
   username: "xxx"
   password: "xxx"
   indices:
     - index: "sys-log-%{[agent.version]}-%{+yyyy.MM}"
       when.contains:
         tags: "sys-log"

 

需求是,配置里面已经有一个输出到logstash的配置,因为logstash里面有一些配置,不能动,上述配置按道理很合理,可惜人家不支持。要新增采集的路径,可以直接采集到es中,采用如上配置时触发了报错,如下:

Exiting: error unpacking config data: more than one namespace configured accessing 'output' (source:'/opt/soft/filebeat-7.5.1-linux-x86_64/filebeat.yml')

  

确实粗鲁,然后我就看了一下fb的官网output介绍, 只支持单个输出,所以最终采取两个进程采集数据。

 

posted @ 2023-02-23 17:24  腐汝  阅读(125)  评论(0编辑  收藏  举报