我正在使用logstash jdbc来保持mysql和elasticsearch之间的同步。一张桌子工作正常。但是现在我想对多个表执行此操作。我需要在终端中打开多个
logstash agent -f /Users/logstash/logstash-jdbc.conf
每个查询都有一个选择查询,或者我们有更好的方法来进行查询,因此可以更新多个表。
我的配置文件
input { jdbc { jdbc_driver_library => "/Users/logstash/mysql-connector-java-5.1.39-bin.jar" jdbc_driver_class => "com.mysql.jdbc.Driver" jdbc_connection_string => "jdbc:mysql://localhost:3306/database_name" jdbc_user => "root" jdbc_password => "password" schedule => "* * * * *" statement => "select * from table1" } } output { elasticsearch { index => "testdb" document_type => "table1" document_id => "%{table_id}" hosts => "localhost:9200" } }
你绝对可以有多个单配置jdbc输入,然后参数化的index,并document_type在你的elasticsearch输出,这取决于表中的事件的来源。
jdbc
index
document_type
elasticsearch
input { jdbc { jdbc_driver_library => "/Users/logstash/mysql-connector-java-5.1.39-bin.jar" jdbc_driver_class => "com.mysql.jdbc.Driver" jdbc_connection_string => "jdbc:mysql://localhost:3306/database_name" jdbc_user => "root" jdbc_password => "password" schedule => "* * * * *" statement => "select * from table1" type => "table1" } jdbc { jdbc_driver_library => "/Users/logstash/mysql-connector-java-5.1.39-bin.jar" jdbc_driver_class => "com.mysql.jdbc.Driver" jdbc_connection_string => "jdbc:mysql://localhost:3306/database_name" jdbc_user => "root" jdbc_password => "password" schedule => "* * * * *" statement => "select * from table2" type => "table2" } # add more jdbc inputs to suit your needs } output { elasticsearch { index => "testdb" document_type => "%{type}" # <- use the type from each input hosts => "localhost:9200" } }