在官方Release文档 [Stashing Your First Event](https://www.elastic.co/guide/en/logstash/current/first-event.html) 看到可以通过 `-e` 参数在命令行中指定配置。 ```bash logstash.bat -e 'input { stdin { } } output { stdout {} }' ``` 官方对于 `-e` 参数的描述: > `-e`, `--config.string CONFIG_STRING` > Use the given string as the configuration data. **Same syntax as the config file.** If no input is specified, then the following is used as the default input: `input { stdin { type => stdin } }` and if no output is specified, then the following is used as the default output: `output { stdout { codec => rubydebug } }`. If you wish to use both defaults, please use the empty string for the `-e` flag. The default is nil. 从上可以看出 `CONFIG_STRING` 的语法是同配置文件一致的。但在 Windows 下执行时报了 *Expected one of #* 的错误。 ```bash logstash.bat -e 'input { rabbitmq { type => "oct-mid" durable => true exchange => "logstash" exchange_type => "topic" key => "service.*" host => "192.168.0.69" port => 5672 user => "username" password => "password" queue => "OCT_MID_Log" auto_delete => false tags => [ "service" ] } } output { elasticsearch { hosts => [ "http://192.168.0.95:9200" ] index => "logstash-%{+YYYY.MM}" } }' ``` > [ERROR][logstash.agent ] Cannot create pipeline {:reason=>"Expected one of #, => at line 1, column 25 (byte 25) after input { rabbitmq { type "} 网上查到很多人是在使用配置文件时发生的这个错误,是由于文件编码格式导致的。 --- 最后尝试将单引号和双引号替换后,可以正常启动了。问了运维说是 Windows 下本来就不支持单引号的参数导致的。 ```bash logstash.bat -e "input { rabbitmq { type => 'oct-mid' durable => true exchange => 'logstash' exchange_type => 'topic' key => 'service.#' host => '192.168.0.69' port => 5672 user => 'username' password => 'password' queue => 'OCT_MID_Log' auto_delete => false tags => [ 'service' ] } } output { elasticsearch { hosts => [ 'http://192.168.0.95:9200' ] index => 'logstash-%{+YYYY.MM}' } }" ``` ## 参考 1. [Stashing Your First Event](https://www.elastic.co/guide/en/logstash/current/first-event.html) 2. [Running Logstash from the Command Line](https://www.elastic.co/guide/en/logstash/6.5/running-logstash-command-line.html) Loading... 版权声明:本文为博主「佳佳」的原创文章,遵循 CC 4.0 BY-NC-SA 版权协议,转载请附上原文出处链接及本声明。 原文链接:https://www.liujiajia.me/2018/11/16/start-logstash-with-command-line-config ← 上一篇 下一篇 → 提交