fluentd+elasticsearch+kibana

技術文書
2015/07/02

[49.212.169.75]

nginxインストール

[root@]# rpm -ivh http://nginx.org/packages/centos/6/noarch/RPMS/nginx-release-centos-6-0.el6.ngx.noarch.rpm
[root@]# yum install nginx
[root@]# nginx -v
[root@]# vi /etc/nginx/conf.d/kibana.conf
server
{
  listen *:8000;
  server_name localhost;

  access_log /var/log/nginx/kibana.access.log;

  location /kibana/
  {
    root /usr/share/nginx/html;
    index index.html index.htm;
  }

  location /
  {
    proxy_pass http://127.0.0.1:9200;
      proxy_read_timeout 90;
  }
}

fluentdインストール

[root@]# curl -L http://toolbelt.treasure-data.com/sh/install-redhat.sh | sh

elasticsearch pluginインストール

[root@]# /usr/lib64/fluent/ruby/bin/fluent-gem install fluent-plugin-elasticsearch

javaインストール

[root@]# yum install java-1.8.0-openjdk-devel

elasticsearchインストール

[root@]# rpm --import http://packages.elasticsearch.org/GPG-KEY-elasticsearch
[root@]# vi /etc/yum.repos.d/elasticsearch.repo
[elasticsearch-1.4]
name=Elasticsearch repository for 1.4.x packages
baseurl=http://packages.elasticsearch.org/elasticsearch/1.4/centos
gpgcheck=1
gpgkey=http://packages.elasticsearch.org/GPG-KEY-elasticsearch
enabled=1
[root@]# yum install elasticsearch
[root@]# vi /etc/elasticsearch/elasticsearch.yml
http.cors.allow-origin: "*" 
http.cors.enabled: true
[root@]# chkconfig elasticsearch on
[root@]# /etc/init.d/elasticsearch start
[root@]# curl -X GET http://localhost:9200/
{
  "status" : 200,
  "name" : "Hank Pym",
  "cluster_name" : "elasticsearch",
  "version" : {
    "number" : "1.4.5",
    "build_hash" : "2aaf797f2a571dcb779a3b61180afe8390ab61f9",
    "build_timestamp" : "2015-04-27T08:06:06Z",
    "build_snapshot" : false,
    "lucene_version" : "4.10.4" 
  },
  "tagline" : "You Know, for Search" 
}

kinabaインストール

[root@]# wget https://download.elasticsearch.org/kibana/kibana/kibana-3.1.0.tar.gz
[root@]# tar zxvf kibana-3.1.0.tar.gz 
[root@]# cp -r kibana-3.1.0 /usr/share/nginx/html/kibana

nginx起動

[root@]# /etc/init.d/nginx start

fluentd設定

[root@]# vi /etc/td-agent/td-agent.conf
<source>
  type forward
  port 24224
</source>

<match nginx.access.**>
  type copy

  <store>
    type stdout
  </store>

  <store>
    type elasticsearch
    host localhost
    port 9200
    type_name access_log
    logstash_format true
    logstash_prefix nginx_access
    logstash_dateformat %Y%m
  </store>

 </match>

fluentd起動

[root@]# /etc/init.d/td-agent start

[49.212.176.26]

送信元サーバfluentd設定

[root@]# vi /etc/td-agent/td-agent.conf
<source>
  type tail
  path /usr/local/openresty/nginx/logs/access.log
  tag nginx.access
  pos_file /var/log/td-agent/nginx.pos
  format apache
</source>
<match nginx.access>
  type forward 
  buffer_type memory
  buffer_chunk_limit 256m
  buffer_queue_limit 128
  flush_interval 5s
  <server>
    host 192.168.1.2
    port 24224
  </server>
</match>

fluentd再起動

[root@]# /etc/init.d/td-agent restart

ブラウザ確認

http://49.212.169.75:8000/kibana/

参考URL
http://www.fisproject.jp/2015/02/centos-fluentd-elasticsearch-kibana-nginx/

ファイル