1. 程式人生 > >windows安裝logstash-input-jdbc

windows安裝logstash-input-jdbc

1.安裝logstash

2.修改logstash 資料夾下Gemfile檔案

將source改為:https://gems.ruby-china.org

3.進入bin目錄

執行logstash-plugin install logstash-input-jdbc

出現如下資訊

Validating logstash-input-jdbc
Installing logstash-input-jdbc
Installation successful

表示安裝成功

4.在bin目錄中新建lib目錄,放入mysql-connector-java-5.1.30.jar包

5.在bin目錄中新建jdbc.sql檔案

加入如下內容

SELECT * from cas_user

6.修改logstash資料夾下config\logstash.conf檔案
改成如下配置:
input {
    stdin {
    }
    jdbc {
      # mysql jdbc connection string to our backup databse
      jdbc_connection_string => "jdbc:mysql://127.0.0.1:3306/exam"
      # the user we wish to excute our statement as
      jdbc_user => "root"
      jdbc_password => "123456"
      # the path to our downloaded jdbc driver
      jdbc_driver_library => "lib\mysql-connector-java-5.1.30.jar"
      # the name of the driver class for mysql
      jdbc_driver_class => "com.mysql.jdbc.Driver"
      jdbc_paging_enabled => "true"
      jdbc_page_size => "50000"
      statement_filepath => "jdbc.sql"
      schedule => "* * * * *"
      type => "jdbc"
    }
}
filter {
    json {
        source => "message"
        remove_field => ["message"]
    }
}
output {
    elasticsearch {
        hosts => ["127.0.0.1:9200"]
        index => "mysql01"
        document_id => "%{id}"
    }
    stdout {
        codec => json_lines
    }

}

7.進入bin目錄,執行如下命令

logstash.bat -f  ../config/logstash.conf

出現如下介面:

代表啟動成功,試著給對應表新增資料試試吧!