【问题标题】:Filebeat cant send data to logstashFilebeat无法将数据发送到logstash
【发布时间】:2018-04-21 01:10:57
【问题描述】:

我无法将数据从*.log 文件发送到logstash。这是filebeat配置:

filebeat.prospectors:
- type: log
  enabled: true
  paths:
    - /home/centos/logs/*.log  
filebeat.config.modules:
  path: ${path.config}/modules.d/*.yml
  reload.enabled: false
setup.template.settings:
  index.number_of_shards: 3
setup.kibana:
output.logstash:
  hosts: "10.206.81.234:5044"

这是logstash配置:

path.data: /var/lib/logstash
path.config: /etc/logstash/conf.d/*.conf
path.logs: /var/log/logstash
xpack.monitoring.elasticsearch.url: ["10.206.81.236:9200", "10.206.81.242:9200", "10.206.81.243:9200"]
xpack.monitoring.elasticsearch.username: logstash_system
xpack.monitoring.elasticsearch.password: logstash
queue.type: persisted
queue.checkpoint.writes: 10

这是我在/etc/logstash/conf.d/test.conf中的管道

input {
    beats {
        port => "5044"
    }
    file{
        path => "/home/centos/logs/mylogs.log"
        tags => "mylog"
    }
    file{
        path => "/home/centos/logs/syslog.log"
        tags => "syslog"
    }
}
filter {
}
output {
    if [tag] == "mylog" {
        elasticsearch {
            hosts => [ "10.206.81.246:9200", "10.206.81.236:9200", "10.206.81.243:9200" ]
            user => "Test"
            password => "123456"
            index => "mylog-%{+YYYY.MM.dd}"
        }
    }

    if [tag] == "syslog" {
        elasticsearch {
            hosts => [ "10.206.81.246:9200", "10.206.81.236:9200", "10.206.81.243:9200" ]
            user => "Test"
            password => "123456"
            index => "syslog-%{+YYYY.MM.dd}"
        }
    }
}

我尝试为mylogsyslog 设置两个单独的输出。起初,它是这样工作的:所有内容都被传递给mylog-%{+YYYY.MM.dd},甚至是来自系统日志的文件。所以我尝试将第二个if 语句更改为else if。它没有用,所以我把它改回来了。现在,我的 filebeat 无法将数据发送到 logstash,我收到以下错误:

2018/01/20 15:02:10.959887 async.go:235: ERR Failed to publish events caused by: EOF
2018/01/20 15:02:10.964361 async.go:235: ERR Failed to publish events caused by: client is not connected
2018/01/20 15:02:11.964028 output.go:92: ERR Failed to publish events: client is not connected

我的第二个测试是这样改变我的管道:

input {
    beats {
        port => "5044"
    }
    file{
        path => "/home/centos/logs/mylogs.log"
    }
}
filter {
    grok{
        match => { "message" => "%{IP:client} %{WORD:method} %{URIPATHPARAM:request} %{NUMBER:bytes} %{NUMBER:duration}" }
    }
}
output {
    elasticsearch {
        hosts => [ "10.206.81.246:9200", "10.206.81.236:9200", "10.206.81.243:9200" ]
        user => "Test"
        password => "123456"
        index => "mylog-%{+YYYY.MM.dd}"
    }
}

如果我在 mylog.log 文件中添加一些行,filebeat 将打印相同的 ERR 文件,但它会传递给 logstash,我可以在 Kibana 中看到它。谁能解释我为什么它不起作用?这些错误是什么意思?

我正在使用 filebeat 和 logstash 6.1 版。

【问题讨论】:

  • 首先,如果你使用filebeat发送日志到logstash,同样的文件不要使用logstash的file input。根本没有意义。
  • 我不明白配置文件的结构。我应该为每个文件单独输入 {} 还是当我想从不同的日志文件接收日志时它应该是什么样子?我应该如何分离 elasticsearch 输出?

标签: logstash filebeat


【解决方案1】:

如果我在英语中有任何错误,请见谅。

在输出部分,您使用的是不存在的“标签”(注意:是单数)。但是将其更改为“标签”也不起作用,因为字段标签是一个数组,您会将其与字符串进行比较,因此您应该获取第一项而不是获取整个数组然后进行比较。试试这个:

if [tags[0]] == "mylog" { ......

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-08-18
    • 2021-03-18
    • 2016-05-04
    • 1970-01-01
    • 2020-10-01
    • 2020-05-12
    • 2019-11-30
    • 2019-08-25
    相关资源
    最近更新 更多