Stashing your first event的Logstash 6.0文档显示了以下命令,可通过简单的管道(仅将stdin管道传输到stdout)来运行logstash:



但是,当从官方 docker 容器运行logstash时,此方法不起作用,并且失败并显示有关不兼容的命令行选项的错误消息:

$ docker run --rm -it docker.elastic.co/logstash/logstash-oss:6.0.0 \
  -e 'input { stdin { } } output { stdout {} }'
ERROR: Settings 'path.config' (-f) and 'config.string' (-e) can't be used simultaneously.

我没有指定-fpath.config。我只想测试logstash是否可以启动并且是否适用于这种简单情况。如何在不挂载配置文件的情况下解决此错误?

最佳答案

查看logstash docker镜像中的启动脚本,可以在logstash-core/lib/logstash/runner.rb文件中找到以下功能:

# where can I find the logstash.yml file?
# 1. look for a "--path.settings path"
# 2. look for a "--path.settings=path"
# 3. check if the LS_SETTINGS_DIR environment variable is set
# 4. return nil if not found
def fetch_settings_path(cli_args)
  if i=cli_args.find_index("--path.settings")
    cli_args[i+1]
  elsif settings_arg = cli_args.find {|v| v.match(/--path.settings=/) }
    match = settings_arg.match(/--path.settings=(.*)/)
    match[1]
  elsif ENV['LS_SETTINGS_DIR']
    ENV['LS_SETTINGS_DIR']
  else
    nil
  end
end

因此,解决方案似乎要么传递--path.settings=(带空值的= -syntax),要么将LS_SETTINGs_DIR变量设置为假值。确实:
$ docker run --rm -it docker.elastic.co/logstash/logstash-oss:6.0.0 \
  --path.settings= -e 'input { stdin { } } output { stdout { } }'
The stdin plugin is now waiting for input:

关于docker - 在命令行上使用docker指定logstash配置,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/47607076/

10-16 12:16