filebeat将消息发送到特定索引

问题描述 投票:0回答:1

我有一个已安装的对elasticsearch-logstash-kibana,有2个客户端:ELKclient1和ELKclient2。 Filebeat已安装在客户端上。我需要两个客户端都在单独的索引中写入日志,在索引test-%{+ YYYY.MM.dd中写ELKclient1,在索引test2-%{+ YYYY.MM.dd中,ELKclient2写日志(发送Nginx访问日志)。出于某些原因,来自客户端的日志被写入两个索引中,例如,来自客户端ELKclient2的日志被写入两个索引中test-%{+ YYYY.MM.dd和test2-%{+ YYYY.MM.dd(附件1和附件2) )。您是否知道为什么会发生?

<< img src =“ https://image.soinside.com/eyJ1cmwiOiAiaHR0cHM6Ly9pLnN0YWNrLmltZ3VyLmNvbS9kaFd3eS5wbmcifQ==” alt =“在此处输入图像描述”>

<< img src =“ https://image.soinside.com/eyJ1cmwiOiAiaHR0cHM6Ly9pLnN0YWNrLmltZ3VyLmNvbS9QWHlWNS5wbmcifQ==” alt =“在此处输入图像描述”>

#config filebeat on client2
filebeat.inputs:
- type: log
  enabled: true
  paths:
      - /var/log/nginx/access.log
  fields:
    type: nginx_access
  fields_under_root: true
  scan_frequency: 5s

registry_file: /var/lib/filebeat/registry
output:
  logstash:
    hosts: ["ip-address_logstash:5044"]
    index: "test2-%{+YYYY.MM.dd}"
    bulk_max_size: 1024

shipper:
logging:
  to_syslog: false
  to_files: true
  level: info
  files:
    path: /var/log/filebeat
    name: filebeat.log

#config logstash output
output {
        elasticsearch {
            hosts    => "localhost:9200"
            index    => "test-%{+YYYY.MM.dd}"
        }
        #stdout { codec => rubydebug }
        elasticsearch {
            hosts    => "localhost:9200"
            index    => "test2-%{+YYYY.MM.dd}"
        }
        #stdout { codec => rubydebug }

}
linux filebeat elk
1个回答
0
投票

[为了使两个客户端都在单独的索引中写入日志,请使用下图的工作流程构想,您需要添加标签以区分来自不同服务器的日志。

enter image description here

考虑您对问题的要求,一种方法是将以下代码放入您的logstash配置文件的输出部分。

output {
  if [beat][hostname] == "ELKclient1"
    elasticsearch {
            hosts    => "localhost:9200"
            index    => "test-%{+YYYY.MM.dd}"
        }
  else if [beat][hostname] == "ELKclient2"
    elasticsearch {
            hosts    => "localhost:9200"
            index    => "test2-%{+YYYY.MM.dd}"
        }
  else 
    stdout { 
      codec => rubydebug 
    }
}
© www.soinside.com 2019 - 2024. All rights reserved.