Elasticsearch5.5.2(現在の最新版)をインストールする方法
Elasticsearchのバージョン5.5.2(2017年9月時点での最新版)をインストールする方法を記載します。
開発環境
開発環境はmacOS Sierra バージョン10.12.6です。
前提条件
Elasticsearchはjavaのバージョン8以上が必要です。
javaのバージョンはターミナルで以下のコマンドを入力すると確認できます。
$ java -version
javaのバージョン8以上が入っている場合は以下のような結果が出ます。
java version "1.8.0_121"
javaのバージョンが8ではないもしくはjava自体がダウンロードされていない場合はこちら( https://java.com/ja/download/ )のページからインストールするといいでしょう。
今回はjavaのインストールについては省略します。
javaのバージョン8以上がインストールされていることが確認できたら、 Elasticsearchをインストールしていきます。
Elasticsearchのインストール
公式のインストールガイド( https://www.elastic.co/jp/downloads/elasticsearch Download Elasticsearch Free • Get Started Now | Elastic )にそってインストールしていきます。
1.Download and unzip Elasticsearh zipファイルをダウンロードして解凍します。
まず下記の画像のzipと書いてあるところを押しzipファイルをダウンロードします。ファイルの大きさは32.0MB程です。
ダウンロードされたファイルを解凍するとelasticsearch-5.5.2というフォルダができます。
2.Run bin/elasticsearch (or bin\elasticsearch.bat on Windows)
elasticsearch-5.5.2のフォルダに行き、コンソールでbin/elasticsearchと入力し、elasticsearchを起動させます。
$ cd elasticsearch-5.5.2/ $ ./bin/elasticsearch
3.Run curl http://localhost:9200/ or Invoke-RestMethod http://localhost:9200 with PowerShell
2番のコマンド
$ ./bin/elasticsearch
を実行させたままコンソールの新しいタブでcurl http://localhost:9200/ と入力します。
$ curl http://localhost:9200/
このような表示が出ればElasticsearchのインストールは成功です。
{ "name" : "cCGN86r", "cluster_name" : "elasticsearch", "cluster_uuid" : "-wwzVPnXQv-5sdtCzccQCw", "version" : { "number" : "5.5.2", "build_hash" : "b2f0c09", "build_date" : "2017-08-14T12:33:14.154Z", "build_snapshot" : false, "lucene_version" : "6.6.0" }, "tagline" : "You Know, for Search" }
エラー
ここで何も応答が返ってこない場合またはコマンドの途中で強制終了した場合、上手くいかなくて2番のコマンドを再起動した場合は 以下のようなエラーがでる可能性があります。
[2017-09-07T12:58:43,632][INFO ][o.e.n.Node ] [] initializing ... [2017-09-07T12:58:43,667][WARN ][o.e.b.ElasticsearchUncaughtExceptionHandler] [] uncaught exception in thread [main] org.elasticsearch.bootstrap.StartupException: java.lang.IllegalStateException: failed to obtain node locks, tried [[/Users/haruka.sugawara/elasticsearch_blog_test/elasticsearch-5.5.2/data/elasticsearch]] with lock id [0]; maybe these locations are not writable or multiple nodes were started without increasing [node.max_local_storage_nodes] (was [1])? at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:127) ~[elasticsearch-5.5.2.jar:5.5.2] at org.elasticsearch.bootstrap.Elasticsearch.execute(Elasticsearch.java:114) ~[elasticsearch-5.5.2.jar:5.5.2] at org.elasticsearch.cli.EnvironmentAwareCommand.execute(EnvironmentAwareCommand.java:67) ~[elasticsearch-5.5.2.jar:5.5.2] at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:122) ~[elasticsearch-5.5.2.jar:5.5.2] at org.elasticsearch.cli.Command.main(Command.java:88) ~[elasticsearch-5.5.2.jar:5.5.2] at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:91) ~[elasticsearch-5.5.2.jar:5.5.2] at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:84) ~[elasticsearch-5.5.2.jar:5.5.2] Caused by: java.lang.IllegalStateException: failed to obtain node locks, tried [[フォルダ名/elasticsearch-5.5.2/data/elasticsearch]] with lock id [0]; maybe these locations are not writable or multiple nodes were started without increasing [node.max_local_storage_nodes] (was [1])? at org.elasticsearch.env.NodeEnvironment.<init>(NodeEnvironment.java:261) ~[elasticsearch-5.5.2.jar:5.5.2] at org.elasticsearch.node.Node.<init>(Node.java:264) ~[elasticsearch-5.5.2.jar:5.5.2] at org.elasticsearch.node.Node.<init>(Node.java:244) ~[elasticsearch-5.5.2.jar:5.5.2] at org.elasticsearch.bootstrap.Bootstrap$5.<init>(Bootstrap.java:232) ~[elasticsearch-5.5.2.jar:5.5.2] at org.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:232) ~[elasticsearch-5.5.2.jar:5.5.2] at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:351) ~[elasticsearch-5.5.2.jar:5.5.2] at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:123) ~[elasticsearch-5.5.2.jar:5.5.2] ... 6 more
このようなエラーが出た場合は以下の方法を試すとうまくいきます。
このURL(
https://stackoverflow.com/questions/28932178/elasticsearch-failed-to-obtain-node-lock-is-the-following-location-writable
Elasticsearch, Failed to obtain node lock, is the following location writable - Stack Overflow )に書かれてるようにコンソールで以下のコマンドを入力します。
$ ps aux | grep 'elastic' $ kill -9 PID(PIDはプロセス番号 例えば845や1127など)
PIDが複数個ある場合は複数個削除したほうがよさそうです。
削除するPIDがなくなったら再度以下の2番のコマンド、3番コマンドを実行します。
$ ./bin/elasticsearch $ curl http://localhost:9200/
このような表示が出ればElasticsearchのインストールは成功です。
{ "name" : "cCGN86r", "cluster_name" : "elasticsearch", "cluster_uuid" : "-wwzVPnXQv-5sdtCzccQCw", "version" : { "number" : "5.5.2", "build_hash" : "b2f0c09", "build_date" : "2017-08-14T12:33:14.154Z", "build_snapshot" : false, "lucene_version" : "6.6.0" }, "tagline" : "You Know, for Search" }