天天看點

Logstash學習19_CentOS下Logstash Sqlite input plugin 插件的使用

在安裝完成Logstash、Sqlite3和Sqlite input plugin 插件後,可以進一步操作。

1、建立一個SQlite資料庫檔案

建立一個example.db檔案;

編輯此檔案,/home/bigdata/data/example.db是檔案的全路徑:

sqlite3 /home/example.db;

建立一張表:

CREATE TABLE weblogs (id INTEGER PRIMARY KEY AUTOINCREMENT,ip STRING,request STRING,response INTEGER);

在表内插入資料:

INSERT INTO weblogs (ip, request, response) VALUES ("1.2.3.4", "/index.html", 200);

此時,查找表内資料,發現已經有結果了:

select * from weblogs;

2、配置Logstash參數

在Logstash的conf檔案夾下,建立一個sqlite.conf 檔案,其内容為:

input {

  sqlite {

    path => "/home/bigdata/data/example.db"

    type => weblogs

  }

}

output {

  stdout {

    codec => rubydebug

  }

}

3、啟動Logstash,其執行結果如下:

[[email protected] conf]$ ../bin/logstash -f sqlite.conf 

Logstash startup completed

{

          "host" => "master",

            "db" => #<Sequel::JDBC::Database: "jdbc:sqlite:/home/bigdata/data/example.db">,

      "@version" => "1",

    "@timestamp" => "2017-10-26T12:24:43.556Z",

          "type" => "weblogs",

            "ip" => "1.2.3.4",

       "request" => "/index.html",

      "response" => 200

}

參考:https://www.elastic.co/guide/en/logstash/current/plugins-inputs-sqlite.html