Ad Code

Responsive Advertisement

Ticker

6/recent/ticker-posts

Use Logstash-input-jdbc to synchronize sqlserver data to elasticsearch

1. Installation and download mssql-jdbc-6.2.2.jre8.jar

bin/plugin install logstash-input-jdbc
go to Microsoft web site download mssql jdbc  , and then unzip gz file to /opt/logstash

2. Configuration

input {
    stdin {
    }
    jdbc {
     jdbc_driver_library => "/opt/logstash/sqljdbc_6.2/enu/mssql-jdbc-6.2.2.jre8.jar"
            jdbc_driver_class => "com.microsoft.sqlserver.jdbc.SQLServerDriver"
            jdbc_connection_string => "jdbc:sqlserver://127.0.0.1:1433;DatabaseName=test"
            jdbc_user => "sa"
            jdbc_password => "123456"
            # schedule => m H D M Y  
            # schedule => * 22  *  *  *     //will execute at 22:00 every day
            schedule => "* * * * *"
            jdbc_paging_enabled => true
            jdbc_page_size => 1000
            clean_run => false
            use_column_value => true            #設定查詢條件的欄位
            tracking_column => pk_id
            record_last_run => true
            last_run_metadata_path => "/opt/data/station_parameter.log"            #設定列名小寫
            lowercase_column_names => true
            statement_filepath => "/jdbcconfig/statement.sql"
            #索引的型別
            type => "jdbc"
    }
}

filter {
    json {
        source => "message"
        remove_field => ["message"]
    }
}

output {
    elasticsearch {
         hosts => ["elasticsearch:9200"]
        action => "index" 
        #set index name
        index => "test"
        document_id => "%{pk_id}"
    }
    stdout {
        #codec => json_lines
        #set output format
        codec => line {
            format => "pk_id: %{[pk_id]} name: %{[name]} lastedittime: %{[lastedittime]} " 
        }
    }
}
Run Test


bin/logstash -f config/jdbc.conf


Reference : logstash-input-jdbc同步mysql數據到elasticsearch
Reference : 利用 Logstash-input-jdbc同步sqlserver資料到elasticsearch
Reference : Logstash JDBC Input Plugin