Ubuntuに入れたElasticsearchにプラグインがインストールできない時の対処まとめ

# 環境

使用しているUbuntuのバージョンは16です。

# Elasticsearchのインストール

以下のコマンド一発で入りました。

```sh:
$ sudo apt-get install elasticsearch
```

# Elasticsearchの起動

以下のコマンド一発で起動しました。

```sh:
$ sudo /usr/share/elasticsearch/bin/elasticsearch
```

Webブラウザで以下のURLにアクセスすると起動の確認ができました。

http://localhost:9200

```json:
{
  "status" : 200,
  "name" : "Werewolf by Night",
  "cluster_name" : "elasticsearch",
  "version" : {
    "number" : "1.7.3",
    "build_hash" : "NA",
    "build_timestamp" : "NA",
    "build_snapshot" : false,
    "lucene_version" : "4.10.4"
  },
  "tagline" : "You Know, for Search"
}
```

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

mobz/elasticsearch-headとelasticsearch/elasticsearch-analysis-kuromojiというプラグインが必須っぽいので、インストールを試みました。

参考URL
https://github.com/mobz/elasticsearch-head
https://github.com/elastic/elasticsearch-analysis-kuromoji

以下のコマンドを実行。

```sh:
$ sudo /usr/share/elasticsearch/bin/plugin install mobz/elasticsearch-head
Exception in thread "main" org.elasticsearch.env.FailedToResolveConfigException: Failed to resolve config path ["/usr/share/elasticsearch/config/elasticsearch.yml"], tried file path ["/usr/share/elasticsearch/config/elasticsearch.yml"], path file ["/usr/share/elasticsearch/config"/"/usr/share/elasticsearch/config/elasticsearch.yml"], and classpath
	at org.elasticsearch.env.Environment.resolveConfig(Environment.java:291)
	at org.elasticsearch.node.internal.InternalSettingsPreparer.prepareSettings(InternalSettingsPreparer.java:95)
	at org.elasticsearch.plugins.PluginManager.main(PluginManager.java:396)
```

エラーで失敗。

# 調査

プラグインのインストールコマンドは、ただのスクリプトみたいなので内容を確認。

```sh:
$ sudo vi /usr/share/elasticsearch/bin/plugin
```

最終行の"exec"を"echo"に変更。

```sh:
echo "$JAVA" $JAVA_OPTS $ES_JAVA_OPTS -Xmx64m -Xms16m -Delasticsearch -Des.path.home=\""$ES_HOME"\" $properties -cp \""$ES_CLASSPATH"\" org.elasticsearch.plugins.PluginManager $args
```

再度コマンドを実行。

```sh:
$ sudo /usr/share/elasticsearch/bin/plugin install mobz/elasticsearch-head
/usr/bin/java -Xmx64m -Xms16m -Delasticsearch -Des.path.home="/usr/share/elasticsearch" -Des.default.path.conf="/usr/share/elasticsearch/config" -Des.default.config="/usr/share/elasticsearch/config/elasticsearch.yml" -cp ":/usr/share/java/lucene-spatial-4.10.4.jar:/usr/share/java/lucene-replicator-4.10.4.jar:/usr/share/java/lucene-queries-4.10.4.jar:/usr/share/java/lucene-demo-4.10.4.jar:/usr/share/java/jna.jar:/usr/share/java/lucene-codecs-4.10.4.jar:/usr/share/java/lucene-analyzers-stempel-4.10.4.jar:/usr/share/java/sigar.jar:/usr/share/java/lucene-analyzers-icu-4.10.4.jar:/usr/share/java/lucene-analyzers-morfologik-4.10.4.jar:/usr/share/java/apache-log4j-extras-1.2.17.jar:/usr/share/java/groovy-all-2.x.jar:/usr/share/java/elasticsearch-1.7.3.jar:/usr/share/java/lucene-suggest-4.10.4.jar:/usr/share/java/log4j-1.2-1.2.17.jar:/usr/share/java/lucene-analyzers-kuromoji-4.10.4.jar:/usr/share/java/lucene-analyzers-phonetic-4.10.4.jar:/usr/share/java/lucene-expressions-4.10.4.jar:/usr/share/java/spatial4j-0.4.1.jar:/usr/share/java/lucene-analyzers-common-4.10.4.jar:/usr/share/java/lucene-misc-4.10.4.jar:/usr/share/java/lucene-benchmark-4.10.4.jar:/usr/share/java/lucene-join-4.10.4.jar:/usr/share/java/lucene-sandbox-4.10.4.jar:/usr/share/java/lucene-queryparser-4.10.4.jar:/usr/share/java/lucene-classification-4.10.4.jar:/usr/share/java/lucene-core-4.10.4.jar:/usr/share/java/lucene-analyzers-smartcn-4.10.4.jar:/usr/share/java/lucene-facet-4.10.4.jar:/usr/share/java/lucene-highlighter-4.10.4.jar:/usr/share/java/lucene-grouping-4.10.4.jar:/usr/share/java/jts.jar:/usr/share/java/lucene-test-framework-4.10.4.jar:/usr/share/java/lucene-analyzers-uima-4.10.4.jar:/usr/share/java/lucene-memory-4.10.4.jar:" org.elasticsearch.plugins.PluginManager "install" "mobz/elasticsearch-head"
```

インストールを実行するコマンドが表示されたので、試しにそのまま実行。

```sh:
$ sudo /usr/bin/java -Xmx64m -Xms16m -Delasticsearch -Des.path.home="/usr/share/elasticsearch" -Des.default.path.conf="/usr/share/elasticsearch/config" -Des.default.config="/usr/share/elasticsearch/config/elasticsearch.yml" -cp ":/usr/share/java/lucene-spatial-4.10.4.jar:/usr/share/java/lucene-replicator-4.10.4.jar:/usr/share/java/lucene-queries-4.10.4.jar:/usr/share/java/lucene-demo-4.10.4.jar:/usr/share/java/jna.jar:/usr/share/java/lucene-codecs-4.10.4.jar:/usr/share/java/lucene-analyzers-stempel-4.10.4.jar:/usr/share/java/sigar.jar:/usr/share/java/lucene-analyzers-icu-4.10.4.jar:/usr/share/java/lucene-analyzers-morfologik-4.10.4.jar:/usr/share/java/apache-log4j-extras-1.2.17.jar:/usr/share/java/groovy-all-2.x.jar:/usr/share/java/elasticsearch-1.7.3.jar:/usr/share/java/lucene-suggest-4.10.4.jar:/usr/share/java/log4j-1.2-1.2.17.jar:/usr/share/java/lucene-analyzers-kuromoji-4.10.4.jar:/usr/share/java/lucene-analyzers-phonetic-4.10.4.jar:/usr/share/java/lucene-expressions-4.10.4.jar:/usr/share/java/spatial4j-0.4.1.jar:/usr/share/java/lucene-analyzers-common-4.10.4.jar:/usr/share/java/lucene-misc-4.10.4.jar:/usr/share/java/lucene-benchmark-4.10.4.jar:/usr/share/java/lucene-join-4.10.4.jar:/usr/share/java/lucene-sandbox-4.10.4.jar:/usr/share/java/lucene-queryparser-4.10.4.jar:/usr/share/java/lucene-classification-4.10.4.jar:/usr/share/java/lucene-core-4.10.4.jar:/usr/share/java/lucene-analyzers-smartcn-4.10.4.jar:/usr/share/java/lucene-facet-4.10.4.jar:/usr/share/java/lucene-highlighter-4.10.4.jar:/usr/share/java/lucene-grouping-4.10.4.jar:/usr/share/java/jts.jar:/usr/share/java/lucene-test-framework-4.10.4.jar:/usr/share/java/lucene-analyzers-uima-4.10.4.jar:/usr/share/java/lucene-memory-4.10.4.jar:" org.elasticsearch.plugins.PluginManager "install" "mobz/elasticsearch-head"
-> Installing mobz/elasticsearch-head...
Trying https://github.com/mobz/elasticsearch-head/archive/master.zip...
Downloading ............................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................DONE
Installed mobz/elasticsearch-head into /usr/share/elasticsearch/plugins/head
```

成功したっぽい...(^_^;)
ブラウザでアクセスしてみるときちんと表示されました。

http://localhost:9200/_plugin/head/

# elasticsearch/elasticsearch-analysis-kuromojiのインストール

先ほどと同じようにインストールするプラグイン名を変更し、同じ方法でやってみたけど失敗。

```sh:
$ sudo /usr/bin/java -Xmx64m -Xms16m -Delasticsearch -Des.path.home="/usr/share/elasticsearch" -Des.default.path.conf="/usr/share/elasticsearch/config" -Des.default.config="/usr/share/elasticsearch/config/elasticsearch.yml" -cp ":/usr/share/java/lucene-spatial-4.10.4.jar:/usr/share/java/lucene-replicator-4.10.4.jar:/usr/share/java/lucene-queries-4.10.4.jar:/usr/share/java/lucene-demo-4.10.4.jar:/usr/share/java/jna.jar:/usr/share/java/lucene-codecs-4.10.4.jar:/usr/share/java/lucene-analyzers-stempel-4.10.4.jar:/usr/share/java/sigar.jar:/usr/share/java/lucene-analyzers-icu-4.10.4.jar:/usr/share/java/lucene-analyzers-morfologik-4.10.4.jar:/usr/share/java/apache-log4j-extras-1.2.17.jar:/usr/share/java/groovy-all-2.x.jar:/usr/share/java/elasticsearch-1.7.3.jar:/usr/share/java/lucene-suggest-4.10.4.jar:/usr/share/java/log4j-1.2-1.2.17.jar:/usr/share/java/lucene-analyzers-kuromoji-4.10.4.jar:/usr/share/java/lucene-analyzers-phonetic-4.10.4.jar:/usr/share/java/lucene-expressions-4.10.4.jar:/usr/share/java/spatial4j-0.4.1.jar:/usr/share/java/lucene-analyzers-common-4.10.4.jar:/usr/share/java/lucene-misc-4.10.4.jar:/usr/share/java/lucene-benchmark-4.10.4.jar:/usr/share/java/lucene-join-4.10.4.jar:/usr/share/java/lucene-sandbox-4.10.4.jar:/usr/share/java/lucene-queryparser-4.10.4.jar:/usr/share/java/lucene-classification-4.10.4.jar:/usr/share/java/lucene-core-4.10.4.jar:/usr/share/java/lucene-analyzers-smartcn-4.10.4.jar:/usr/share/java/lucene-facet-4.10.4.jar:/usr/share/java/lucene-highlighter-4.10.4.jar:/usr/share/java/lucene-grouping-4.10.4.jar:/usr/share/java/jts.jar:/usr/share/java/lucene-test-framework-4.10.4.jar:/usr/share/java/lucene-analyzers-uima-4.10.4.jar:/usr/share/java/lucene-memory-4.10.4.jar:" org.elasticsearch.plugins.PluginManager "install" "elasticsearch/elasticsearch-analysis-kuromoji"
-> Installing elasticsearch/elasticsearch-analysis-kuromoji...
Trying https://github.com/elasticsearch/elasticsearch-analysis-kuromoji/archive/master.zip...
Downloading ...............................DONE
Installed elasticsearch/elasticsearch-analysis-kuromoji into /usr/share/elasticsearch/plugins/analysis-kuromoji
Usage:
    -u, --url     [plugin location]   : Set exact URL to download the plugin from
    -i, --install [plugin name]       : Downloads and installs listed plugins [*]
    -t, --timeout [duration]          : Timeout setting: 30s, 1m, 1h... (infinite by default)
    -r, --remove  [plugin name]       : Removes listed plugins
    -l, --list                        : List installed plugins
    -v, --verbose                     : Prints verbose messages
    -s, --silent                      : Run in silent mode
    -h, --help                        : Prints this help message

 [*] Plugin name could be:
     elasticsearch/plugin/version for official elasticsearch plugins (download from download.elasticsearch.org)
     groupId/artifactId/version   for community plugins (download from maven central or oss sonatype)
     username/repository          for site plugins (download from github master)

Message:
   Error while installing plugin, reason: IllegalArgumentException: Plugin installation assumed to be site plugin, but contains source code, aborting installation.
```

少し調べてみると、elasticsearch/elasticsearch-analysis-kuromojiはインストールする時にバージョンを指定しないといけないみたいなので、"elasticsearch/elasticsearch-analysis-kuromoji"の部分を"elasticsearch/elasticsearch-analysis-kuromoji/2.7.0"に変更して再度実行。

```sh:
$ sudo /usr/bin/java -Xmx64m -Xms16m -Delasticsearch -Des.path.home="/usr/share/elasticsearch" -Des.default.path.conf="/usr/share/elasticsearch/config" -Des.default.config="/usr/share/elasticsearch/config/elasticsearch.yml" -cp ":/usr/share/java/lucene-spatial-4.10.4.jar:/usr/share/java/lucene-replicator-4.10.4.jar:/usr/share/java/lucene-queries-4.10.4.jar:/usr/share/java/lucene-demo-4.10.4.jar:/usr/share/java/jna.jar:/usr/share/java/lucene-codecs-4.10.4.jar:/usr/share/java/lucene-analyzers-stempel-4.10.4.jar:/usr/share/java/sigar.jar:/usr/share/java/lucene-analyzers-icu-4.10.4.jar:/usr/share/java/lucene-analyzers-morfologik-4.10.4.jar:/usr/share/java/apache-log4j-extras-1.2.17.jar:/usr/share/java/groovy-all-2.x.jar:/usr/share/java/elasticsearch-1.7.3.jar:/usr/share/java/lucene-suggest-4.10.4.jar:/usr/share/java/log4j-1.2-1.2.17.jar:/usr/share/java/lucene-analyzers-kuromoji-4.10.4.jar:/usr/share/java/lucene-analyzers-phonetic-4.10.4.jar:/usr/share/java/lucene-expressions-4.10.4.jar:/usr/share/java/spatial4j-0.4.1.jar:/usr/share/java/lucene-analyzers-common-4.10.4.jar:/usr/share/java/lucene-misc-4.10.4.jar:/usr/share/java/lucene-benchmark-4.10.4.jar:/usr/share/java/lucene-join-4.10.4.jar:/usr/share/java/lucene-sandbox-4.10.4.jar:/usr/share/java/lucene-queryparser-4.10.4.jar:/usr/share/java/lucene-classification-4.10.4.jar:/usr/share/java/lucene-core-4.10.4.jar:/usr/share/java/lucene-analyzers-smartcn-4.10.4.jar:/usr/share/java/lucene-facet-4.10.4.jar:/usr/share/java/lucene-highlighter-4.10.4.jar:/usr/share/java/lucene-grouping-4.10.4.jar:/usr/share/java/jts.jar:/usr/share/java/lucene-test-framework-4.10.4.jar:/usr/share/java/lucene-analyzers-uima-4.10.4.jar:/usr/share/java/lucene-memory-4.10.4.jar:" org.elasticsearch.plugins.PluginManager "install" "elasticsearch/elasticsearch-analysis-kuromoji/2.7.0"
-> Installing elasticsearch/elasticsearch-analysis-kuromoji/2.7.0...
Trying http://download.elasticsearch.org/elasticsearch/elasticsearch-analysis-kuromoji/elasticsearch-analysis-kuromoji-2.7.0.zip...
Downloading .........................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................DONE
Installed elasticsearch/elasticsearch-analysis-kuromoji/2.7.0 into /usr/share/elasticsearch/plugins/analysis-kuromoji
```

...成功(^_^;)

さて、次はこれから何をするかですね...