##はじめに
Fluentdをインストールしてみたときに、elasticsearch、kibanaもインストール
https://qiita.com/ijimakenta/items/1794cfe193d1a4755258
##環境
- CentOS7
##インストール
###openjdkインストール
yum install -y java-1.8.0-openjdk
###elasticsearch, kibanaインストール
参考
https://www.elastic.co/guide/en/elasticsearch/reference/current/rpm.html
# 公開鍵インポート
rpm --import https://artifacts.elastic.co/GPG-KEY-elasticsearch
# レポジトリ登録
cat <<'EOT' > /etc/yum.repos.d/elasticsearch.repo
[elasticsearch-6.x]
name=Elasticsearch repository for 6.x packages
baseurl=https://artifacts.elastic.co/packages/6.x/yum
gpgcheck=1
gpgkey=https://artifacts.elastic.co/GPG-KEY-elasticsearch
enabled=1
autorefresh=1
type=rpm-md
EOT
# インストール
yum install elasticsearch kibana
# 自動起動
systemctl enable elasticsearch kibana
##設定
とりあえず、0.0.0.0でLISTEN
diff elasticsearch.yml elasticsearch.yml_org | grep "^<"
< network.host: 0.0.0.0
###kibanaログ設定
デフォルトだと/var/log/messagesに出力されてしまうので、きれいにする
cat <<'EOT' > /etc/rsyslog.d/kibana.conf
:programname, isequal, "kibana" -/var/log/kibana.log
& stop
EOT
systemctl restart rsyslog &&\
sed -i '1i\/var\/log\/kibana.log' /etc/logrotate.d/syslog
##インデックス削除スクリプト
インデクスが肥大化していくみたいなので、自動削除スクリプトを以下サイト参考に作成
http://y-ken.hatenablog.com/entry/elasticsearch-delete-index-with-one-liners
#!/bin/bash
index_rotate_day=3
index[0]=$(date +apache.access-%Y.%m.%d --date "$index_rotate_day days ago")
index[1]=$(date +apache.error-%Y.%m.%d --date "$index_rotate_day days ago")
index[2]=$(date +postfix.maillog-%Y.%m.%d --date "$index_rotate_day days ago")
logdir=/usr/local/bin/del_elasticsearch_index/log
logfile=del_elasticsearch_index-$(date "+%Y%m%d").log
log_rotate_day=+31
{
find ${logdir} -name 'del_elasticsearch_index*' -mtime "$log_rotate_day" -exec rm -vf {} \;
for ((i=0; i < ${#index[@]}; i++))
do
curl -XDELETE -w'\n' http://localhost:9200/"${index[$i]}"
done
} 2>&1 | awk '{print strftime("%Y-%m-%d %H:%M:%S "),$0 } { fflush() } ' | tee -a "$logdir/$logfile"