Elasticsearch を Homebrew でサクッと Mac インストールする手順

Pocket

Mac に Elasticsearch をインストールしたので手順をご紹介します。

インストール可能な Elasticsearch のバージョンを確認

2016年4月26日時点での最新版 2.3.1 がインストールできそうです。

$ brew info elasticsearch
elasticsearch: stable 2.3.1, HEAD
Distributed search & analytics engine
https://www.elastic.co/products/elasticsearch
Not installed
From: https://github.com/Homebrew/homebrew-core/blob/master/Formula/elasticsearch.rb
==> Caveats
Data:    /usr/local/var/elasticsearch/elasticsearch_bakorer/
Logs:    /usr/local/var/log/elasticsearch/elasticsearch_bakorer.log
Plugins: /usr/local/Cellar/elasticsearch/2.3.1/libexec/plugins/
Config:  /usr/local/etc/elasticsearch/
plugin script: /usr/local/Cellar/elasticsearch/2.3.1/libexec/bin/plugin
 
To have launchd start elasticsearch now and restart at login:
  brew services start elasticsearch
Or, if you don't want/need a background service you can just run:
  elasticsearch

Elasticsearch をインストール

brew コマンドでサクッと elasticsearch をインストールしようとすると Java が無いというエラーが発生します。Java・・・

$ brew install elasticsearch
elasticsearch: Java 1.7+ is required to install this formula.
You can install with Homebrew Cask:
  brew install Caskroom/cask/java
 
You can download from:
  http://www.oracle.com/technetwork/java/javase/downloads/index.html
Error: An unsatisfied requirement failed this build.

Java をインストール

Oracle 公式サイトから Java をインストールしてもいいんですが、楽するために Java も brew コマンドでインストールしてしまいます。

$ brew install Caskroom/cask/java
==> brew cask install Caskroom/cask/java
==> We need to make Caskroom for the first time at /opt/homebrew-cask/Caskroom
==> We'll set permissions properly so we won't need sudo in the future
Password:
==> Caveats
This Cask makes minor modifications to the JRE to prevent issues with
packaged applications, as discussed here:
 
  https://bugs.eclipse.org/bugs/show_bug.cgi?id=411361
 
If your Java application still asks for JRE installation, you might need
to reboot or logout/login.
 
Installing this Cask means you have AGREED to the Oracle Binary Code
License Agreement for Java SE at
 
  http://www.oracle.com/technetwork/java/javase/terms/license/index.html
 
==> Downloading http://download.oracle.com/otn-pub/java/jdk/8u92-b14/jdk-8u92-macosx-x64.dmg
######################################################################## 100.0%
==> Verifying checksum for Cask java
==> Running installer for java; your password may be necessary.
==> Package installers may write to any location; options such as --appdir are ignored.
==> installer: Package name is JDK 8 Update 92
==> installer: Installing at base path /
==> installer: The install was successful.
🍺  java staged at '/opt/homebrew-cask/Caskroom/java/1.8.0_92-b14' (2 files, 227M)

念の為 Java がインストールされていることを確認します。

$ java -version 
java version "1.8.0_92"
Java(TM) SE Runtime Environment (build 1.8.0_92-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.92-b14, mixed mode)

改めて Elasticsearch をインストール

$ brew install elasticsearch
==> Downloading https://download.elasticsearch.org/elasticsearch/release/org/elasticsearch/distribution/tar/elasticsearch/2.3.1/elasticsearch-2.3.1.tar.gz
######################################################################## 100.0%
==> Caveats
Data:    /usr/local/var/elasticsearch/elasticsearch_bakorer/
Logs:    /usr/local/var/log/elasticsearch/elasticsearch_bakorer.log
Plugins: /usr/local/Cellar/elasticsearch/2.3.1/libexec/plugins/
Config:  /usr/local/etc/elasticsearch/
plugin script: /usr/local/Cellar/elasticsearch/2.3.1/libexec/bin/plugin
 
To have launchd start elasticsearch now and restart at login:
  brew services start elasticsearch
Or, if you don't want/need a background service you can just run:
  elasticsearch
==> Summary
🍺  /usr/local/Cellar/elasticsearch/2.3.1: 59 files, 29.4M, built in 1 minute 40 seconds

こちらも念の為、elasticsearch のバージョンを確認しておきます。

$ elasticsearch --version
Version: 2.3.1, Build: bd98092/2016-04-04T12:25:05Z, JVM: 1.8.0_92

elasticsearch を起動

Elasticsearch を起動してみます。

$ brew services start elasticsearch
==> Tapping homebrew/services
Cloning into '/usr/local/Library/Taps/homebrew/homebrew-services'...
remote: Counting objects: 7, done.
remote: Compressing objects: 100% (6/6), done.
remote: Total 7 (delta 0), reused 6 (delta 0), pack-reused 0
Unpacking objects: 100% (7/7), done.
Checking connectivity... done.
Tapped 0 formulae (32 files, 46.0K)
==> Successfully started `elasticsearch` (label: homebrew.mxcl.elasticsearch)

elasticsearch のプロセスが起動されていることを確認しました。

$ ps aux | grep elasticsearch
bakorer          1308   0.5  1.5  5075616 256028   ??  S     7:04PM   0:07.18 /usr/bin/java -Xms256m -Xmx1g -Djava.awt.headless=true -XX:+UseParNewGC -XX:+UseConcMarkSweepGC -XX:CMSInitiatingOccupancyFraction=75 -XX:+UseCMSInitiatingOccupancyOnly -XX:+HeapDumpOnOutOfMemoryError -XX:+DisableExplicitGC -Dfile.encoding=UTF-8 -Djna.nosys=true -Des.path.home=/usr/local/Cellar/elasticsearch/2.3.1/libexec -cp /usr/local/Cellar/elasticsearch/2.3.1/libexec/lib/elasticsearch-2.3.1.jar:/usr/local/Cellar/elasticsearch/2.3.1/libexec/lib/* org.elasticsearch.bootstrap.Elasticsearch start
bakorer          1327   0.0  0.0  2432772    560 s000  S+    7:04PM   0:00.00 grep --color=always elasticsearch

[おまけ] elasticsearch-head をインストール

Elasticsearch には plugin をインストールできる仕組みがあり、elasticsearch-head をインストールするとブラウザから色々と確認できるようになります。

$ /usr/local/Cellar/elasticsearch/2.3.1/libexec/bin/plugin install mobz/elasticsearch-head
-> Installing mobz/elasticsearch-head...
Trying https://github.com/mobz/elasticsearch-head/archive/master.zip ...
Downloading 
...............................................................................................DONE
Verifying https://github.com/mobz/elasticsearch-head/archive/master.zip checksums if available ...
NOTE: Unable to verify checksum for downloaded plugin (unable to find .sha1 or .md5 file to verify)
Installed head into /usr/local/Cellar/elasticsearch/2.3.1/libexec/plugins/head

管理画面の URL は http://localhost:9200/_plugin/head/ です。

elasticsearch-head を使って見れる管理画面

elasticsearch-head によって http://localhost:9200/_plugin/head/ から見れるそれっぽい管理画面

Elasticsearch を使い始めたばかりなので、これから徐々にキャッチアップしていきたいと思います。

  1. コメントはまだありません。

  1. トラックバックはまだありません。