美文网首页
logstash 配置

logstash 配置

作者: 良人与我 | 来源:发表于2019-03-22 16:33 被阅读0次

下载 logstash
https://www.elastic.co/downloads/past-releases/logstash-6-3-2

需要配置好 java 的环境变量
验证 Logstash

[river@localhost bin]$ pwd
/soft/logstash-6.3.2/bin
[river@localhost bin]$ ./logstash -e 'input { stdin { } } output { stdout {} }'
Sending Logstash's logs to /soft/logstash-6.3.2/logs which is now configured via log4j2.properties
[2019-03-22T01:00:08,520][WARN ][logstash.config.source.multilocal] Ignoring the 'pipelines.yml' file because modules or command line options are specified
[2019-03-22T01:00:08,934][INFO ][logstash.runner          ] Starting Logstash {"logstash.version"=>"6.3.2"}
[2019-03-22T01:00:10,281][INFO ][logstash.pipeline        ] Starting pipeline {:pipeline_id=>"main", "pipeline.workers"=>2, "pipeline.batch.size"=>125, "pipeline.batch.delay"=>50}
The stdin plugin is now waiting for input:
[2019-03-22T01:00:10,360][INFO ][logstash.pipeline        ] Pipeline started successfully {:pipeline_id=>"main", :thread=>"#<Thread:0x45e95705 sleep>"}
[2019-03-22T01:00:10,399][INFO ][logstash.agent           ] Pipelines running {:count=>1, :running_pipelines=>[:main], :non_running_pipelines=>[]}
[2019-03-22T01:00:10,534][INFO ][logstash.agent           ] Successfully started Logstash API endpoint {:port=>9600}

看到已经成功start 了。
输入字符测试下

hello world
{
      "@version" => "1",
          "host" => "localhost.localdomain",
       "message" => "hello world",
    "@timestamp" => 2019-03-21T17:01:59.662Z
}

读取文件 并输出的文件
配置文件 simple.conf 如下

input {
  file {
    type => "messagelog"  
    path => "/home/river/Documents/messages"
    start_position => "beginning"       
    }
}

output {
  file {
    path => "/home/river/Documents/%{type}.%{+YYYY.MM.dd}"  
  }
}

执行命令
./bin/logstash -f config/simple.conf
结果

[river@localhost Documents]$ echo "hello world" >> /home/river/Documents/messages
[river@localhost Documents]$ cat /home/river/Documents/messagelog.2019.03.21 
{"type":"messagelog","@timestamp":"2019-03-21T18:56:11.725Z","host":"localhost.localdomain","message":"hello world","@version":"1","path":"/home/river/Documents/messages"}

保存到 elasticsearch 里面

output {
   elasticsearch { hosts => ["192.168.130.105:9200"] }
}

如果想同时输出到控制台 out put 里添加: stdout { codec => rubydebug }

output {
  elasticsearch { hosts => ["192.168.130.105:9200"] } 
  stdout { codec => rubydebug } 
}

启动并向文件里写入数据

[river@localhost logstash-6.3.2]$ ./bin/logstash -f config/simple.conf
Sending Logstash's logs to /soft/logstash-6.3.2/logs which is now configured via log4j2.properties
[2019-03-22T18:54:09,843][WARN ][logstash.config.source.multilocal] Ignoring the 'pipelines.yml' file because modules or command line options are specified
[2019-03-22T18:54:10,259][INFO ][logstash.runner          ] Starting Logstash {"logstash.version"=>"6.3.2"}
[2019-03-22T18:54:12,298][INFO ][logstash.pipeline        ] Starting pipeline {:pipeline_id=>"main", "pipeline.workers"=>2, "pipeline.batch.size"=>125, "pipeline.batch.delay"=>50}
[2019-03-22T18:54:12,726][INFO ][logstash.outputs.elasticsearch] Elasticsearch pool URLs updated {:changes=>{:removed=>[], :added=>[http://192.168.130.105:9200/]}}
[2019-03-22T18:54:12,733][INFO ][logstash.outputs.elasticsearch] Running health check to see if an Elasticsearch connection is working {:healthcheck_url=>http://192.168.130.105:9200/, :path=>"/"}
[2019-03-22T18:54:12,873][WARN ][logstash.outputs.elasticsearch] Restored connection to ES instance {:url=>"http://192.168.130.105:9200/"}
[2019-03-22T18:54:12,911][INFO ][logstash.outputs.elasticsearch] ES Output version determined {:es_version=>6}
[2019-03-22T18:54:12,913][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}
[2019-03-22T18:54:12,940][INFO ][logstash.outputs.elasticsearch] New Elasticsearch output {:class=>"LogStash::Outputs::ElasticSearch", :hosts=>["//192.168.130.105:9200"]}
[2019-03-22T18:54:12,960][INFO ][logstash.outputs.elasticsearch] Using mapping template from {:path=>nil}
[2019-03-22T18:54:12,969][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"}}}}}}}}
[2019-03-22T18:54:13,200][INFO ][logstash.pipeline        ] Pipeline started successfully {:pipeline_id=>"main", :thread=>"#<Thread:0x51a7cf04 run>"}
[2019-03-22T18:54:13,258][INFO ][logstash.agent           ] Pipelines running {:count=>1, :running_pipelines=>[:main], :non_running_pipelines=>[]}
[2019-03-22T18:54:13,582][INFO ][logstash.agent           ] Successfully started Logstash API endpoint {:port=>9600}
{
      "@version" => "1",
       "message" => "have a  good day",
    "@timestamp" => 2019-03-22T10:54:16.530Z,
          "host" => "localhost.localdomain",
          "path" => "/home/river/Documents/messages",
          "type" => "messagelog"
}

看到已经在控制台输出了 写入的内容
那es中呢


image.png

通过 kibana 查看 图表


相关文章

网友评论

      本文标题:logstash 配置

      本文链接:https://www.haomeiwen.com/subject/pdecvqtx.html