社内se × プログラマ × ビッグデータ

プログラミングなどITに興味があります。

Elasticsearch のディレクトリ構成を見てみる

Elasticsearch のディレクトリ構成

バージョン 7.6.2 をモデルにしています。
デフォルトではインストール直後は以下のようなディレクトリ構成になっています。

/usr/share/elasticsearch # ls
LICENSE.txt  NOTICE.txt  README.asciidoc  bin  config  data  jdk  lib  logs  modules  plugins
bin
# ls bin
elasticsearch           elasticsearch-env            elasticsearch-plugin           elasticsearch-sql-cli-7.6.2.jar  x-pack-watcher-env
elasticsearch-certgen   elasticsearch-env-from-file  elasticsearch-saml-metadata    elasticsearch-syskeygen
elasticsearch-certutil  elasticsearch-keystore       elasticsearch-setup-passwords  elasticsearch-users
elasticsearch-cli       elasticsearch-migrate        elasticsearch-shard            x-pack-env
elasticsearch-croneval  elasticsearch-node           elasticsearch-sql-cli          x-pack-security-env
config
# ls config/
elasticsearch.keystore  elasticsearch.yml  jvm.options  log4j2.properties  role_mapping.yml  roles.yml  users  users_roles
elasticsearch.yml

Elasticsearch 用のメイン設定ファイル。
1. cluster.name は設定することが推奨されている(明示するため)

# ---------------------------------- Cluster -----------------------------------
#
# Use a descriptive name for your cluster:
#
#cluster.name: my-application
#

2. node.name は設定することが推奨されている(明示するため)

# ------------------------------------ Node ------------------------------------
#
# Use a descriptive name for the node:
#
#node.name: node-1
#
# Add custom attributes to the node:
#
#node.attr.rack: r1

3. データやログは Elasticsearch のディレクトリの外部に設定することが推奨される。
※elasticsearch バージョンアップ時に便利

# ----------------------------------- Paths ------------------------------------
#
# Path to directory where to store the data (separate multiple locations by comma):
#
${path.data}
#
# Path to log files:
#
${path.logs}

4. Elasticsearch を別のIPアドレスにバインドが可能

# ---------------------------------- Network -----------------------------------
#
# Set the bind address to a specific IP (IPv4 or IPv6):
#
#network.host: 192.168.0.1
#
# Set a custom port for HTTP:
#
#http.port: 9200
#
# For more information, consult the network module documentation.

5. どれだけの数の Elasticsearch インスタンスが接続されるか設定可能

# --------------------------------- Discovery ----------------------------------
#
# Pass an initial list of hosts to perform discovery when this node is started:
# The default list of hosts is ["127.0.0.1", "[::1]"]
#
#discovery.seed_hosts: ["host1", "host2"]
#
# Bootstrap the cluster using an initial set of master-eligible nodes:
#
#cluster.initial_master_nodes: ["node-1", "node-2"]
#
# For more information, consult the discovery and cluster formation module documentation.
jvm.options

Elasticsearch は Java でビルドされており、JVM 内で動作するため、重要な設定。
特にヒープサイズの設定が重要だが、最低でも1GB以上の設定が要求される。

# cat config/jvm.options 
## JVM configuration

################################################################
## IMPORTANT: JVM heap size
################################################################
##
## You should always set the min and max JVM heap
## size to the same value. For example, to set
## the heap to 4 GB, set:
##
## -Xms4g
## -Xmx4g
##
## See https://www.elastic.co/guide/en/elasticsearch/reference/current/heap-size.html
## for more information
##
################################################################

# Xms represents the initial size of total heap space
# Xmx represents the maximum size of total heap space

-Xms1g
-Xmx1g
(省略)
log4j2.properties

Elasticsearch は log4j2 のロギングフレームワークを使用している。

role_mapping.yml roles.yml users users_roles

これらの設定は Kibana 内で設定することが推奨されている。

jdk

jdkディレクトリには、Elasticsearchに同梱されているOpenJDKが含まれています。

lib

「lib」ディレクトリには、Elasticsearchに必要な多数の依存関係が含まれています。
"log4j" logging フレームワークや、Apache Lucene など。

module

「module」ディレクトリには、Elasticsearchにいくつかの追加機能を提供する多数の組み込みモジュールが含まれています。
これらはデフォルトで有効になっているようです。
たとえば、X-Pack 機能が配置されているのが分かります。

# ls modules/
aggs-matrix-stats  ingest-user-agent  percolator             transform         x-pack-deprecation  x-pack-monitoring
analysis-common    lang-expression    rank-eval              transport-netty4  x-pack-enrich       x-pack-rollup
flattened          lang-mustache      reindex                vectors           x-pack-graph        x-pack-security
frozen-indices     lang-painless      repository-url         x-pack-analytics  x-pack-ilm          x-pack-sql
ingest-common      mapper-extras      search-business-rules  x-pack-ccr        x-pack-logstash     x-pack-voting-only-node
ingest-geoip       parent-join        spatial                x-pack-core       x-pack-ml           x-pack-watcher
plugins

「plugins」ディレクトリは最初は空です。
何らかのプラグインを追加したい場合に、ここに追加可能です。
module との違いは、module は Elasticsearch に同梱されているものであるのに対して、plugins はカスタム機能の追加を提供してくれます。
そのため、サードパーティ製や自分たちで作成したものを追加できます。
※plugins は取り外し可能ですが、module は取り外しません(できません)