利用 Logstash-input-jdbc同步sqlserver數據到elasticsearch

這裏我演示的是在windows下的操做sql

首先下載logstash-5.6.1,直接去官網自行下載json

1.須要建立以下jdbc.conf和myes.sql兩個文件windows

input {
    stdin {
    }
    jdbc {
     jdbc_driver_library => "D:\jdbcconfig\sqljdbc4-4.0.jar"
            jdbc_driver_class => "com.microsoft.sqlserver.jdbc.SQLServerDriver"
            jdbc_connection_string => "jdbc:sqlserver://127.0.0.1:1433;DatabaseName=abtest"
            jdbc_user => "sa"
            jdbc_password => "123456"
                        # schedule => 分 時 天 月 年  
                        # 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 => lastedittime record_last_run => true last_run_metadata_path => "D:\jdbcconfig\data\station_parameter.txt"
#設置列名小寫 lowercase_column_names => true statement_filepath => "/jdbcconfig/myes.sql" #索引的類型 type => "test" } } filter { json { source => "message" remove_field => ["message"] } } output { elasticsearch { hosts => ["172.16.57.233:9200"] action => "index" #索引 index => "test" document_id => "%{productid}" } stdout { #codec => json_lines
#設置輸出的格式 codec
=> line { format => "productid: %{[productid]} isdeleted: %{[isdeleted]} lastedittime: %{[lastedittime]} " } } }
必定要注意配置的路徑是否正確,否者執行會報錯

myes.sql是裏面你須要執行查詢的SQL語句elasticsearch


SELECT *
FROM [dbo].testsqlserver

首先要啓動elasticsearch,spa

 

而後在logstash的bin目錄下執行以下命令:logstash -f jdbcconfig/jdbc.conf3d

數據就開始同步了。。。。code

相關文章
相關標籤/搜索