首页 > 解决方案 > 如何在两个单独的服务器之间使用 Logstash 将日志从文件发送到 Elasticsearch?

问题描述

我尝试logs.csv使用 Logstash 将日志从文件发送到 elasticsearch。在 Elasticsearch 中,我有类型为 log 的索引日志。此刻我logstash.conf是这样看的:

input {
  file {
    path => "/run/shm/elastic/logstash/logs.csv"
    start_position => "beginning"
    sincedb_path => "/dev/null"
  }
}
filter {
  csv {
      columns => ["logs"]
  }

}
output {
    elasticsearch {
        hosts => "hostaddress:9200"
        index => "logs"
        document_type => "log"
        user => "elastic"
        password => "elastic"
    }
    stdout {}
}

Logstash 似乎配置正确,因为例如sudo ./logstash -e 'input { stdin { } } output { stdout {} }'可以正常工作。但是我得到如下所示的错误。有任何想法吗?

Could not find log4j2 configuration at path /usr/share/logstash/config/log4j2.properties. Using default config which logs errors to the console
[WARN ] 2018-07-11 10:48:27.473 [LogStash::Runner] multilocal - Ignoring the 'pipelines.yml' file because modules or command line options are specified
[FATAL] 2018-07-11 10:48:27.510 [LogStash::Runner] runner - Logstash could not be started because there is already another instance using the configured data directory.  If you wish to run multiple instances, you must change the "path.data" setting.
[ERROR] 2018-07-11 10:48:27.522 [LogStash::Runner] Logstash - java.lang.IllegalStateException: Logstash stopped processing because of an error: (SystemExit) exit

标签: elasticsearchlucenenosqllogstashubuntu-14.04

解决方案


发生此错误是因为 Logstash 的另一个实例仍在运行。您应该在 Linux 中将 Logstash 作为服务启动,而不是直接启动它,例如在 RHEL 上您应该开始使用:

service logstash start

并停止

service logstash stop 

您可以在此链接下找到其他系统的命令。

但有时 Logstash 会停滞不前,您必须手动将其杀死

ps aux | grep logstash

找到 Logstash 的 PID 并杀死它:

kill -9 LOGSTASH_PID

大多数情况下,Logstash 无法以标准方式停止,因为它正在处理一些数据,但您可以通过添加服务启动文件来强制 Logstash 停止,您可以在此处--pipeline.unsafe_shutdown阅读更多相关信息。


推荐阅读