개요

Install Elasticsearch with RPM

GPG key imort

rpm --import https://artifacts.elastic.co/GPG-KEY-elasticsearch

RPM repository 통해 설치

/etc/yum.repos.d/elasticsearch.repo 생성

cat <<EOF > /etc/yum.repos.d/elasticsearch.repo
[elasticsearch]
name=Elasticsearch repository for 7.x packages
baseurl=https://artifacts.elastic.co/packages/7.x/yum
gpgcheck=1
gpgkey=https://artifacts.elastic.co/GPG-KEY-elasticsearch
enabled=0
autorefresh=1
type=rpm-md
EOF

yum 통해 설치

sudo yum install --enablerepo=elasticsearch elasticsearch

RPM 통해 설치 후 구조

system service

[root@vultr ~]# cat /usr/lib/systemd/system/elasticsearch.service
[Unit]
Description=Elasticsearch
Documentation=https://www.elastic.co
Wants=network-online.target
After=network-online.target

[Service]
Type=notify
RuntimeDirectory=elasticsearch
PrivateTmp=true
Environment=ES_HOME=/usr/share/elasticsearch
Environment=ES_PATH_CONF=/etc/elasticsearch
Environment=PID_DIR=/var/run/elasticsearch
Environment=ES_SD_NOTIFY=true
EnvironmentFile=-/etc/sysconfig/elasticsearch

WorkingDirectory=/usr/share/elasticsearch

User=elasticsearch
Group=elasticsearch

ExecStart=/usr/share/elasticsearch/bin/systemd-entrypoint -p ${PID_DIR}/elasticsearch.pid --quiet

# StandardOutput is configured to redirect to journalctl since
# some error messages may be logged in standard output before
# elasticsearch logging system is initialized. Elasticsearch
# stores its logs in /var/log/elasticsearch and does not use
# journalctl by default. If you also want to enable journalctl
# logging, you can simply remove the "quiet" option from ExecStart.
StandardOutput=journal
StandardError=inherit

# Specifies the maximum file descriptor number that can be opened by this process
LimitNOFILE=65535

# Specifies the maximum number of processes
LimitNPROC=4096

# Specifies the maximum size of virtual memory
LimitAS=infinity

# Specifies the maximum file size
LimitFSIZE=infinity

# Disable timeout logic and wait until process is stopped
TimeoutStopSec=0

# SIGTERM signal is used to stop the Java process
KillSignal=SIGTERM

# Send the signal only to the JVM rather than its control group
KillMode=process

# Java process is never killed
SendSIGKILL=no

# When a JVM receives a SIGTERM signal it exits with code 143
SuccessExitStatus=143

# Allow a slow startup before the systemd notifier module kicks in to extend the timeout
TimeoutStartSec=75

[Install]
WantedBy=multi-user.target

# Built for packages-7.15.2 (packages)

데이터 경로

# /etc/elasticsearch/elasticsearch.yml
# 
# ----------------------------------- Paths ------------------------------------
#
# Path to directory where to store the data (separate multiple locations by comma):
#
path.data: /var/lib/elasticsearch
#
# Path to log files:
#
path.logs: /var/log/elasticsearch

systemctl elasticsearch start

[root@vultr ~]# /usr/share/elasticsearch/jdk/bin/java --version
openjdk 17.0.1 2021-10-19
OpenJDK Runtime Environment Temurin-17.0.1+12 (build 17.0.1+12)
OpenJDK 64-Bit Server VM Temurin-17.0.1+12 (build 17.0.1+12, mixed mode, sharing)

[root@vultr ~]# systemctl start elasticsearch
[root@vultr ~]# ps -ef | grep elasticsearch

/usr/share/elasticsearch/jdk/bin/java \
  -Xshare:auto \
  -Des.networkaddress.cache.ttl=60 \
  -Des.networkaddress.cache.negative.ttl=10 \
  -XX:+AlwaysPreTouch \
  -Xss1m \
  -Djava.awt.headless=true \
  -Dfile.encoding=UTF-8 \
  -Djna.nosys=true \
  -XX:-OmitStackTraceInFastThrow \
  -XX:+ShowCodeDetailsInExceptionMessages \
  -Dio.netty.noUnsafe=true \
  -Dio.netty.noKeySetOptimization=true \
  -Dio.netty.recycler.maxCapacityPerThread=0 \
  -Dio.netty.allocator.numDirectArenas=0 \
  -Dlog4j.shutdownHookEnabled=false \
  -Dlog4j2.disable.jmx=true \
  -Djava.locale.providers=SPI,COMPAT \
  --add-opens=java.base/java.io=ALL-UNNAMED \
  -XX:+UseG1GC \
  -Djava.io.tmpdir=/tmp/elasticsearch-9517931333804689362 \
  -XX:+HeapDumpOnOutOfMemoryError \
  -XX:HeapDumpPath=/var/lib/elasticsearch \
  -XX:ErrorFile=/var/log/elasticsearch/hs_err_pid%p.log \
  -Xlog:gc*,gc+age=trace,safepoint:file=/var/log/elasticsearch/gc.log:utctime,pid,tags:filecount=32,filesize=64m \
  -Xms3884m \
  -Xmx3884m \
  -XX:MaxDirectMemorySize=2036334592 \
  -XX:G1HeapRegionSize=4m \
  -XX:InitiatingHeapOccupancyPercent=30 \
  -XX:G1ReservePercent=15 \
  -Des.path.home=/usr/share/elasticsearch \
  -Des.path.conf=/etc/elasticsearch \
  -Des.distribution.flavor=default \
  -Des.distribution.type=rpm \
  -Des.bundled_jdk=true \
  -cp /usr/share/elasticsearch/lib/* org.elasticsearch.bootstrap.Elasticsearch \
  -p /var/run/elasticsearch/elasticsearch.pid --quiet

Troubleshooting

at least one of of [discovery.seed_hosts, discovery.seed_providers, cluster.initial_master_nodes] must be configured

문제

ERROR: [1] bootstrap checks failed. You must address the points described in the following [1] lines before starting Elasticsearch.
bootstrap check failure [1] of [1]: the default discovery settings are unsuitable for production use; at least one of [discovery.seed_hosts, discovery.seed_providers, cluster.initial_master_nodes] must be configured
ERROR: Elasticsearch did not exit normally - check the logs at /var/log/elasticsearch/elasticsearch.log

원인

해결

failed to obtain node locks, tried [[/var/lib/elasticsearch]] with lock id [0]

문제

java.lang.IllegalStateException: failed to obtain node locks, tried [[/var/lib/elasticsearch]] with lock id [0]; maybe these locations are not writable or multiple nodes were started without increasing [node.max_local_storage_nodes] (was [1])?
Likely root cause: java.nio.file.AccessDeniedException: /var/lib/elasticsearch/nodes/0/node.lock

원인

해결

chown -R elasticsearch:elasticsearch /var/lib/elasticsearch