题记
一次同步多张表是开发中的一般需求。之前研究了很久找到方法,但没有详细总结。
博友前天在线提问,说明这块理解的还不够透彻。
我整理下,
一是为了尽快解决博友问题,
二是加深记忆,便于未来产品开发中快速上手。
1、同步原理
原有ES专栏中有详解,不再赘述。详细请参考我的专栏:
深入详解Elasticsearch
以下是通过ES5.4.0, logstash5.4.1 验证成功。
可以确认的是2.X版本同样可以验证成功。
2、核心配置文件
input {
stdin {
}
jdbc {
type => "cxx_article_info"
# mysql jdbc connection string to our backup databse 后面的test对应mysql中的test数据库
jdbc_connection_string => "jdbc:mysql://110.10.15.37:3306/cxxwb"
# the user we wish to excute our statement as
jdbc_user => "root"
jdbc_password => "xxxxx"
record_last_run => "true"
use_column_value => "true"
tracking_column => "id"
last_run_metadata_path => "/opt/logstash/bin/logstash_xxy/cxx_info"
clean_run => "false"
# the path to our downloaded jdbc driver
jdbc_driver_library => "/opt/elasticsearch/lib/mysql-connector-java-5.1.38.jar"
# the name of the driver class for mysql
jdbc_driver_class => "com.mysql.jdbc.Driver"
jdbc_paging_enabled => "true"
jdbc_page_size => "500"
statement => "select * from cxx_article_info where id > :sql_last_value"