LoginSignup
4
3

More than 5 years have passed since last update.

Cygwinにfluentd, Elasticsearch, Kibanaをインストールして動かす

Last updated at Posted at 2014-08-03

Cygwinにfluentd, Elasticsearch, Kibanaをインストールして、httpdのログを見るまでのメモ。

環境

  • Windows 7 64bit
  • Cygwin 1.7.30-1 (64bit版)
  • Ruby 1.9.1 (Cygwin)

前提

  • Cygwinで以下のパッケージがインストール済み
    • make
    • wget
    • tar
    • libcrypt-devel
    • libcurl-devel
    • gcc-core
    • gcc-g++
    • apache2(Kibanaアクセス用)
      • httpd.confは初期設定のまま(Windowsサービス上でcygserverが動いており、localhost:80からアクセスできる)

手順

  1. Elasticsearch, Kibanaをダウンロードして配置

    # http://www.elasticsearch.org/overview/elkdownloads/の最新版をダウンロード
    wget https://download.elasticsearch.org/elasticsearch/elasticsearch/elasticsearch-1.3.1.tar.gz
    tar zxvf elasticsearch-1.3.1.tar.gz
    # /opt以下に配置
    mv elasticsearch-1.3.1 /opt/elasticsearch
    
    # http://www.elasticsearch.org/overview/elkdownloads/の最新版をダウンロード
    wget https://download.elasticsearch.org/kibana/kibana/kibana-3.1.0.tar.gz
    tar zxvf kibana-3.1.0.tar.gz
    # /opt以下に配置
    mv kibana-3.1.0 /opt/kibana
    
  2. fluentd, fluent-plugin-elasticsearchのインストール

    gem install fluentd --no-ri --no-rdoc
    gem install fluent-plugin-elasticsearch
    
  3. httpd.confのDocumentRootを/opt/kibanaにする(httpdでKibanaにアクセスするため)

  4. fluent.confの設定(httpdのログをElasticsearchに送る)

    <source>
      type tail
      format /^(?<host>[^ ]*) [^ ]* (?<user>[^ ]*) \[(?<time>[^\]]*)\] "(?<method>\S+)(?: +(?<path>[^ ]*) +\S*)?" (?<code>[^ ]*) (?<size>[^ ]*)(?: "(?<referer>[^\"]*)" "(?<agent>[^\"]*)" (?<received_byte>[^ ]*) (?<sent_byte>[^ ]*) (?<response_time_micro_sec>[^ ]*))?$/
      time_format %d/%b/%Y:%H:%M:%S %z
      path /var/log/apache2/access_log
      pos_file /var/log/fluentd/buffer/httplog.pos
      tag httplog
    </source>
    
    <match httplog>
      type elasticsearch
      host localhost
      port 9200
      type_name httplog
      logstash_format true
    </match>
    
  5. elasticsearchを立ち上げ、fluentdを実行

    # localhost:9200でelasticsearchが立ち上がる
    /opt/elasticsearch/bin/elasticsearch
    # 前のステップで作成したfluent.confを使用する
    fluentd -c fluent.conf
    
  6. ブラウザでlocalhost(Kibana)にアクセスし、ログが表示されることを確認する

    • Logstash Dashboardに移動し、"EVENTS OVER TIME"のグラフを確認
    • 今回の設定では、localhost自身へのアクセスログがelasticsearchに転送され、kibanaに表示される

備考

  • 上記手順は、自分でいくつかはまったものを最終的に整理したものなので、同等の環境でうまくいかなかったらご指摘ください。
  • fluentdのインストールは苦労しました。実際は以下の手順をたどっています(cygwinのパッケージインストールにはapt-cygを使用)。
    1. "gem install fluentd --no-ri --no-rdoc"を実行するも、msgpackの部分でエラーになる
    2. 一応"gem install msgpack"を実行するもやはりエラー
    3. msgpackのmkmf.log(自分の環境では/usr/lib/ruby/gems/1.9.1/gems/msgpack-0.5.8/ext/msgpack/mkmf.log)を確認すると、"/usr/bin/ld: cannot find -lcrypt"というメッセージがあった
    4. "apt-cyg install libcrypt-devel"実行でlcryptを解決
    5. 次に"gem install msgpack"を実行すると"sh: make: command not found"とエラー
    6. "apt-cyg install make"でmakeインストール
    7. "gem install msgpack"で今度こそ成功。
    8. 改めて"gem install fluentd --no-ri --no-rdoc"実行して成功
  • 当初、fluentdはWindows側に直接インストールしようとしました。fluentd, fluent-plugin-elasticsearchまでインストールしたものの、fluentdを動かしたら"runtime error!"とか出たので早々と諦めました。一応インストールまでの手順を書いておきます。
    1. rubyのdevkitをダウンロードして、"ruby dk.rb init", "ruby dk.rb install" 実行
    2. cool.ioをgithubからzipダウンロード
    3. 2を解凍し、"gem install cool.io"
    4. githubからfluentdのwindowsブランチのソースコードをzipダウンロード
    5. 4を解凍し、"gem install fluentd-0.10.46.gem"でインストール
    6. Win版libcurlをダウンロードし、C:\curl-7.21.0-devel-mingw32に配置
    7. PATHにC:\curl-7.21.0-devel-mingw32\binを追加
    8. "gem install fluent-plugin-elasticsearch -- --with-curl-lib=C:\curl-7.21.0-devel-mingw32\bin --with-curl-include=C:\curl-7.21.0-devel-mingw32\include"実行

参考にしたページ

4
3
0

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
4
3