1. 从官网下载Logstash安装包解压
2. 在config目录下增加logstash.conf文件
input {
stdin { }
jdbc {
jdbc_driver_library => "mysql-connector-java-5.1.43.jar"
jdbc_driver_class => "com.mysql.jdbc.Driver"
jdbc_connection_string => "jdbc:mysql://192.168.6.27:3306/dbName"
jdbc_user => "root"
jdbc_password => "123456"
jdbc_paging_enabled => "true"
jdbc_page_size => "50000"
schedule => "* * * * *"
use_column_value => true
tracking_column => "update_time"
tracking_column_type => "timestamp"
statement => "select * from table_name where update_time >= :sql_last_value"
type => "dbName_table_name"
last_run_metadata_path => "../path/dbName_table_name.log"
}
}
output {
elasticsearch {
index => "%{type}"
document_id => "%{id}"
document_type => "%{type}" # <- use the type from each input
hosts => "localhost:9200"
}
stdout { codec => rubydebug }
}
3. bin目录下,安装插件logstash-input-jdbc,cmd执行如下命令
logstash-plugin prepare-offline-pack --overwrite --output logstash-input-jdbc-4.2.2.zip logstash-input-jdbc
logstash-plugin install file://D:/ProgramFiles/ELK/logstash-6.2.4/bin/logstash-input-jdbc-4.2.2.zip
注意:第一个命令行执行完后,会生成logstash-input-jdbc-4.2.2.zip,保存文件,后期如果需要使用,可以直接执行第二个命令安装插件
4. 将mysql-connector-java-5.1.43.jar放到目录bin中
5.最后
bin目录下,cmd运行 logstash -f ../config/logstash.conf
或者
config目录pipeline.xml中配置如下
- pipeline.id: esm_bsj_v4
path.config: "../config/logstash.conf"
bin目录下,cmd运行 logstash