logstash.config:
> input {
> jdbc {
> jdbc_connection_string => "jdbc:mysql://localhost:3306/db_name?ssl=false"
> jdbc_user => "admin"
> jdbc_password => "password"
> jdbc_driver_library => "D:/elk/mysql-connector-java-5.1.47.jar"
> jdbc_driver_class => "com.mysql.jdbc.Driver"
> statement => "SELECT * FROM Users"
> use_column_value => true
> tracking_column => id
> tracking_column_type => "numeric"
>
> }
> }
> output {
> stdout { codec => json_lines }
> elasticsearch {
> "hosts" =>"localhost:9200"
> "index" => "xyz"
> "document_type" => "data"
>
> }
>
> }
Output:
D:\elk\logstash-5.6.3\bin>logstash -f logstash-config.conf
Sending Logstash's logs to D:/elk/logstash-5.6.3/logs which is now configured via log4j2.properties
[2020-06-27T10:54:04,431][INFO ][logstash.modules.scaffold] Initializing module {:module_name=>"fb_apache", :directory=>"D:/elk/logstash-5.6.3/modules/fb_apache/configuration"}
[2020-06-27T10:54:04,436][INFO ][logstash.modules.scaffold] Initializing module {:module_name=>"netflow", :directory=>"D:/elk/logstash-5.6.3/modules/netflow/configuration"}
[2020-06-27T10:54:05,415][INFO ][logstash.outputs.elasticsearch] Elasticsearch pool URLs updated {:changes=>{:removed=>, :added=>[http://localhost:9200/]}}
[2020-06-27T10:54:05,418][INFO ][logstash.outputs.elasticsearch] Running health check to see if an Elasticsearch connection is working {:healthcheck_url=>http://localhost:9200/, :path=>"/"}
[2020-06-27T10:54:05,564][WARN ][logstash.outputs.elasticsearch] Restored connection to ES instance {:url=>"http://localhost:9200/"}
[2020-06-27T10:54:05,613][INFO ][logstash.outputs.elasticsearch] Using mapping template from {:path=>nil}
[2020-06-27T10:54:05,618][INFO ][logstash.outputs.elasticsearch] Attempting to install template {:manage_template=>{"template"=>"logstash-", "version"=>50001, "settings"=>{"index.refresh_interval"=>"5s"}, "mappings"=>{"default"=>{"_all"=>{"enabled"=>true, "norms"=>false}, "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", "include_in_all"=>false}, "@version"=>{"type"=>"keyword", "include_in_all"=>false}, "geoip"=>{"dynamic"=>true, "properties"=>{"ip"=>{"type"=>"ip"}, "location"=>{"type"=>"geo_point"}, "latitude"=>{"type"=>"half_float"}, "longitude"=>{"type"=>"half_float"}}}}}}}}
[2020-06-27T10:54:05,625][INFO ][logstash.outputs.elasticsearch] New Elasticsearch output {:class=>"LogStash::Outputs::ElasticSearch", :hosts=>["//localhost:9200"]}
[2020-06-27T10:54:05,632][INFO ][logstash.pipeline ] Starting pipeline {"id"=>"main", "pipeline.workers"=>4, "pipeline.batch.size"=>125, "pipeline.batch.delay"=>5, "pipeline.max_inflight"=>500}
[2020-06-27T10:54:05,923][INFO ][logstash.pipeline ] Pipeline main started
[2020-06-27T10:54:06,079][INFO ][logstash.agent ] Successfully started Logstash API endpoint {:port=>9600}
[2020-06-27T10:54:49,378][ERROR][logstash.inputs.jdbc ] Unable to connect to database. Tried 1 times {:error_message=>"Java::ComMysqlJdbcExceptionsJdbc4::CommunicationsException: Communications link failure\n\nThe last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server."}
[2020-06-27T10:54:49,384][WARN ][logstash.inputs.jdbc ] Exception when executing JDBC query {:exception=>#<Sequel::DatabaseConnectionError: Java::ComMysqlJdbcExceptionsJdbc4::CommunicationsException: Communications link failure
The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.>}
[2020-06-27T10:54:49,387][WARN ][logstash.inputs.jdbc ] Attempt reconnection.
[2020-06-27T10:54:57,876][WARN ][logstash.runner ] SIGINT received. Shutting down the agent.
[2020-06-27T10:54:57,906][WARN ][logstash.agent ] stopping pipeline {:id=>"main"}
[2020-06-27T10:54:58,241][FATAL][logstash.runner ] SIGINT received. Terminating immediately..
Terminate batch job (Y/N)?
^C
D:\elk\logstash-5.6.3\bin>