ねこものがたり

いちにちいっぽ

ElasticsearchをHomebrewでインストールし起動する方法

Download Elasticsearch (No JDK)(公式)とか Elasticsearch実践ガイドを読んで、生Elasticsearchを触ってみようと思ったんだけど、なんかうまくいかないし、実践ガイドにはMacOSでのインストール・起動方法はとくに触れられていませんでした。

MacだしHomebrewで入れたい」って思うじゃないですか。

最初のDownload Elasticsearch (No JDK)に書いてあった"Elasticsearch can also be installed from our package repositories using apt or yum, or installed on Windows using an MSI installer package. See Repositories in the Guide."のリンクから飛んでInstall Elasticsearch on macOS with Homebrewへたどり着きました。(ぜえぜえ)

インストール

コマンドは引用です。

$ brew tap elastic/tap
$ brew install elastic/tap/elasticsearch-full

OSS版を使いたければelastic/tap/elasticsearch-ossを指定してねって書いてあるのですが、今は本をもとに進めてるのもあってOSS版は保留。

起動

$ bin/elasticsearch

と公式getting startedでも書籍でも紹介されていますが

$ elasticseach

で起動しました。

接続確認

これは公式ページにも書籍にも書いてあるままコマンドを実行しました。

$  curl -XGET http://localhost:9200
{
  "name" : "kanekokeikonoMacBook.local",
  "cluster_name" : "elasticsearch_keiko",
  "cluster_uuid" : "NUXBP0TIRYCp9CRmCJgi9Q",
  "version" : {
    "number" : "7.6.0",
    "build_flavor" : "default",
    "build_type" : "tar",
    "build_hash" : "7f634e9f44834fbc12724506cc1da681b0c3b1e3",
    "build_date" : "2020-02-06T00:09:00.449973Z",
    "build_snapshot" : false,
    "lucene_version" : "8.4.0",
    "minimum_wire_compatibility_version" : "6.8.0",
    "minimum_index_compatibility_version" : "6.0.0-beta1"
  },
  "tagline" : "You Know, for Search"
}

接続できました!

もしポート番号がわからなくても、

$ elasticsearch
OpenJDK 64-Bit Server VM warning: Option UseConcMarkSweepGC was deprecated in version 9.0 and will likely be removed in a future release.
[2020-02-23T17:37:27,615][INFO ][o.e.e.NodeEnvironment    ] [kanekokeikonoMacBook.local] using [1] data paths, mounts [[/System/Volumes/Data (/dev/disk1s1)]], net usable_space [67.2gb], net total_space [233.4gb], types [apfs]
(略)

とログが続いている中に情報が出ているので、それを見れば良さそうです。

[2020-02-23T17:40:21,837][INFO ][o.e.h.AbstractHttpServerTransport] [kanekokeikonoMacBook.local] publish_address {127.0.0.1:9200}, bound_addresses {[::1]:9200}, {127.0.0.1:9200}

起動コマンドのオプション

$ elasticsearch -h
OpenJDK 64-Bit Server VM warning: Option UseConcMarkSweepGC was deprecated in version 9.0 and will likely be removed in a future release.
Starts Elasticsearch

Option                Description                                               
------                -----------                                               
-E <KeyValuePair>     Configure a setting                                       
-V, --version         Prints Elasticsearch version information and exits        
-d, --daemonize       Starts Elasticsearch in the background                    
-h, --help            Show help                                                 
-p, --pidfile <Path>  Creates a pid file in the specified path on start         
-q, --quiet           Turns off standard output/error streams logging in console
-s, --silent          Show minimal output                                       
-v, --verbose         Show verbose output 

-d でバックグラウンドでの起動ができるようです。慣れるまではこのオプションは自分は使わないでやっておこうと思います。

余談ですがdocker等でもバックグラウンドのオプションが -d だけど”バックグラウンドなのになんでdなんだろう”と思っていたのですがdeamonizeのことだったのかと知りました。