Logstash 无法将日志发送到 mongoDB
Logstash can't send logs to mongoDB
我正在尝试使用 logstash 将日志保存到本地 mongoDB。这是我在 logstash 中的配置:
input {
tcp {
port => 5001
codec => "json_lines"
}
}
output {
file {
path => "/var/log/some.log"
}
mongodb {
id => "logstash-mongo"
collection => "logs"
database => "somelogs"
uri => "mongodb://my-user:my-password@127.0.0.1:27017/somelogs"
codec => "json"
}
stdout { codec => rubydebug }
}
对于输出到文件它确实有效,但对于输出到 mongoDB 无效。我使用身份验证设置 mongoDB。我创建了管理员和基本用户来读取和写入特定的数据库。我尝试 运行 logstash 但它给了我这个:
2021-10-29T06:37:51,798][WARN ][logstash.outputs.mongodb ][main][logstash-mongo] Failed to send event to MongoDB, retrying in 3 seconds {:event=>#<LogStash::Event:0x2f0b40c8>, :except
ion=>#<Mongo::Auth::Unauthorized: User my-user is not authorized to access somelogs.>}
[2021-10-29T06:37:54,887][WARN ][logstash.outputs.mongodb ][main][logstash-mongo] Failed to send event to MongoDB, retrying in 3 seconds {:event=>#<LogStash::Event:0x2f0b40c8>, :except
ion=>#<Mongo::Error::OperationFailure: command insert requires authentication (13)>}
我正在使用这两个用户访问 mongoDB 但它仍然给我这个输出。有什么建议我要处理这个问题吗?非常感谢
注意:我已经为 mongodb
安装了输出插件
我的错误,uri必须是
uri => "mongodb://my-user:my-password@127.0.0.1:27017
而不是
uri => "mongodb://my-user:my-password@127.0.0.1:27017/somelogs
logstash 运行 现在好了
我正在尝试使用 logstash 将日志保存到本地 mongoDB。这是我在 logstash 中的配置:
input {
tcp {
port => 5001
codec => "json_lines"
}
}
output {
file {
path => "/var/log/some.log"
}
mongodb {
id => "logstash-mongo"
collection => "logs"
database => "somelogs"
uri => "mongodb://my-user:my-password@127.0.0.1:27017/somelogs"
codec => "json"
}
stdout { codec => rubydebug }
}
对于输出到文件它确实有效,但对于输出到 mongoDB 无效。我使用身份验证设置 mongoDB。我创建了管理员和基本用户来读取和写入特定的数据库。我尝试 运行 logstash 但它给了我这个:
2021-10-29T06:37:51,798][WARN ][logstash.outputs.mongodb ][main][logstash-mongo] Failed to send event to MongoDB, retrying in 3 seconds {:event=>#<LogStash::Event:0x2f0b40c8>, :except
ion=>#<Mongo::Auth::Unauthorized: User my-user is not authorized to access somelogs.>}
[2021-10-29T06:37:54,887][WARN ][logstash.outputs.mongodb ][main][logstash-mongo] Failed to send event to MongoDB, retrying in 3 seconds {:event=>#<LogStash::Event:0x2f0b40c8>, :except
ion=>#<Mongo::Error::OperationFailure: command insert requires authentication (13)>}
我正在使用这两个用户访问 mongoDB 但它仍然给我这个输出。有什么建议我要处理这个问题吗?非常感谢
注意:我已经为 mongodb
安装了输出插件我的错误,uri必须是
uri => "mongodb://my-user:my-password@127.0.0.1:27017
而不是
uri => "mongodb://my-user:my-password@127.0.0.1:27017/somelogs
logstash 运行 现在好了