端くれプログラマの備忘録 Elasticsearch [Elasticsearch] v.2.3.2のセットアップ

[Elasticsearch] v.2.3.2のセットアップ

現時点の最新版2.3.2をVagrant上のCentOS 7.1にインストールする。

Setup | Elasticsearch Reference [2.3] | Elastic
https://www.elastic.co/guide/en/elasticsearch/reference/current/setup.html

VagrantへのCentOS 7.1のインストール

$ mkdir centos-7.1-es
$ cd centos-7.1-es
$ vagrant init centos-7.1
$ vagrant up
$ sudo yum update -y

Javaのインストール

  • Elasticsearchの実行にはJava 7以降が必須
  • Java 8 update 20以降またはJava 7 update 77以降を推奨

CentOSのリポジトリでJava(OpenJDK)を探す。

$ yum search openjdk
...
java-1.6.0-openjdk.x86_64 : OpenJDK Runtime Environment
java-1.6.0-openjdk-demo.x86_64 : OpenJDK Demos
java-1.6.0-openjdk-devel.x86_64 : OpenJDK Development Environment
java-1.6.0-openjdk-javadoc.x86_64 : OpenJDK API Documentation
java-1.6.0-openjdk-src.x86_64 : OpenJDK Source Bundle
java-1.7.0-openjdk.x86_64 : OpenJDK Runtime Environment
java-1.7.0-openjdk-accessibility.x86_64 : OpenJDK accessibility connector
java-1.7.0-openjdk-demo.x86_64 : OpenJDK Demos
java-1.7.0-openjdk-devel.x86_64 : OpenJDK Development Environment
java-1.7.0-openjdk-headless.x86_64 : The OpenJDK runtime environment without audio and video support
java-1.7.0-openjdk-javadoc.noarch : OpenJDK API Documentation
java-1.7.0-openjdk-src.x86_64 : OpenJDK Source Bundle
java-1.8.0-openjdk.x86_64 : OpenJDK Runtime Environment
java-1.8.0-openjdk-accessibility.x86_64 : OpenJDK accessibility connector
java-1.8.0-openjdk-accessibility-debug.x86_64 : OpenJDK accessibility connector for packages with debug on
java-1.8.0-openjdk-debug.x86_64 : OpenJDK Runtime Environment with full debug on
java-1.8.0-openjdk-demo.x86_64 : OpenJDK Demos
java-1.8.0-openjdk-demo-debug.x86_64 : OpenJDK Demos with full debug on
java-1.8.0-openjdk-devel.x86_64 : OpenJDK Development Environment
java-1.8.0-openjdk-devel-debug.x86_64 : OpenJDK Development Environment with full debug on
java-1.8.0-openjdk-headless.x86_64 : OpenJDK Runtime Environment
java-1.8.0-openjdk-headless-debug.x86_64 : OpenJDK Runtime Environment with full debug on
java-1.8.0-openjdk-javadoc.noarch : OpenJDK API Documentation
java-1.8.0-openjdk-javadoc-debug.noarch : OpenJDK API Documentation for packages with debug on
java-1.8.0-openjdk-src.x86_64 : OpenJDK Source Bundle
java-1.8.0-openjdk-src-debug.x86_64 : OpenJDK Source Bundle for packages with debug on
...

Java 8のランタイムをインストールする。

$ sudo yum install java-1.8.0-openjdk -y
$ java -version
openjdk version "1.8.0_91"
OpenJDK Runtime Environment (build 1.8.0_91-b14)
OpenJDK 64-Bit Server VM (build 25.91-b14, mixed mode)

Elasticreserchのインストール

$ wget https://download.elastic.co/elasticsearch/release/org/elasticsearch/distribution/rpm/elasticsearch/2.3.2/elasticsearch-2.3.2.rpm
$ sudo rpm -ivh elasticsearch-2.3.2.rpm
$ sudo systemctl daemon-reload
$ sudo systemctl enable elasticsearch.service

Elasticsearchの設定

ローカルホストに加えて、VagrantのホストOS側からのアクセスも許す

/etc/elasticsearch/elasticsearch.yml

network.host: [127.0.0.1, 192.168.33.10]

Elasticsearchの実行

$ sudo service elasticsearch start

ざっくり動作確認

まずはローカルホストのシェルから

$ curl -X GET 'http://localhost:9200'
{
  "name" : "Possessor",
  "cluster_name" : "elasticsearch",
  "version" : {
    "number" : "2.3.2",
    "build_hash" : "b9e4a6acad4008027e4038f6abed7f7dba346f94",
    "build_timestamp" : "2016-04-21T16:03:47Z",
    "build_snapshot" : false,
    "lucene_version" : "5.5.0"
  },
  "tagline" : "You Know, for Search"
}

次にホストOSのブラウザから

http://192.168.33.10:9200/
{
  "name" : "Georgianna Castleberry",
  "cluster_name" : "elasticsearch",
  "version" : {
  "number" : "2.3.2",
  "build_hash" : "b9e4a6acad4008027e4038f6abed7f7dba346f94",
  "build_timestamp" : "2016-04-21T16:03:47Z",
  "build_snapshot" : false,
  "lucene_version" : "5.5.0"
  },
  "tagline" : "You Know, for Search"
}

Headプラグインのインストール

$ cd /usr/share/elasticsearch
$ sudo bin/plugin install mobz/elasticsearch-head
$ sudo service elasticsearch restart

http://192.168.33.10:9200/_plugin/head/

elasticsearch-head