Installation#

last update 2024/07/10

summary#


environment#

environment#

OS

Elasticsearch

Kibana

AlmaLinux 9

8.14.2-1

8.14.2-1


Elasticsearch#

ヒント

Elasticsearchはjava実行環境込みでインストールされるため、別途jdkをインストールする必要はない

Elasticsearch install#

dnf -y install https://rpms.remirepo.net/enterprise/remi-release-9.rpm
dnf -y install tar mod_maxminddb GeoIP*
rpm --import https://artifacts.elastic.co/GPG-KEY-elasticsearch
cat <<__EOT__>> /etc/yum.repos.d/elasticsearch.repo
[elasticsearch]
name=Elasticsearch repository for 8.x packages
baseurl=https://artifacts.elastic.co/packages/8.x/yum
gpgcheck=1
gpgkey=https://artifacts.elastic.co/GPG-KEY-elasticsearch
enabled=1
autorefresh=1
type=rpm-md
__EOT__
dnf -y install elasticsearch

注釈

スーパーユーザ (elastic) の初期パスワードを控えておく
--------------------------- Security autoconfiguration information ------------------------------

Authentication and authorization are enabled.
TLS for the transport and HTTP layers is enabled and configured.

The generated password for the elastic built-in superuser is : ???????????????????

Elasticsearch configure#

デフォルトの設定で特に問題なく動作するが明示的に設定を変更することも可能

JVMのヒープサイズはノードの役割と総メモリ量に基づいて自動的に設定されるため、本番環境に於てもデフォルトのままが推奨。オーバーライドしたい場合は、ヒープサイズの最小値と最大値をXms・Xmxに設定する

#ヒープサイズを2GBに設定する例
echo "-Xms2g" > /etc/elasticsearch/jvm.options.d/elasticsearch.options
echo "-Xmx2g" >> /etc/elasticsearch/jvm.options.d/elasticsearch.options

ヒント

XmsとXmxは総メモリの50%以下に設定する

デフォルトではlocalhostからのアクセスのみ可能となるため、Kibanaを別のホストで動作させる場合は外部からのアクセスを許可する必要がある

#KibanaのホストIPアドレスが192.168.0.10の場合の例
sed -i -e 's/#network.host: 192.168.0.1/network.host: 192.168.0.10/' /etc/elasticsearch/elasticsearch.yml

Kibanaから接続するポートを変更する場合は以下の設定を行う

#ポートを9500に変更する場合の例
sed -i -e 's/#http.port: 9200/http.port: 9500/' /etc/elasticsearch/elasticsearch.yml

明示的にシングルノードで動作させる場合は以下の設定を行う

sed -i -e 's/cluster.initial_master_nodes/#cluster.initial_master_nodes/' /etc/elasticsearch/elasticsearch.yml
echo 'discovery.type: single-node' >> /etc/elasticsearch/elasticsearch.yml

ちなみに

single-nodeを指定する場合、cluster.initial_master_nodesは無効化する必要がある

ヒント

/etc/elasticsearch/elasticsearch.yml では、その他暗号化の設定等が調整できる

Elasticsearch start#

systemctl enable elasticsearch
systemctl start elasticsearch

Curator (CLIベースの管理ツール) install#

インデックス操作、スナップショット操作などがコマンドで実行できるツールが必要な場合はCuratorをインストールする

dnf -y install pip
pip install elasticsearch-curator

Kibana#

Kibana install#

cat <<__EOT__>> /etc/yum.repos.d/kibana.repo
[kibana-8.x]
name=Kibana repository for 8.x packages
baseurl=https://artifacts.elastic.co/packages/8.x/yum
gpgcheck=1
gpgkey=https://artifacts.elastic.co/GPG-KEY-elasticsearch
enabled=1
autorefresh=1
type=rpm-md
__EOT__
dnf -y install kibana

Kibana configure#

表示を日本語に変更

sed -i -e 's/#i18n.locale: "en"/i18n.locale: "ja-JP"/' /etc/kibana/kibana.yml
KibanaがバインドするデフォルトのIPアドレスはlocalhostとなっているため、外部からアクセスするためのFromIPアドレスを設定
Webサーバをプロキシにする場合は特に不要
#アクセス元を限定しない場合の設定
sed -i -e 's/#server.host: \"localhost\"/server.host: \"0.0.0.0\"/' /etc/kibana/kibana.yml
ブラウザアクセスする際のポートを変更する場合の設定
Webサーバをプロキシにする場合は特に不要
sed -i -e 's/#server.port: 5601/server.port: 80/' /etc/kibana/kibana.yml

ブラウザアクセスする際の公開URLを指定

sed -i -e 's/#server.publicBaseUrl: \"\"/server.publicBaseUrl: \"http:\/\/example.com:80\"/' /etc/kibana/kibana.yml

Kibana start#

systemctl enable kibana
systemctl start kibana