Windows環境安裝Logstash和Logstash-input-jdbc

本文爲Windows環境下的相關安裝示例,適用於須要用Logstash和Logstash-input-jdbc將數據從數據庫導入到Elasticsearch中的場景。

安裝步驟

0. 安裝JDK 8及Elasticsearch

安裝JDK8並配置JAVA_HOME環境變量;
安裝Elasticsearch並啓動;java

1. 安裝Logstash

1.1 下載與你的Elasticsearch版本對應的Logstash版本

Logstash官方下載地址mysql

1.2 解壓到本地路徑

如: 「D:Serverlogstash-6.8.0」git

1.3 啓動與驗證

打開CMD命令行,切換到logstash安裝路徑下的bin目錄,執行:github

logstash -e "input { stdin { } } output { stdout {} }"

正常能夠看到如圖打印啓動成功的信息。sql

clipboard.png

能夠輸入測試內容,如「hello world」 進一步驗證。數據庫

2. 安裝Logstash-input-jdbc插件

CMD命令行切換到bin目錄,執行如下命令安裝Logstash-input-jdbc插件:json

logstash-plugin install logstash-input-jdbc

clipboard.png
安裝正常將打印成功信息。框架

3. 驗證Logstash-input-jdbc

3.1 以MySQL爲例,下載驅動jar到本地目錄(此處以logstash-6.8.0/test路徑爲例)

3.2 寫測試的conf文件(如 test.conf)

input {
  stdin {
  }
  jdbc {
  jdbc_connection_string => "jdbc:mysql://localhost:3306/example"
  jdbc_user => "dbuser"
  jdbc_password => "123456"
  jdbc_driver_library => "../test/mysql-connector-java-5.1.47.jar"
  jdbc_driver_class => "com.mysql.jdbc.Driver"
  statement => "SELECT * FROM user"
  type => "test"
  }
}
output {
  elasticsearch {
    hosts => "localhost:9200"
    index => "world"
    document_id => "%{id}"
  }
  stdout {
    codec => json_lines
  }
}

3.3 運行測試conf

logstash -f ../test/test.conf

你將會看到JDBC的查詢結果信息
clipboard.pngelasticsearch


diboot 簡單高效的輕代碼開發框架測試

相關文章
相關標籤/搜索