概要
2015/10/25 時点で各種最新版を導入する手順を確認したのでメモ。
お試し用として、1つのEC2インスタンスにインストールする構成で作る。
環境について
OS
Amazon Linux 2015.09
ミドル
原則yumでインストールする。
また、Kibanaにbasic認証をかけるためnginxを利用する。
td-agent-2.2.1-0.el2015.x86_64
elasticsearch-1.7.3-1.noarch
kibana-4.1.1-1.x86_64
nginx-1.8.0-10.25.amzn1.x86_64
fluentd-plugin
fluent-plugin-elasticsearch (1.1.0)
fluent-plugin-elb-log (0.2.5)
AWS側の設定
ELBのアクセスログを出力させる
EC2 > Load Balancers > [対象ELB] > Description
Access Logs の Edit
を選択して編集
ログ出力のインターバルは5分で設定。
また、今回は例として下記のbacket, prefixを利用するとしてtd-agent.confを設定する。
s3://example-bucket/example-elb
S3 readonly User作成
FluentdからS3を参照するために作成する。
具体的には下記など同様に作成する。
http://dev.classmethod.jp/etc/create_readonly_iamuser/
access_Key, secret_keyを控えておく。
各種インストール
ElasticSearch インストール
yumで導入する
GPG-KEYをインポート
rpm --import https://packages.elastic.co/GPG-KEY-elasticsearch
リポジトリ追加
vim /etc/yum.repos.d/elasticsearch.repo
[elasticsearch-1.7]
name=Elasticsearch repository for 1.7.x packages
baseurl=http://packages.elastic.co/elasticsearch/1.7/centos
gpgcheck=1
gpgkey=http://packages.elastic.co/GPG-KEY-elasticsearch
enabled=1
インストール
yum install elasticsearch
service elasticsearch start
chkconfgi elasticsearch on
Kibanaインストール
yumで導入。また、リバースプロキシとしてnginxを使い、TCP:80をkibana(localhost:5601)に渡す。
yumリポジトリを設定する
vi /etc/yum.repos.d/kibana.repo
[kibana-4.1]
name=Kibana repository for 4.1.x packages
baseurl=http://packages.elastic.co/kibana/4.1/centos
gpgcheck=1
gpgkey=http://packages.elastic.co/GPG-KEY-elasticsearch
enabled=1
kibana インストール
yum install -y kibana
kibana 設定変更、起動
vim /opt/kibana/config/kibana.yml
# The host to bind the server to.
host: "localhost"
service kibana start
chkconfg kibana on
nginx install
yum install nginx http-tools
basic認証設定
tpasswd -c /etc/nginx/htpasswd.users kibanaadmin
<任意のパスワード入力>
nginx.conf 編集
デフォルトで設定されている serverブロックをコメントアウトする。
vim /etc/nginx/nginx.conf
内容省略
kibana用のリバースプロキシ設定を投入する。
vim /etc/nginx/conf.d/kibana.conf
server {
listen 80;
server_name example.com;
auth_basic "Restricted Access";
auth_basic_user_file /etc/nginx/htpasswd.users;
location / {
proxy_pass http://localhost:5601;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}
service nginx start
chkconfig nginx on
http://<サーバIP> で接続し、kibanaにbasic認証でログイン可能か確認する。
td-agent2
インストール
curl -L http://toolbelt.treasuredata.com/sh/install-redhat-td-agent2.sh | sh
fluent-pluginをインストール
/opt/td-agent/usr/sbin/td-agent-gem install fluent-plugin-elasticsearch
/opt/td-agent/usr/sbin/td-agent-gem install fluent-plugin-elb-log
td-agent.confを編集する
s3 read onlyユーザのaccess_key, secret_keyを指定する。
vim /etc/td-agent/td-agent.conf
<source>
type elb_log
region ap-northeast-1
s3_bucketname example-bucket
s3_prefix example-elb
timestamp_file /tmp/elb_last_at.dat
buf_file /tmp/fluentd-elblog.tmpfile
refresh_interval 300
tag elb.access
access_key_id <acees_key>
secret_access_key <secret_key>
</source>
<match elb.access>
type elasticsearch
type_name access_log
host localhost
port 9200
logstash_format true
include_tag_key true
tag_key @log_name
</match>
起動
service td-agent start
chkconfig td-agent on
Kibana初期設定
Setting > indeces
Configure an index pattern
と表示されてるページで
Time-field name = time を選択して Create
あとはELBのログ出力、Fluentdの転送を待ちましょう。
参考
- http://www.denet.ad.jp/technology/2014/04/vol11-elbfluentdelasticsearchkibana.html
- https://www.digitalocean.com/community/tutorials/how-to-install-elasticsearch-logstash-and-kibana-4-on-centos-7
- https://www.elastic.co/guide/en/elasticsearch/reference/current/setup-repositories.html
- http://dev.classmethod.jp/cloud/td-agent2-amazon-linux/