12
10

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

ubuntuにLogstashを入れる

Posted at

Elasticsearch、kibanaときて、次はLogstashを入れます

環境

  • VirtualBox 4.3
  • ubuntu 14.04
  • java8(1.8.0_25)
  • logstash(1.4.2)

logstashのインストール

$ cd 
$ wget https://download.elasticsearch.org/logstash/logstash/logstash-1.4.2.tar.gz
$ sudo mv logstash-1.4.2.tar.gz /usr/local/
$ cd /usr/local
$ sudo tar zxvf logstash-1.4.2.tar.gz
$ sudo ln -s logstash-1.4.2 logstash

※最新版はhttp://logstash.net/

起動と動作確認

以下のようなApacheログを用意しました

access.log
[ip] - - [27/Apr/2015:01:05:10 +0900] "GET [url]" "Mozilla/5.0 (iPhone; CPU iPhone OS 8_3 like Mac OS X) AppleWebKit/600.1.4 (KHTML, like Gecko) Mobile/12F70"

※ip,urlは伏せてあります

設定ファイル作成

test.conf
$ cd /usr/local/logstash
$ sudo mkdir conf
$ cd conf
$ sudo vim test.conf
-----
input { stdin {} }

filter {
  grok {
    match => { "message" => "%{COMBINEDAPACHELOG}" }
    break_on_match => false
    tag_on_failure => ["parse_failure"]
  }
  date {
    match => [ "timestamp" , "dd/MMM/yyyy:HH:mm:ss Z" ]
    locale => "en"
  }
}
                                         
output {
  stdout { codec => rubydebug }
}
-----

起動と動作確認

$ /usr/local/logstash/bin/logstash -f /usr/local/logstash/conf/test.conf
標準入力になるので、ここに上記ログを貼り付けます
[ip] - - [27/Apr/2015:01:05:10 +0900] "GET [url]" "Mozilla/5.0 (iPhone; CPU iPhone OS 8_3 like Mac OS X) AppleWebKit/600.1.4 (KHTML, like Gecko) Mobile/12F70"
Enterで実行

{
        "message" => "[ip] - - [27/Apr/2015:01:04:24 +0900] \"GET [url]" 200 1375 \"-\" \"Mozilla/5.0 (iPhone; CPU iPhone OS 8_3 like Mac OS X) AppleWebKit/600.1.4 (KHTML, like Gecko) Mobile/12F70\"",
       "@version" => "1",
     "@timestamp" => "2015-04-26T16:04:24.000Z",
           "host" => "[host]",
       "clientip" => "[ip]",
          "ident" => "[ident]",
           "auth" => "[auth]",
      "timestamp" => "27/Apr/2015:01:04:24 +0900",
           "verb" => "GET",
        "request" => "[url]",
    "httpversion" => "1.1",
       "response" => "200",
          "bytes" => "1375",
       "referrer" => "[referrer]",
          "agent" => "\"Mozilla/5.0 (iPhone; CPU iPhone OS 8_3 like Mac OS X) AppleWebKit/600.1.4 (KHTML, like Gecko) Mobile/12F70\""
}

パースされました。

設定ファイルの内容

設定 説明
input 入力ログのパス等を記載する。今回は標準入力
filter 入力ログに対して設定するフィルタを記述する
grok 非定型なログを処理する設定
match 入力されたログをマッチングさせる。今回はCOMBINEDAPACHELOG形式でマッチング
date 時間パース設定
output パース結果の出力先。今回は標準出力
12
10
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
12
10

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?