- What is Logstash? Logstash is a data collection engine with real-time
pipelining capabilities. You can use Logstash to collect your logs,
parse them into your desirable format and store them for searching or
monitoring for your application.
Step-1: Download latest version of
elastic search
Step-2: After downloading logstasch need to install jdbc plugin
bin/plugin install logstash-input-jdbc
Step-3: Download mysql-jdbc driver...as i downloaded and the file
name is mysql-connector-java-5.1.36.jar. put this file inside
logstash/drivers/mysql-connector-java-5.1.36.jar ....you can put it
anywhere you want. but remember the path.
Step-4: Now create a db.conf file and put it inside logstash
directory...in my case logstash-2.3.2/logstash-jdbc.conf here is the
content:
input { jdbc { jdbc_driver_library => "/opt/logstash-2.3.2/drivers/mysql-connector-java-5.1.36.jar" jdbc_driver_class => "com.mysql.jdbc.Driver" jdbc_connection_string => "jdbc:mysql://localhost/myapp_development" jdbc_user => "root" jdbc_password => "admin" parameters => { "user_list" => "users" } schedule => "* * * * *" statement => "select name,email from users" } } output { elasticsearch { index => "users" document_type => "users" document_id => "%{123}" hosts => "localhost:9200" } }
Jdbc Input Parameter Description
jdbc_driver_library Full path of jdbc library jdbc_driver_class JDBC
driver class to load, for MySQL it is com.mysql.jdbc.Driver
jdbc_connection_string JDBC mysql connection string jdbc_user MySQL
user jdbc_password MySQL user password schedule Run input statement
every minutes. Available scheduling option statement MySQL statement
parameters Parameter to pass in MySQL statement
Jdbc Output Parameters Description
Parameter Description
index Elasticsearch Index name
document_type Elasticsearch Index type.
document_id Id of elastic search doc
Step-5: Now set up is complete. we need to start logstart. before that start elasicsearch
then start logstsh and give it jadbc-db.conf file for configuration $
cd logstash-2.3.2 $ bin/logstash agent -f logstash-jdbc.conf
Now test your data quick in elastic search
http://localhost:9200/users/users/_search
Thank You Debs