概要
Kibanaを利用するにあたり、開発環境に入っているElasticsearchが古すぎたため、最新のバージョンにアップデートをしようと。
こちらの公式ガイドを見たところ、Elasticsearch Migration Pluginなるものがあり、移行時に必要な作業等をチェックしてくれる模様。
ここでは、1.x -> 2.xのバージョンアップが可能かをチェックしてみる。ガイドはこちら。
ちなみに、2.x -> 5.xの場合はこちらを参照。
作業環境はAWSのEC2インスタンス。
Elasticsearch Migration Pluginの導入
# elasticsearchのあるディレクトリに移動
$ cd /usr/local/share/elasticsearch
# インストール実行
$ ./bin/plugin -i migration -u https://github.com/elastic/elasticsearch-migration/releases/download/v1.19/elasticsearch-migration-1.19.zip
-> Installing migration...
# エラー(ディレクトリのパーミッションの問題)
Failed to install migration, reason: plugin directory /usr/local/share/elasticsearch/plugins is read only
# rootで実行
$ sudo ./bin/plugin -i migration -u https://github.com/elastic/elasticsearch-migration/releases/download/v1.19/elasticsearch-migration-1.19.zip
-> Installing migration...
Trying https://github.com/elastic/elasticsearch-migration/releases/download/v1.19/elasticsearch-migration-1.19.zip...
Failed: IOException[Can't get https://github.com/elastic/elasticsearch-migration/releases/download/v1.19/elasticsearch-migration-1.19.zip to /usr/local/share/elasticsearch/plugins/migration.zip]; nested: FileNotFoundException[https://github.com/elastic/elasticsearch-migration/releases/download/v1.19/elasticsearch-migration-1.19.zip]; nested: FileNotFoundException[https://github.com/elastic/elasticsearch-migration/releases/download/v1.19/elasticsearch-migration-1.19.zip];
Trying https://github.com/null/migration/archive/master.zip...
Failed to install migration, reason: failed to download out of all possible locations..., use --verbose to get detailed information
バージョンが存在しない、と怒られた。
releasesを確認したところ、v1.18がいたので、とりあえずこれを入れてみる。
# インストール
$ sudo ./bin/plugin -i migration -u https://github.com/elastic/elasticsearch-migration/releases/download/v1.18/elasticsearch-migration-1.18.zip
-> Installing migration...
Trying https://github.com/elastic/elasticsearch-migration/releases/download/v1.18/elasticsearch-migration-1.18.zip...
Downloading ...............................................................DONE
Installed migration into /usr/local/share/elasticsearch/plugins/migration
ブラウザから確認
http://<ホスト名>:9200/_plugin/migration/
をブラウザで開く。
「Run checks now」のボタンをクリックし、下記のように「All checks completed successfully.」と表示されれば、バージョン移行可能なことが分かる。
インデックスのバックアップ
移行時はこちらのスナップショットとリストアの機能を利用すれば良いらしい。
elasticsearch.ymlに下記を追記。
path.repo: ["/usr/local/share/elasticsearch_snapshot"]
# バックアップ先のディレクトリ作成
$ sudo mkdir -p /usr/local/share/elasticsearch_snapshot
$ sudo chmod 777 /usr/local/share/elasticsearch_snapshot
# リポジトリを登録
$ curl -XPUT 'http://localhost:9200/_snapshot/snapshot1' -d '{
"type": "fs",
"settings": {
"location": "/usr/local/share/elasticsearch_snapshot/snapshot1",
"compress": true
}
}'
{"acknowledged":true}
# 確認
$ ls -l /usr/local/share/elasticsearch_snapshot
合計 4
drwxr-xr-x 2 root root 4096 1月 15 22:08 snapshot1
# バックアップ(スナップショットの取得)
# ここでは、「areas」インデックスのスナップショットを、「areas-2017.01.15」に取得する
$ curl -XPUT 'http://localhost:9200/_snapshot/snapshot1/areas-2017.01.15?wait_for_completion=true' -d '{
"indices": "areas",
"ignore_unavailable": true,
"include_global_state": false
}'
{"snapshot":{"snapshot":"areas-2017.01.15","indices":["areas"],"state":"SUCCESS","start_time":"2017-01-15T13:13:55.213Z","start_time_in_millis":1484486035213,"end_time":"2017-01-15T13:13:55.353Z","end_time_in_millis":1484486035353,"duration_in_millis":140,"failures":[],"shards":{"total":5,"failed":0,"successful":5}}}
# ディレクトリ確認
$ ls -l /usr/local/share/elasticsearch_snapshot/snapshot1
合計 16
-rw-r--r-- 1 root root 39 1月 15 22:13 index
drwxr-xr-x 3 root root 4096 1月 15 22:13 indices
-rw-r--r-- 1 root root 61 1月 15 22:13 metadata-areas-2017.01.15
-rw-r--r-- 1 root root 183 1月 15 22:13 snapshot-areas-2017.01.15
# スナップショット確認
$ curl -XGET 'http://localhost:9200/_snapshot/snapshot1/areas-2017.01.15'
{"snapshots":[{"snapshot":"areas-2017.01.15","indices":["areas"],"state":"SUCCESS","start_time":"2017-01-15T13:13:55.213Z","start_time_in_millis":1484486035213,"end_time":"2017-01-15T13:13:55.353Z","end_time_in_millis":1484486035353,"duration_in_millis":140,"failures":[],"shards":{"total":5,"failed":0,"successful":5}}]}
バックアップを利用してリストアを試す
$ curl -XPOST 'http://localhost:9200/_snapshot/snapshot1/areas-2017.01.15/_restore' -d '{
"indices": "areas",
"include_global_state": false
}'
{"error":"SnapshotRestoreException[[snapshot1:areas-2017.01.15] cannot restore index [areas] because it's open]","status":500}
インデックスが登録済なので上書きできない、ということのよう。
ので、一旦削除。
$ curl -XDELETE http://localhost:9200/areas
{"acknowledged":true}
再度リストア実行。
$ curl -XPOST 'http://localhost:9200/_snapshot/snapshot1/areas-2017.01.15/_restore' -d '{
"indices": "areas",
"include_global_state": false
}'
{"accepted":true}