Hello,World

我的logstash在使用logstash-input-jdbc插件时,一直再往ES中同步,无法结束。

Logstash | 作者 fishinhouse | 发布于2018年07月31日 | 阅读数:4627

我的mysql数据库中的数据没有多少,但是执行导入时不断的再把数据同步到ES中,我请求http://192.168.1.210:9200/sys_ ... Dtrue,返回结果显示,版本已经到27了:
"_index" : "sys_user_log",
"_type" : "sys_user_log",
"_id" : "76313",
"_version" : 27,
"found" : true,
。。。
ES安装完都是默认配置。
 
插件配置文件logstash-input-jdbc-mysql.conf
input{

stdin{
}

jdbc{

jdbc_connection_string => "jdbc:mysql://192.168.1.204:3306/xxx"
jdbc_user => "xxx"
jdbc_password => "xxx"
jdbc_driver_library => "/usr/elasticsearch/mysql-connector-java-5.1.44.jar"
jdbc_driver_class => "com.mysql.jdbc.Driver"
jdbc_paging_enabled => "true"
jdbc_page_size => "50000"
statement_filepath => "/usr/elasticsearch/logstash-6.3.2/sys_user_log.sql"
schedule => "* * * * *"
type => "jdbc"


}

}

output{
stdout{
codec => json_lines
}
elasticsearch{
hosts => "192.168.1.210:9200"
index => "sys_user_log"
document_type => "sys_user_log"
document_id => "%{id}"
}
}

 
已邀请:

fishinhouse

赞同来自:

问题找到了。
原因是SQL逻辑和定时逻辑。
SQL逻辑是:select * from sys_user_log
把表中的全部数据实时同步到ES,没有标记记录已经同步的位置,这样同步完全部数据后,定是逻辑继续触发同步全部数据。
这样就造成一开始执行时遇到的不断同步停不下来的现象。
 
在网上找了一个解决方案,引入配置选项:
jdbc{
    statement => "SELECT * from app_stat where update_date > :sql_last_value"
    tracking_column => "update_date"
    use_column_value => false
}
说明:
:sql_last_value 用于记录上一次同步的时间,每次执行 都会更新。
use_column_value 如果设置true 每次运行的时间 sql_last_value 值不会变化 。
 
这个方案要求,我们在设计表时提前定义一个时间戳字段,同步时根据这个时间戳进行增量同步数据。

 

qw8613243

赞同来自:

为什么不监控mysql.log日志 同步数据呢

要回复问题请先登录注册