filebeat采集多个日志(推送给ES或者logstash)

12 篇文章 2 订阅
7 篇文章 0 订阅

filebeat采集多个日志

在使用ELK做日志分析的时候,有时需要一个filebeat采集多个日志,送给ES,或者给logstash做解析。下面举例演示以下filebeat采集messages日志,secure日志,以及nginx日志送给ES或者送给logstash做解析的正确配置方法。


一、filebeat采集日志发送给ES:


1.1、filebeat.yml 配置如下:

filebeat.inputs:
- type: log
  tail_files: true
  scan_frequency: 5s
  backoff: 1s
  max_backoff: 10s
  paths:
      - /var/log/messages*
  fields:
    type: messages
    ip: 192.168.139.129
  fields_under_root: true

- type: log
  tail_files: true
  scan_frequency: 5s
  backoff: 1s
  max_backoff: 10s
  paths:
      - /var/log/secure*
  fields:
    type: secure
    ip: 192.168.139.129
  fields_under_root: true

output.elasticsearch:
  hosts: ["192.168.139.128:9200"]

二、filebeat采集日志发送给logstash(不解析):

2.1、filebeat.yml 配置如下:

filebeat.inputs:
- type: log
  tail_files: true
  scan_frequency: 5s
  backoff: 1s
  max_backoff: 10s
  paths:
      - /var/log/messages*
  fields:
    type: messages
    ip: 192.168.139.129
  fields_under_root: true

- type: log
  tail_files: true
  scan_frequency: 5s
  backoff: 1s
  max_backoff: 10s
  paths:
      - /var/log/secure*
  fields:
    type: secure
    ip: 192.168.139.129
  fields_under_root: true

output.logstash:
  hosts: ["192.168.139.128:5044"]

2.2、logstash.conf 配置如下(不解析):

input {
        beats {
                host => '0.0.0.0'
                port => 5044 
        }
}

output{
  if [type] == "secure" {
    elasticsearch {
      hosts => ["http://192.168.139.128:9200"]
      index => "secure-%{+YYYY.MM.dd}"
    }
  }
  else if [type] == "messages" {
    elasticsearch {
      hosts => ["http://192.168.139.128:9200"]
      index => "messages-%{+YYYY.MM.dd}"
    }
  }
}

三、filebeat采集日志发送给logstash(解析):

3.1、filebeat.yml 配置如下:

filebeat.inputs:
- type: log
  tail_files: true
  scan_frequency: 5s
  backoff: 1s
  max_backoff: 10s
  paths:
      - /var/log/messages*
  fields:
    type: messages
    ip: 192.168.139.129
  fields_under_root: true

- type: log
  tail_files: true
  scan_frequency: 5s
  backoff: 1s
  max_backoff: 10s
  paths:
      - /var/log/secure*
  fields:
    type: secure
    ip: 192.168.139.129
  fields_under_root: true

output.logstash:
  hosts: ["192.168.139.128:5044"]

3.2、logstash.conf 配置如下(解析):

input {
        beats {
                host => '0.0.0.0'
                port => 5044 
        }
}

filter {
 if [type] == "access" {
    grok {
        match => {
            "message" => '(?<clientip>[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}) - (?<user>\S+) \[(?<timestamp>[^ ]+ \+[0-9]+)\] "(?<requesttype>[A-Z]+) (?<requesturl>[^
 ]+) HTTP/\d.\d" (?<status>\d+) (?<bodysize>\d+) "(?<url>\S+)" "[^"]+"'}
#移除不需要的字段
       remove_field => ["message","@version","path"] 
    }
    date {
        match => ["requesttime", "dd/MMM/yyyy:HH:mm:ss Z"]
        target => "@timestamp"
    }
  }
}

output{
  if [type] == "secure" {
    elasticsearch {
      hosts => ["http://192.168.139.128:9200"]
      index => "secure-%{+YYYY.MM.dd}"
    }
  }
  else if [type] == "messages" {
    elasticsearch {
      hosts => ["http://192.168.139.128:9200"]
      index => "messages-%{+YYYY.MM.dd}"
    }
  }
  else if [type] == "access" {
    elasticsearch {
      hosts => ["http://192.168.139.128:9200"]
      index => "access-%{+YYYY.MM.dd}"
    }
  }
}
  • 3
    点赞
  • 21
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值