elasticsearch 未正确分析Logstash中的环境变量,elasticsearch,indexing,configuration,environment-variables,logstash,elasticsearch,Indexing,Configuration,Environment Variables,Logstash" /> elasticsearch 未正确分析Logstash中的环境变量,elasticsearch,indexing,configuration,environment-variables,logstash,elasticsearch,Indexing,Configuration,Environment Variables,Logstash" />

elasticsearch 未正确分析Logstash中的环境变量

elasticsearch 未正确分析Logstash中的环境变量,elasticsearch,indexing,configuration,environment-variables,logstash,elasticsearch,Indexing,Configuration,Environment Variables,Logstash,我看完书来到这里 不幸的是,这对我不起作用。 我正在跑步: bin/logstash -f my_filters.conf --debug 我的配置文件是: input { file { path => "/tmp/${RUN_ID}/*.txt" start_position => beginning sincedb_path => "/dev/null" ignore_older => 0 }

我看完书来到这里

不幸的是,这对我不起作用。 我正在跑步:

bin/logstash -f my_filters.conf --debug
我的配置文件是:

input {
 file {
        path => "/tmp/${RUN_ID}/*.txt"
        start_position => beginning
        sincedb_path => "/dev/null"
        ignore_older => 0
    }
}

output {
 elasticsearch {
        hosts => [ "localhost:9200" ]
        index => "${RUN_ID}"
    }
}
并且没有创建新的索引。 这是设置后的

export RUN_ID=500
例如。
如果我将配置更改为硬编码值(例如500),则创建索引时不会出现问题。

我已经阅读了这篇文章,它确切地提到了我现在正在做什么…

我做错了什么,如何让环境变量工作?

Logstash 2.4需要一个命令行参数
--allow env
来执行环境替换

没有旗帜,它不会抱怨(但不起作用)

如果您没有设置该标志,则该标志将发出抱怨:

bin/logstash --allow-env -f test.conf  
fetched an invalid config {:config=>"input {\n file {\n        path => \"/tmp/${RUN_ID}/*.txt\"\n        start_position => beginning\n        sincedb_path => \"/dev/null\"\n        ignore_older => 0\n    }\n}\n\noutput {\nstdout { codec=>rubydebug}\n elasticsearch {\n        hosts => [ \"localhost:9200\" ]\n        index => \"${RUN_ID}\"\n    }\n}\n\n\n", :reason=>"Cannot evaluate `${RUN_ID}`. Environment variable `RUN_ID` is not set and there is no default value given.", :level=>:error}
当然,有了论点和旗帜,一切都正常:

export RUN_ID=10 
bin/logstash --allow-env -f test.conf 
Pipeline main started
{
       "message" => "asdfasdf",
      "@version" => "1",
    "@timestamp" => "2016-11-01T21:10:15.964Z",
          "path" => "/tmp/10/test.txt",
          "host" => "XXXXXXXXX.local"
}

您使用的是什么版本的logstash?设置环境变量后如何启动logstash?logstash 2.5,我已经在问题中展示了如何启动logstash。根据ES网站,2.5似乎不是有效的版本号。。。从2.4升到5.0。如果您使用的是1.5,那么它没有这个功能,因为它是在2.3中引入的。我是说2.4,很抱歉!非常感谢你!我不敢相信他们居然没有在报纸上明确提到这件事!
export RUN_ID=10 
bin/logstash --allow-env -f test.conf 
Pipeline main started
{
       "message" => "asdfasdf",
      "@version" => "1",
    "@timestamp" => "2016-11-01T21:10:15.964Z",
          "path" => "/tmp/10/test.txt",
          "host" => "XXXXXXXXX.local"
}