0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Elasticsearchをソースからビルドして動かしてみる

Posted at

TL;DR

オープンソースの全文検索エンジンであるElasticsearchは、GitHubにソースコードが公開されています。
Elasticsearch
今回は、このソースコードからElasticsearchをビルドし、動かしてみました。
また、Elasticsearchの可視化ツールであるelasticsearch-headの動かし方や設定も記載します。
(内容は、ほぼほぼ備忘録です)

Elasticsearchをビルド

まず、GitHubからソースコードをクローンします。

git clone https://github.com/elastic/elasticsearch.git

そして、ビルドを実行。ビルドには、Gradleを使用します。Linuxユーザの場合、sdkmanなどでインストールしておきましょう。
また、JavaはJDK14以上が必要です。(JDK11ではビルドに失敗するので注意)
なお、ビルド手順はGitHubのREADMEにも記載されています。

cd elasticsearch
./gradlew localDistro

ビルドに成功すると、buildディレクトリ以下にモジュールが作成されます。

Elasticsearchの実行

ビルドされたモジュールを実行します。

cd build/distribution/local/elasticsearch-8.0.0-SNAPSHOT/ # パスは環境によって異なります
./bin/elasticsearch

正常に実行できているかは、以下のようにHTTPリクエストを送信して確認します。

curl -X GET http://localhost:9200/

elasticsearch-headの起動

elasticsearch-headを使い、ブラウザから可視化をしてみます。

まず、elasticsearch-headをダウンロード

git clone https://github.com/mobz/elasticsearch-head.git

npmコマンドでサーバを起動します。

cd elasticsearch-head
npm install
npm run start

サーバの起動後、http://localhost:9100にブラウザでアクセスします。

localhost以外からアクセスする時の設定

Elasticsearchは、デフォルトではlocalhost以外からのアクセスはできなくなっています。そのため、以下の設定をElasticsearch本体のconfig配下にあるelasticsearch.ymlに追加します。

elasticsearch.yml
# CORSの有効化
http.cors.enabled: true
http.cors.allow-origin: "*"

# 外部からのアクセスの有効化
network.host: 0.0.0.0
http.port: 9200
transport.host: localhost

参考サイト

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?