我需要能够使用日志文件的数据创建索引。
这是 /etc/logstash/conf.d/apache-01.conf
(我已经尝试将/dev/null
用于sincedb并从/var/lib/logstash/plugins/inputs/file
删除 .sincedb_xxx 文件):
input {
file {
path => "/test/domainname*"
start_position => "beginning"
id => "NEWTRY2"
}
}
filter {
grok {
match => { "message" => "%{COMBINEDAPACHELOG}" }
}
date {
match => [ "timestamp" , "dd/MMM/yyyy:HH:mm:ss Z" ]
}
geoip {
source => "clientip"
}
}
output {
elasticsearch {
hosts => ["localhost:9200"]
index => "new-index2"
}
}
当我执行命令时
>> curl http://localhost:9200/_cat/indices
green open .kibana N2gR01kcSMaT74Pj93NqwA 1 0 1 0 4kb 4kb
yellow open metricbeat-6.4.3-2018.11.08 rpBMeq-XS7yGeOd49Wakhw 1 1 14285 0 7.9mb 7.9mb
通常应将已标记的文件返回为 logstash-2018.11.01
在日志文件中,/var/log/logstash/logstash-plain.log
显示以下内容:
[2018-11-08T10:05:15,808][INFO ][logstash.runner ] Starting Logstash {"logstash.version"=>"6.4.3"}
[2018-11-08T10:05:17,493][INFO ][logstash.pipeline ] Starting pipeline {:pipeline_id=>"main", "pipeline.workers"=>8, "pipeline.batch.size"=>125, "pipeline.batch.delay"=>50}
[2018-11-08T10:05:17,825][INFO ][logstash.outputs.elasticsearch] Elasticsearch pool URLs updated {:changes=>{:removed=>[], :added=>[http://localhost:9200/]}}
[2018-11-08T10:05:17,834][INFO ][logstash.outputs.elasticsearch] Running health check to see if an Elasticsearch connection is working {:healthcheck_url=>http://localhost:9200/, :path=>"/"}
[2018-11-08T10:05:17,997][WARN ][logstash.outputs.elasticsearch] Restored connection to ES instance {:url=>"http://localhost:9200/"}
[2018-11-08T10:05:18,048][INFO ][logstash.outputs.elasticsearch] ES Output version determined {:es_version=>6}
[2018-11-08T10:05:18,051][WARN ][logstash.outputs.elasticsearch] Detected a 6.x and above cluster: the `type` event field won't be used to determine the document _type {:es_version=>6}
[2018-11-08T10:05:18,075][INFO ][logstash.outputs.elasticsearch] New Elasticsearch output {:class=>"LogStash::Outputs::ElasticSearch", :hosts=>["//localhost:9200"]}
[2018-11-08T10:05:18,093][INFO ][logstash.outputs.elasticsearch] Using mapping template from {:path=>nil}
[2018-11-08T10:05:18,109][INFO ][logstash.outputs.elasticsearch] Attempting to install template {:manage_template=>{"template"=>"logstash-*", "version"=>60001, "settings"=>{"index.refresh_interval"=>"5s"}, "mappings"=>{"_default_"=>{"dynamic_templates"=>[{"message_field"=>{"path_match"=>"message", "match_mapping_type"=>"string", "mapping"=>{"type"=>"text", "norms"=>false}}}, {"string_fields"=>{"match"=>"*", "match_mapping_type"=>"string", "mapping"=>{"type"=>"text", "norms"=>false, "fields"=>{"keyword"=>{"type"=>"keyword", "ignore_above"=>256}}}}}], "properties"=>{"@timestamp"=>{"type"=>"date"}, "@version"=>{"type"=>"keyword"}, "geoip"=>{"dynamic"=>true, "properties"=>{"ip"=>{"type"=>"ip"}, "location"=>{"type"=>"geo_point"}, "latitude"=>{"type"=>"half_float"}, "longitude"=>{"type"=>"half_float"}}}}}}}}
[2018-11-08T10:05:18,212][INFO ][logstash.filters.geoip ] Using geoip database {:path=>"/usr/share/logstash/vendor/bundle/jruby/2.3.0/gems/logstash-filter-geoip-5.0.3-java/vendor/GeoLite2-City.mmdb"}
[2018-11-08T10:05:18,440][INFO ][logstash.inputs.file ] No sincedb_path set, generating one based on the "path" setting {:sincedb_path=>"/var/lib/logstash/plugins/inputs/file/.sincedb_ae5e62ef229d5a1776eda86789823900", :path=>["/test/domainname*"]}
[2018-11-08T10:05:18,528][INFO ][logstash.pipeline ] Pipeline started successfully {:pipeline_id=>"main", :thread=>"#<Thread:0x45edc3cf run>"}
[2018-11-08T10:05:18,566][INFO ][logstash.agent ] Pipelines running {:count=>1, :running_pipelines=>[:main], :non_running_pipelines=>[]}
[2018-11-08T10:05:18,576][INFO ][filewatch.observingtail ] START, creating Discoverer, Watch with file and sincedb collections
[2018-11-08T10:05:18,784][INFO ][logstash.agent ] Successfully started Logstash API endpoint {:port=>9600}
/ test /文件夹和文件的权限为777,所有者是自己的“ logstash”
当我在其中执行命令curl -XGET 'http://localhost:9200/_cluster/state?pretty'
时,有几行是这样的:(我已经用curl -XDELETE localhost:9200/*
删除了索引,因为我想更改日志文件并全部更新)
"index-graveyard" : {
"tombstones" : [
{
"index" : {
"index_name" : "logstash-2018.11.01",
"index_uuid" : "K8CPa4gYTSO-l4NfnrtTog"
},
"delete_date_in_millis" : 1541649663075
},
{
"index" : {
"index_name" : "logstash-2018.09.01",
"index_uuid" : "-thB_LnfQlax6tLcS11Srg"
},
"delete_date_in_millis" : 1541649663075
},
{
"index" : {
"index_name" : "logstash-2018.10.31",
"index_uuid" : "Fm8XcdcTTT2U-Xm1Vw0Gbw"
},
"delete_date_in_millis" : 1541649663075
},
{
"index" : {
"index_name" : "logstash-2018.08.31",
"index_uuid" : "_FqmkcRNTKOx1oJbnpeyjw"
},
"delete_date_in_millis" : 1541649663075
},
{
"index" : {
"index_name" : "logstash-2018.11.02",
"index_uuid" : "ZU04EZDaS_eeqD0auI9o5Q"
},
"delete_date_in_millis" : 1541649663075
},
{
"index" : {
"index_name" : ".kibana",
"index_uuid" : "sZEoKhVlRRy7e8gAAnAEZw"
},
"delete_date_in_millis" : 1541653339359
},
{
"index" : {
"index_name" : "metricbeat-6.4.1-2018.11.06",
"index_uuid" : "T5UZFMHiRJSMsBjTw40ztA"
},
curl -XDELETE localhost:9200/*
删除内容重要:当我第一次执行它时,一切正常,但现在不起作用
注意:我是该主题的初学者 谢谢。
答案 0 :(得分:1)
使用文件输入调试Logstash管道时,我想用stdin
和stdout
简化它
input {
stdin {}
}
filter {
...your filter
}
output {
stdout { codec => rubydebug }
}
然后
cat mylogfile > logstash -f mypipeline.conf
目标是查看我们是否可以获取数据。如果是这样,则文件输入配置或Elasticsearch输出出现问题。弄乱每个,直到您找出哪个不起作用。另外,请确保您确实可以通过执行类似stat /path/to/your/file
通常,文件输入的问题是权限或sincedb,但听起来您已经能够消除两者。在这种情况下,我希望stdin
成功。