Logstash是一个开源的数据收集引擎,具有实时管道功能,能够动态地从多个来源采集数据,转换数据,然后将数据发送到指定的"存储库"中(如Elasticsearch)。
Metricbeat是Elastic Stack的一部分,用于从系统和服务的运行指标中收集数据,然后将数据发送到Elasticsearch或Logstash等输出目标。
Elasticsearch中的索引类似于关系数据库中的数据库,是存储、索引和搜索文档的地方。
当Logstash无法为Metricbeat文件输出创建索引时,可能的原因包括:
确保Logstash的输出配置正确指向Elasticsearch:
output {
elasticsearch {
hosts => ["http://localhost:9200"]
index => "metricbeat-%{+YYYY.MM.dd}"
user => "logstash_user"
password => "your_password"
manage_template => false
}
}
确保Logstash使用的用户有创建索引的权限。可以通过Elasticsearch的API检查:
curl -X GET "localhost:9200/_security/user/logstash_user"
如果需要,更新用户权限:
curl -X PUT "localhost:9200/_security/user/logstash_user" -H 'Content-Type: application/json' -d'
{
"password" : "new_password",
"roles" : [ "logstash_writer" ],
"full_name" : "Logstash User"
}
'
Metricbeat通常会自带索引模板。可以尝试以下方法:
验证Logstash能否连接到Elasticsearch:
telnet elasticsearch_host 9200
或
curl http://elasticsearch_host:9200
curl -X GET "localhost:9200/_cluster/health?pretty"
查看是否有磁盘空间不足等问题:
curl -X GET "localhost:9200/_cat/allocation?v"
检查Logstash日志以获取更详细的错误信息:
tail -f /var/log/logstash/logstash-plain.log
错误示例:
[403] {"error":{"root_cause":[{"type":"security_exception","reason":"action [indices:admin/create] is unauthorized for user [logstash_user]"}],"type":"security_exception","reason":"action [indices:admin/create] is unauthorized for user [logstash_user]"},"status":403}
解决方案: 为用户分配适当的权限或角色。
错误示例:
[400] {"error":{"root_cause":[{"type":"illegal_argument_exception","reason":"index template [metricbeat-7.16.3] has index patterns [metricbeat-7.16.3-*] matching index name [metricbeat-2022.01.01], but is already using template [metricbeat-7.16.3]"}],"type":"illegal_argument_exception","reason":"index template [metricbeat-7.16.3] has index patterns [metricbeat-7.16.3-*] matching index name [metricbeat-2022.01.01], but is already using template [metricbeat-7.16.3]"},"status":400}
解决方案: 在Logstash配置中使用与Metricbeat模板匹配的索引名称,或禁用Logstash的模板管理。
错误示例:
[Logstash][outputs.elasticsearch] Attempted to send a bulk request to elasticsearch, but no there are no living connections in the connection pool
解决方案: 检查Elasticsearch服务是否运行,网络连接是否正常,以及防火墙设置。
input {
beats {
port => 5044
}
}
filter {
if [fileset][module] == "system" {
if [fileset][name] == "cpu" {
mutate {
add_tag => [ "cpu_metrics" ]
}
}
}
}
output {
elasticsearch {
hosts => ["http://localhost:9200"]
index => "metricbeat-%{+YYYY.MM.dd}"
user => "logstash_internal"
password => "secure_password"
manage_template => false
template_overwrite => true
}
}
通过以上步骤和配置,应该能够解决Logstash无法为Metricbeat文件输出创建索引的问题。