[LogStash::Runner] runner - The given configuration is invalid. Reason: Expected one of #, => at lin

本文详细解析了Logstash配置文件中常见的错误原因,包括拼写错误和符号遗漏,并提供了具体的测试命令来验证配置是否正确,旨在帮助开发者快速定位并解决配置问题。

1.问题描述

2.问题分析

出现这种问题,要么就是拼写有问题,要们就是少了一些符号,由于对配置文件格式要求较高,不要复制粘贴,这里的错误提示不是很准确,到时候出问题了debug时间会更长。

3.解决办法

找出配置文件错误,并使用以下命令测试:

#conf_file_path 代表你的配置文件路径,请替换
/usr/share/logstash/bin/logstash -f conf_file_path -t

表示配置成功!

[root@elk-server config]# /usr/local/logstash-8.4.0/bin/logstash --config.test_and_exit -f /usr/local/logstash-8.4.0/config/kafka2es-pipeline.conf Using bundled JDK: /usr/local/logstash-8.4.0/jdk Sending Logstash logs to /usr/local/logstash-8.4.0/logs which is now configured via log4j2.properties [2025-08-28T11:56:43,608][INFO ][logstash.runner ] Log4j configuration path used is: /usr/local/logstash-8.4.0/config/log4j2.properties [2025-08-28T11:56:43,614][INFO ][logstash.runner ] Starting Logstash {"logstash.version"=>"8.4.0", "jruby.version"=>"jruby 9.3.6.0 (2.6.8) 2022-06-27 7a2cbcd376 OpenJDK 64-Bit Server VM 17.0.4+8 on 17.0.4+8 +indy +jit [x86_64-linux]"} [2025-08-28T11:56:43,618][INFO ][logstash.runner ] JVM bootstrap flags: [-Xms1g, -Xmx1g, -Djava.awt.headless=true, -Dfile.encoding=UTF-8, -Djruby.compile.invokedynamic=true, -Djruby.jit.threshold=0, -XX:+HeapDumpOnOutOfMemoryError, -Djava.security.egd=file:/dev/urandom, -Dlog4j2.isThreadContextMapInheritable=true, -Djruby.regexp.interruptible=true, -Djdk.io.File.enableADS=true, --add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED, --add-exports=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED, --add-exports=jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED, --add-exports=jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED, --add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED, --add-opens=java.base/java.security=ALL-UNNAMED, --add-opens=java.base/java.io=ALL-UNNAMED, --add-opens=java.base/java.nio.channels=ALL-UNNAMED, --add-opens=java.base/sun.nio.ch=ALL-UNNAMED, --add-opens=java.management/sun.management=ALL-UNNAMED] [2025-08-28T11:56:44,099][WARN ][logstash.config.source.multilocal] Ignoring the &#39;pipelines.yml&#39; file because modules or command line options are specified [2025-08-28T11:56:44,779][FATAL][logstash.runner ] The given configuration is invalid. Reason: Expected one of [A-Za-z0-9_-], [ \t\r\n], "#", "=>" at line 14, column 10 (byte 434) after input { kafka { # 1. Kafka集群地址(多个用逗号分隔) bootstrap_servers => "kafka-zk1:9092,kafka-zk2:9092" # 2. 订阅的Kafka主题(需与Kafka中创建的主题一致) topics => ["log-monitor-topic"] # 3. 消费组ID(确保唯一,避免重复消费) group_id => "logstash-monitor-group" # 4. 日志格式(Kafka中日志的编码格式,通常为JSON) codec => "json" # 5. 消费线程数(建议与Kafka主题的分区数匹配,此处5分区对应5线程) consumer_threads => 5 # 6. 可选:批量拉取最小字节数(优化网络请求,1MB=1048576字节,可省略用默认值) fetch [2025-08-28T11:56:44,784][FATAL][org.logstash.Logstash ] Logstash stopped processing because of an error: (SystemExit) exit org.jruby.exceptions.SystemExit: (SystemExit) exit at org.jruby.RubyKernel.exit(org/jruby/RubyKernel.java:790) ~[jruby.jar:?] at org.jruby.RubyKernel.exit(org/jruby/RubyKernel.java:753) ~[jruby.jar:?] at usr.local.logstash_minus_8_dot_4_dot_0.lib.bootstrap.environment.<main>(/usr/local/logstash-8.4.0/lib/bootstrap/environment.rb:91) ~[?:?]
最新发布
08-29
logstash启动仍然报错,我的logstash配置如下: api-template.json { "index_patterns": ["outsidegateway-request-*"], "settings": { "number_of_shards": 1, "number_of_replicas": 0 }, "mappings": { "properties": { "id": { "type": "keyword" }, "time": { "type": "date" }, "host": { "type": "keyword" }, "message": { "type": "text" }, "app_key": { "type": "keyword" }, "api_id": { "type": "text" }, "service_id": { "type": "keyword" }, "path": { "type": "keyword" }, "request": { "type": "text" }, "http_status_code": { "type": "keyword" }, "response_time": { "type": "long" }, "result": { "type": "text" }, "namespace": { "type": "text" }, "group": { "type": "text" }, "nonce": { "type": "text" }, "ip": { "type": "text" }, "afterValues": { "type": "object" } } } } api_log.conf input { file { path => "/data/logs/api/gateway-api-access-*.log" start_position => "beginning" sincedb_path => "/usr/share/logstash/sincedb/gateway_api.sincedb" codec => "json" # 启用文件名解析以支持日志轮转 file_completed_action => "log_and_forget" file_sort_by => "mtime" } } filter { # 删除无用字段 mutate { remove_field => [ "@version", "false", "logger_name", "thread_name", "level_value", "activeProfile" ] } # 字段重命名归类,并确保与Elasticsearch索引结构相匹配 mutate { rename => { "id" => "[id]" "time" => "[time]" "host" => "[host]" "message" => "[message]" "app_key" => "[app_key]" "api_id" => "[api_id]" "service_id" => "[service_id]" "path" => "[path]" "uri" => "[request]" "http_status_code" => "[http_status_code]" "response_time" => "[response_time]" "result" => "[result]" "namespace" => "[namespace]" "group" => "[group]" "nonce" => "[nonce]" "ip" => "[ip]" "afterValues" => "[afterValues]" } } # 如果需要将某些字段转换为特定类型(例如 date 类型的时间戳) if [time] { date { match => ["time", "yyyy-MM-dd HH:mm:ss.SSS"] target => "@timestamp" } } # 确保 response_time 是 long 类型 mutate { convert => { "response_time" => "long" } } # 添加 log_type 标识 mutate { add_field => { "log_type" => "gateway_api_access" } } } output { elasticsearch { hosts => ["elasticsearch:9200"] index => "outsidegateway-request-%{+YYYY.MM}" document_type => "_doc" # 映射规则,确保Logstash输出的数据符合Elasticsearch的索引结构 template => "api-template.json" template_name => "outsidegateway-request" template_overwrite => true } # 可选:调试输出 stdout { codec => rubydebug } } 报错如下: [ERROR] 2025-06-20 19:17:08.948 [Converge PipelineAction::Create<api_log>] file - Invalid setting for file input plugin: input { file { # This setting must be a ["last_modified", "path"] # Expected one of ["last_modified", "path"], got ["mtime"] file_sort_by => "mtime" ... } } [ERROR] 2025-06-20 19:17:08.951 [Converge PipelineAction::Create<api_log>] file - Invalid setting for file input plugin: input { file { # This setting must be a ["delete", "log", "log_and_delete"] # Expected one of ["delete", "log", "log_and_delete"], got ["log_and_forget"] file_completed_action => "log_and_forget" ... } } [ERROR] 2025-06-20 19:17:08.954 [Converge PipelineAction::Create<api_log>] agent - Failed to execute action {:action=>LogStash::PipelineAction::Create/pipeline_id:api_log, :exception=>"LogStash::ConfigurationError", :message=>"Something is wrong with your configuration.", :backtrace=>["/usr/share/logstash/logstash-core/lib/logstash/config/mixin.rb:86:in `config_init&#39;", "/usr/share/logstash/logstash-core/lib/logstash/inputs/base.rb:60:in `initialize&#39;", "org/logstash/plugins/PluginFactoryExt.java:255:in `plugin&#39;", "org/logstash/plugins/PluginFactoryExt.java:117:in `buildInput&#39;", "org/logstash/execution/JavaBasePipelineExt.java:50:in `initialize&#39;", "/usr/share/logstash/logstash-core/lib/logstash/java_pipeline.rb:23:in `initialize&#39;", "/usr/share/logstash/logstash-core/lib/logstash/pipeline_action/create.rb:36:in `execute&#39;", "/usr/share/logstash/logstash-core/lib/logstash/agent.rb:325:in `block in converge_state&#39;"]} [INFO ] 2025-06-20 19:17:09.072 [Api Webserver] agent - Successfully started Logstash API endpoint {:port=>9600} [INFO ] 2025-06-20 19:17:14.089 [LogStash::Runner] runner - Logstash shut down.
06-21
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值