Fluentd+Elasticsearch+Kibanaをインストールしてみる

VirtualBoxにCentOSをとりあえずインストール
の続き

CentOSにFluentd+Elasticsearch+Kibanaをインストールして、
Apacheのログを同じサーバー上で可視化して見れるようにしてみる。

準備

まずrootになる。

$ su -

ダウンロードに必要なので入れる。

# yum -y install curl wget unzip

Apacheのログを可視化するので、Apacheを入れる。

# yum -y install httpd
# service httpd start
# chkconfig httpd on

Elasticsearch

Elasticsearchをインストールする。

まず、javaが必要なのでインストールする。

# yum -y install java-1.7.0-openjdk

Elasticsearchをインストールする。
今回は最新の1.2.0をインストールする。

# wget https://download.elasticsearch.org/elasticsearch/elasticsearch/elasticsearch-1.2.0.noarch.rpm
# rpm -ivh elasticsearch-1.2.0.noarch.rpm

起動する。ついでに自動起動の設定もしておく。

# service elasticsearch start
# chkconfig elasticsearch on

Fluentd

次に、Fluentdをインストールする。

# curl -L http://toolbelt.treasuredata.com/sh/install-redhat.sh | sh

permissionを変えておかないと参照できないので変えておく。

# chmod 755 /var/log/httpd

fluent-plugin-elasticsearchをインストールする際に必要なので
インストールする。

# yum -y install gcc libcurl-devel
【参考】
CentOSに入れたtd-agentでfluent-plugin-elasticsearch (0.3.0)を入れようとしてハマった - zakki-cho
http://zakiblog.hatenablog.com/entry/2014/03/18/141631

fluent-plugin-elasticsearchをインストールする。

# /usr/lib64/fluent/ruby/bin/fluent-gem install fluent-plugin-elasticsearch

td-agent.confを書き換え、
ApacheのログをElasticsearchに記録するよう設定する。

# vi /etc/td-agent/td-agent.conf
<source>
  type tail
  path /var/log/httpd/access_log
  pos_file /var/log/td-agent/access_log.pos
  format apache2
  tag apache.access
</source>

<match apache.access>
  type elasticsearch
  host localhost
  port 9200
  type_name access_log
  logstash_format true
  flush_interval 3s
</match>

Fluentdを起動する。自動起動の設定もしておく。

# service td-agent start
# chkconfig td-agent on

Kibana

Kibanaをダウンロードして設置する。

# cd /var/www/html
# wget http://download.elasticsearch.org/kibana/kibana/kibana-latest.zip
# unzip kibana-latest.zip
# mv kibana-latest kibana

確認

http://サーバーのアドレス/kibana
にアクセスすると、

KibanaのTOPページが表示され、

Sample Dashboardをクリックすると、ダッシュボードが表示される。