LoginSignup
25
26

More than 5 years have passed since last update.

fluentd + Elasticsearch + Kibanaでデータ集計サーバを作る

Posted at

色んなログにも使えて、いい感じに整形してくれて
解析もしやすいです。使いこなせてるかどうかは謎

fluentd...ログを集計してく便利なやつ
Elasticsearch...サーチエンジン。fluentdで収集したログをいい感じに加工してくれるやつ
kibana...集計・加工をナイスに見る事が出来て、色々な検索もできる凄いやつ

Elasticsearchインストール

■公式サイト
http://www.elasticsearch.org/overview/elkdownloads/

今回はRPM版からインストールします

wget https://download.elasticsearch.org/elasticsearch/elasticsearch/elasticsearch-1.2.1.noarch.rpm

rpm -ivh elasticsearch-1.2.1.noarch.rpm

chkconfig --add elasticsearch

javaをoracleからインストール
ちなみにyumで入るバージョンだとうまく動かないので手動で入れる

■javaサイト(「java インストール」でぐぐれば出てくる)

rpm版をインストール

rpm -ivh jdk-8u5-linux-x64.rpm

設定ファイル変更

とりあえず一台構成なので最低限の設定を入れる

/etc/elasticsearch/elasticsearch.yml
index.number_of_shards: 1
index.number_of_replicas: 0
path.data: /data
path.logs: /var/log/elasticsearch/logs

対象のディレクトリを作成して権限付与

mkdir -p elasticsearch:elasticsearch /data/elasticsearch
chown -R elasticsearch:elasticsearch /data

サービス起動

/etc/init.d/elasticsearch start
elasticsearch を起動中:                                    [  OK  ]

これでとりあえずElasticsearchの準備は終了

またrpmでインストールしたjavaは大丈夫だろうけど
ソースからインストールしたり、複数のjavaが動いている時等
ほうっておくとyum updateでJAVA_HOMEが勝手に書き換わったり
コマンドのPATHが巻き戻ったりと色々不具合が出るので対象外にしておく

/etc/yum.conf

execlude=java*

kibanaインストール

kibanaダウンロードサイト
http://www.elasticsearch.org/overview/kibana/installation/

wgetでもってきて配置

wget https://download.elasticsearch.org/kibana/kibana/kibana-3.1.0.tar.gz

tar xvfz kibana-3.1.0.tar.gz

mv kibana-3.1.0 /opt/kibana

Fluentdインストール

rpm版をインストール

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

インストールの前に

fluentdの公式ではOSのカーネルを変更するのが推奨されているようなので設定変更
http://docs.fluentd.org/ja/articles/before-install

ntpdをインストール

yum install ntpd
chkconfig ntpd on

ファイルディスクリプタの最大値を増やす

/etc/security/limits.conf

root soft nofile 65536
root hard nofile 65536
* soft nofile 65536
* hard nofile 65536

ネットワーク関係のカーネルパラメータの最適化

/etc/sysctl.conf
net.ipv4.tcp_tw_recycle = 1
net.ipv4.tcp_tw_reuse = 1
net.ipv4.ip_local_port_range = 10240    65535

全部終わったらreboot

Fluentd-agentインストール

今回はログ集計サーバとは別にリモートから送りたいので別サーバにagentとしてインストールします。
上記で記述しているFluentdインストール部分は全て終わらせます。

Elasticsearchプラグインをインストール

rpmでインストールしたfluetndはrubyも内包されているので
内包されたrubyに対してgem installを行う

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

エラー

ERROR:  Error installing fluent-plugin-elasticsearch:
    ERROR: Failed to build gem native extension.

        /usr/lib64/fluent/ruby/bin/ruby extconf.rb
checking for curl-config... no
checking for main() in -lcurl... *** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers.  Check the mkmf.log file for more

解決

yum install libcurl-devel

再度エラー。gccないだけだった・・・

yum install gcc

設定ファイルを変更。apacheログを収集してみます。

/etc/td-agent/td-agent.conf

<source>
  type tail
  format apache
  path /var/log/httpd/access_log.%Y%m%d
  tag apache.access
</source>

<match apache.access>
  type elasticsearch
  host 192.168.33.10
  port 9200
  type_name access_log_2
  logstash_format true
  logstash_prefix apache_access
  logstash_dateformat %Y%m
</match>

やってから思った。
これkibana側にfluentd要らなかった。

25
26
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
25
26