1

我在输入的jdbc插件中有这样的 MySQL 语句。logstash

statement => "SELECT * from TEST where id > :sql_last_value"

我的表没有任何datedatetime这样的字段。因此,我试图通过使用 a 逐分钟检查scheduler是否有任何新行已添加到表中来更新索引。

我应该只能更新新记录,而不是从现有记录更新现有值更改。所以要做到这一点,我有这样的logstash输入:

input {
    jdbc {
        jdbc_connection_string => "jdbc:mysql://myhostmachine:3306/mydb" 
        jdbc_user => "root"
        jdbc_password => "root"
        jdbc_validate_connection => true
        jdbc_driver_library => "/mypath/mysql-connector-java-5.1.39-bin.jar"
        jdbc_driver_class => "com.mysql.jdbc.Driver"
        jdbc_paging_enabled => "true"
        jdbc_page_size => "50000"
        schedule => "* * * * *"
        statement => "SELECT * from mytable where id > :sql_last_value"
        use_column_value => true
        tracking_column => id
        last_run_metadata_path => "/path/.logstash_jdbc_last_run"
        clean_run => true
    }
}

因此,每当我创建索引并运行此logstash文件以上传文档时,它根本不会被上传。文档计数显示为零。我确保.logstash_jdbc_last_run在运行 conf 文件之前删除了logstashconf 文件。

logstash 控制台输出的一部分:

[2016-11-02T16:33:00,294][INFO][logstash.inputs.jdbc] (0.002000s) SELECT count(*) AS countFROM (SELECT * from TEST where id > '2016-11-02 11:02: 00') 作为t1限制 1

并且通过一分钟一分钟地检查这是正确的但它没有得到记录来继续进行。它是如何工作的?

我错过了什么吗?任何帮助都将不胜感激。

4

1 回答 1

5

您需要像这样修改您的 logstash 配置:

jdbc { 
  jdbc_connection_string => "jdbc:mysql://myhostmachine:3306/mydb" 
  jdbc_user => "root" 
  jdbc_password => "root" 
  jdbc_validate_connection => true 
  jdbc_driver_library => "/mypath/mysql-connector-java-5.1.39-bin.jar" 
  jdbc_driver_class => "com.mysql.jdbc.Driver" 
  jdbc_paging_enabled => "true" 
  jdbc_page_size => "50000" 
  schedule => "* * * * *" 
  statement => "SELECT * from TEST where id > :sql_last_value" 
  use_column_value => true 
  tracking_column => "id" 
  tracking_column_type => "numeric" 
  clean_run => true 
  last_run_metadata_path => "/mypath/.logstash_jdbc_last_run" 
}

最后五个设置对您的情况很重要。.logstash_jdbc_last_run即使这样做,也要确保删除该文件clean_run => true

于 2016-11-02T16:41:40.177 回答