初心者歓迎! Elastic Stack 5.0 を使ってみる — 前編 -

eureka, Inc.
Eureka Engineering
Published in
8 min readOct 31, 2016
Elasticsearch-Logo-Color-V

こんにちは! Pairsの検索アルゴリズムの新規開発・改修を担当している小島です。

先週末、待ちに待ったElastic Stack 5.0.0 GA版がリリースされました!

新機能の追加や性能改善などこれまで使ってきた私たちにも嬉しいですが、導入のしやすさという点でもますます魅力に磨きがかかり、これからElasticsearchを始める方にも嬉しいものになったと思います。

今回は手っ取り早くElastic Stack5.0を使ってみたかったので、OS X上での設定から簡単な導入までを書いてみようと思います。

インストール

skitch1

Elasticsearchのインストール

まずは以下コマンドでElasticsearchをダウンロードしましょう。

$ curl -L -O https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-5.0.0.zip
$ unzip elasticsearch-5.0.0.zip

起動

$ cd elasticsearch-5.0.0
$ ./bin/elasticsearch
# 起動確認
$ curl localhost:9200
{
"name" : "MXI1h01",
"cluster_name" : "elasticsearch",
"cluster_uuid" : "DJrn6rP7Tsu6Y1jp56TeKQ",
"version" : {
"number" : "5.0.0",
"build_hash" : "253032b",
"build_date" : "2016-10-26T04:37:51.531Z",
"build_snapshot" : false,
"lucene_version" : "6.2.0"
},
"tagline" : "You Know, for Search"
}
Kibanaのインストール続いてKibanaをインストールします。ダウンロードcurl -L -O https://artifacts.elastic.co/downloads/kibana/kibana-5.0.0-darwin-x86_64.tar.gz
tar xzvf kibana-5.0.0-darwin-x86_64.tar.gz
起動cd kibana-5.0.0-darwin-x86_64/
./bin/kibana
以下のようなページが開きます。
kibana
Elasticsearch-headのインストール次にElasticsearchのindexを確認しやすくするため、Elasticsearch-headをインストールします。
2.xまではpluginとして動かしていたheadですが、ElasticsearchにGUIを追加するsite plugin機能がセキュリティ上の理由により削除されたため、pluginとしては使用できなくなりました。ただheadに関しては単体のアプリケーションとしても起動できるため、今回はそちらを起動させて使用します。
githubのREAD MEに手順が書かれているので、その手順通りに進めます。
elasticsearch-head#running-with-built-in-server
$ git clone https://github.com/mobz/elasticsearch-head$ cd elasticsearch-head$ npm install$ grunt serverこれでheadが起動しますので、ページを開いてみます。$ open http://localhost:9100/一番上のElasticsearchのステータスが「cluster health: not connected」 になっていて接続できていないのでElasticsearchの設定を修正します。
以下の内容を config/elasticsearch.yml に追記してElasticsearchを再起動してください。
http.cors.enabled: true
http.cors.allow-origin: "*"
すると先程の「cluster health: not connected」が「cluster health: green (0 of 0)」に変わります。
これでheadも使用できるようになりました。
Logstashのインストール続いてLogstashをインストールします。ダウンロード$ curl -L -O https://artifacts.elastic.co/downloads/logstash/logstash-5.0.0.zip
$ unzip logstash-5.0.0.zip
Beatsからの出力されたデータをLogstashで受け取り、加工した後にElasticsearchへと入れるため、LogstashにBeats用のpluginをインストールします。cd logstash-5.0.0
./bin/logstash-plugin install logstash-input-beats
次にインプットとアウトプットの設定用ファイルを作成します。# ファイルを作成
$ vim logstash.conf
# 以下を入力するinput {
beats {
port => 5044
}
}
output {
elasticsearch {
hosts => "localhost:9200"
manage_template => false
index => "%{[@metadata][beat]}-%{+YYYY.MM.dd}"
document_type => "%{[@metadata][type]}"
}
}
作成したconfigを指定して、Logstashを起動する。./bin/logstash -f logstash.conf

Beatsのインストール

最後にBeatsをインストールします。
今回、私の環境がOS Xなので、OS Xのローカルでも使用できる 「filebeat」を使ってみようと思います。
filebeat
  • インストール
$ curl -L -O https://artifacts.elastic.co/downloads/beats/filebeat/filebeat-5.0.0-darwin-x86_64.tar.gz
$ tar xzvf filebeat-5.0.0-darwin-x86_64.tar.gz
$ cd packetbeat-5.0.0-darwin-x86_64
$ vim filebeat.yml
# 以下を編集する#-------------------------- Elasticsearch output ------------------------------
output.elasticsearch:
# Array of hosts to connect to.
hosts: ["localhost:9200"]
# 以下を追記
template.name: "filebeat"
template.path: "filebeat.template.json"
template.overwrite: false
# ----------------------------- Logstash output --------------------------------
# 以下のようにコメントアウトされている部分をコメントイン
output.logstash:
# The Logstash hosts
hosts: ["localhost:5044"]
filebeatのテンプレートを登録する$ cd filebeat-5.0.0-darwin
$ curl -XPUT 'http://localhost:9200/_template/filebeat' -d@filebeat.template.json
filebeatの起動sudo ./filebeat -e -c filebeat.yml -d "publish"これでOS X上のログがElasticsearchへと登録されます。Kibana上で確認以下のように、Discoverタブにグラフが表示されるようになれば成功です。最後に前編では、Elastic Stackそれぞれのインストールと簡単な表示確認までをご紹介しました。
後編はKibanaでのダッシュボードの設定方法や、ログのパースの仕方など、もっと詳細に書きたいと思います。
参考: https://www.elastic.co/guide/en/beats/libbeat/5.0/getting-started.html

--

--

eureka, Inc.
Eureka Engineering

Learn more about how Eureka technology and engineering