さくらVPS に Elasticsearch 6.4 のインストールを実施します。
OS は CentOS 7系でのインストールを行います。
基本のインストール手順は公式サイトの以下の通りとなります。
https://www.elastic.co/guide/en/elasticsearch/reference/current/rpm.html
Elasticsearch のインストール
それではインストールを実施します。
インストールは公式からのリポジトリを追加し yum でのインストールを行います。
1 2 3 4 5 |
# yum -y update # rpm --import https://artifacts.elastic.co/GPG-KEY-elasticsearch |
次に以下のファイルを追加します。
1 2 3 4 5 6 7 8 9 10 |
[elasticsearch-6.x] name=Elasticsearch repository for 6.x packages baseurl=https://artifacts.elastic.co/packages/6.x/yum gpgcheck=1 gpgkey=https://artifacts.elastic.co/GPG-KEY-elasticsearch enabled=1 autorefresh=1 type=rpm-md |
こちでインストールを行います。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# yum -y install elasticsearch 読み込んだプラグイン:fastestmirror, langpacks Loading mirror speeds from cached hostfile epel/x86_64/metalink | 8.6 kB 00:00 * base: ftp.iij.ad.jp * epel: ftp.iij.ad.jp * extras: ftp.iij.ad.jp * updates: ftp.iij.ad.jp base | 3.6 kB 00:00 elasticsearch-6.x | 1.3 kB 00:00 extras | 3.4 kB 00:00 updates | 3.4 kB 00:00 elasticsearch-6.x/primary | 98 kB 00:01 elasticsearch-6.x 241/241 依存性の解決をしています --> トランザクションの確認を実行しています。 ---> パッケージ elasticsearch.noarch 0:6.4.0-1 を インストール --> 依存性解決を終了しました。 依存性を解決しました ================================================================================ Package アーキテクチャー バージョン リポジトリー 容量 ================================================================================ インストール中: elasticsearch noarch 6.4.0-1 elasticsearch-6.x 93 M トランザクションの要約 ================================================================================ インストール 1 パッケージ 総ダウンロード容量: 93 M インストール容量: 144 M Downloading packages: elasticsearch-6.4.0.rpm | 93 MB 00:24 Running transaction check Running transaction test Transaction test succeeded Running transaction which: no java in (/sbin:/bin:/usr/sbin:/usr/bin:/usr/X11R6/bin) could not find java; set JAVA_HOME or ensure java is in PATH error: %pre(elasticsearch-0:6.4.0-1.noarch) scriptlet failed, exit status 1 Error in PREIN scriptlet in rpm package elasticsearch-6.4.0-1.noarch 検証中 : elasticsearch-6.4.0-1.noarch 1/1 失敗: elasticsearch.noarch 0:6.4.0-1 完了しました! |
おっとJavaを入れていないので失敗しました。
Javaをインストールします。
1 2 3 |
# yum -y install java-1.8.0-openjdk-devel |
こちらで再度インストールを実行します。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# yum -y install elasticsearch 読み込んだプラグイン:fastestmirror, langpacks Loading mirror speeds from cached hostfile * base: ftp.iij.ad.jp * epel: ftp.iij.ad.jp * extras: ftp.iij.ad.jp * updates: ftp.iij.ad.jp 依存性の解決をしています --> トランザクションの確認を実行しています。 ---> パッケージ elasticsearch.noarch 0:6.4.0-1 を インストール --> 依存性解決を終了しました。 依存性を解決しました ================================================================================ Package アーキテクチャー バージョン リポジトリー 容量 ================================================================================ インストール中: elasticsearch noarch 6.4.0-1 elasticsearch-6.x 93 M トランザクションの要約 ================================================================================ インストール 1 パッケージ 総ダウンロード容量: 93 M インストール容量: 144 M Downloading packages: elasticsearch-6.4.0.rpm | 93 MB 00:28 Running transaction check Running transaction test Transaction test succeeded Running transaction Creating elasticsearch group... OK Creating elasticsearch user... OK インストール中 : elasticsearch-6.4.0-1.noarch 1/1 ### NOT starting on installation, please execute the following statements to configure elasticsearch service to start automatically using systemd sudo systemctl daemon-reload sudo systemctl enable elasticsearch.service ### You can start elasticsearch service by executing sudo systemctl start elasticsearch.service Created elasticsearch keystore in /etc/elasticsearch 検証中 : elasticsearch-6.4.0-1.noarch 1/1 インストール: elasticsearch.noarch 0:6.4.0-1 完了しました! |
こちらでインストールは実施できました。
kuromoji は必須になるのでインストール後にすぐに入れてしまいます。
1 2 3 |
# /usr/share/elasticsearch/bin/elasticsearch-plugin install analysis-kuromoji |
次に以下で起動の設定を行います。
1 2 3 4 |
# systemctl enable elasticsearch.service # systemctl start elasticsearch |
それではローカル環境から接続の確認を行います。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# curl localhost:9200 { "name" : "sh_03Cm", "cluster_name" : "elasticsearch", "cluster_uuid" : "HDRl3xBfTACJZ__uj9u6rA", "version" : { "number" : "6.4.0", "build_flavor" : "default", "build_type" : "rpm", "build_hash" : "595516e", "build_date" : "2018-08-17T23:18:47.308994Z", "build_snapshot" : false, "lucene_version" : "7.4.0", "minimum_wire_compatibility_version" : "5.6.0", "minimum_index_compatibility_version" : "5.0.0" }, "tagline" : "You Know, for Search" } |
無事、接続の確認が行えました。
今回、リモートからの接続を試すので Elasticsearch が外部から接続できるような設定を行います。
1 2 3 4 5 6 7 8 |
# vi /etc/elasticsearch/elasticsearch.yml -----------------------------変更 network.host: 0.0.0.0 ----------------------------- # systemctl restart elasticsearch |
こちらのアドレスはアクセスを受け付ける(bind)インターフェースのアドレスの設定をしています。
アクセス許可や制限のIPではありません。
実際の運用ではアクセスを受け付けるIPの制限など行います。
受け付けIPの設定をするにはX-PACKのセキュリティの設定か、FirewallなどでIPの制限をする必要があります。
また、firewall-cmd で外部からの接続を許可します。
firewall-cmdについては以下で記載しています。
https://colabmix.co.jp/tech-blog/centos-7-firewalld/
1 2 3 4 |
# firewall-cmd --add-port=9200/tcp # firewall-cmd --permanent --add-port=9200/tcp |
こちらで設定は完了です。
外部からコマンドで確認を実施しました。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
$ curl xxx.xxx.xxx.xxx:9200 { "name" : "sh_03Cm", "cluster_name" : "elasticsearch", "cluster_uuid" : "HDRl3xBfTACJZ__uj9u6rA", "version" : { "number" : "6.4.0", "build_flavor" : "default", "build_type" : "rpm", "build_hash" : "595516e", "build_date" : "2018-08-17T23:18:47.308994Z", "build_snapshot" : false, "lucene_version" : "7.4.0", "minimum_wire_compatibility_version" : "5.6.0", "minimum_index_compatibility_version" : "5.0.0" }, "tagline" : "You Know, for Search" } |
無事接続ができました。
kibana のインストール
今回、折角なので追加で kibana のインストールを実施します。
まずはインストールから。
1 2 3 |
# yum -y install kibana |
続いて管理画面の接続設定をします。
1 2 3 4 5 6 |
# vi /etc/kibana/kibana.yml -----------------------------変更 server.host: "0.0.0.0" ----------------------------- |
こちらも上記と同様に(bind)インターフェースのアドレスの設定をしています。
アクセス許可や制限のIPではありません。
実際の運用ではアクセスを受け付けるIPの制限など行います。
受け付けIPの設定をするにはX-PACKのセキュリティの設定か、FirewallなどでIPの制限をする必要があります。
続いて起動とポート解放の設定です。
1 2 3 4 5 6 7 |
# systemctl enable kibana.service # systemctl start kibana # firewall-cmd --add-port=5601/tcp # firewall-cmd --permanent --add-port=5601/tcp |
これで「http://xxx.xxx.xxx.xxx:5601/」のURLで管理画面にアクセスができます。
こちらで一通りの設定は完了です。
このブログは株式会社CoLabMixによる技術ブログです。
GCP、AWSなどでのインフラ構築・運用や、クローリング・分析・検索などを主体とした開発を行なっています。
Ruby on RailsやDjango、Pythonなどの開発依頼などお気軽にお声がけください。
開発パートナーを増やしたいという企業と積極的に繋がっていきたいです。