ElasticsearchリポジトリのGPGキー(公開鍵)をimport
sudo rpm --import https://artifacts.elastic.co/GPG-KEY-elasticsearch
ElasticsearchのYUMリポジトリを追加
sudo tee /etc/yum.repos.d/elasticsearch.repo <<EOF
[elasticsearch-8.x]
name=Elasticsearch repository for 8.x packages
baseurl=https://artifacts.elastic.co/packages/8.x/yum
enabled=1
gpgcheck=1
gpgkey=https://artifacts.elastic.co/GPG-KEY-elasticsearch
autorefresh=1
type=rpm-md
EOF
インストール
sudo dnf install elasticsearch
[sooni@vm105 ~]$ sudo dnf install elasticsearch
Elasticsearch repository for 8.x packages
:
以下省略
:
-------------------------------------------------------------------------------------------------
### 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
/usr/lib/tmpfiles.d/elasticsearch.conf:1: Line references path below legacy directory /var/run/, updating /var/run/elasticsearch → /run/elasticsearch; please update the tmpfiles.d/ drop-in file accordingly.
検証中 : elasticsearch-8.18.0-1.x86_64 1/1
インストール済み:
elasticsearch-8.18.0-1.x86_64
完了しました!
[sooni@vm105 ~]$
Firewallのポート開放
Firewallのポート開放
[sooni@vm105 ~]$ sudo firewall-cmd --zone=public --add-port=9200/tcp --permanent
[sudo] sooni のパスワード:
success
[sooni@vm105 ~]$
[sooni@vm105 ~]$ sudo firewall-cmd --reload
設定ファイルを開いて http.port: 9200 を有効に
sudo vi /etc/elasticsearch/elasticsearch.yml
サービス起動
とりあえずサーバ起動。私はリソースの不足がちな環境で検証している事もありますが、そこそこ立ち上げ時間がかかります。(1~2分?)
sudo systemctl start elasticsearch
[sudo] sooni のパスワード:
[sooni@vm105 ~]$
-- 自動起動にするなら
[sooni@vm105 ~]$ sudo systemctl enable elasticsearch
[sudo] sooni のパスワード:
Created symlink /etc/systemd/system/multi-user.target.wants/elasticsearch.service → /usr/lib/systemd/system/elasticsearch.service.
[sooni@vm105 ~]$
接続確認
curl -k -X GET “https://localhost:9200/” を叩くも認証エラー発生。どうやらhttpsで利用するには認証がマストのようです。もし認証なしで利用するならhttpに切り替える必要があります。(httpで利用するには設定ファイルに以下を追加してください)
xpack.security.http.ssl.enabled: false
xpack.security.enabled: false
[sooni@vm105 ~]$ curl -k -X GET "https://localhost:9200/"
{"error":{"root_cause":[{"type":"security_exception","reason":"missing authentication credentials for REST request [/]","header":{"WWW-Authenticate":["Basic realm=\"security\", charset=\"UTF-8\"","Bearer realm=\"security\"","ApiKey"]}}],"type":"security_exception","reason":"missing authentication credentials for REST request [/]","header":{"WWW-Authenticate":["Basic realm=\"security\", charset=\"UTF-8\"","Bearer realm=\"security\"","ApiKey"]}},"status":401}[sooni@vm105 ~]$
SSLで動かしてみたいのでパスワードを設定する
elasticとゆうユーザがデフォルトで用意されているので以下リセットします。新規に作成する場合はAPIで作成できるようです。(今回はやりません)
sudo /usr/share/elasticsearch/bin/elasticsearch-reset-password -u elastic
[sooni@vm105 ~]$ sudo /usr/share/elasticsearch/bin/elasticsearch-reset-password -u elastic
This tool will reset the password of the [elastic] user to an autogenerated value.
The password will be printed in the console.
Please confirm that you would like to continue [y/N]y
Password for the [elastic] user successfully reset.
New value: lVK8pTLrNXStaacN3QA8
[sooni@vm105 ~]$
--
-- いざ接続確認
--
[sooni@vm105 ~]$ curl -k -u elastic:lVK8pTLrNXStaacN3QA8 "https://localhost:9200/"
{
"name" : "vm105.com",
"cluster_name" : "elasticsearch",
"cluster_uuid" : "NzHTmHVMSfmuJVKa7OVDIA",
"version" : {
"number" : "8.18.0",
"build_flavor" : "default",
"build_type" : "rpm",
"build_hash" : "04e979aa50b657bebd4a0937389308de82c2bdad",
"build_date" : "2025-04-10T10:09:16.444104780Z",
"build_snapshot" : false,
"lucene_version" : "9.12.1",
"minimum_wire_compatibility_version" : "7.17.0",
"minimum_index_compatibility_version" : "7.0.0"
},
"tagline" : "You Know, for Search"
}
[sooni@vm105 ~]$