インストール順序
Elasticserch
↓
kibana
の順でインストールする。
環境
・CentOS Stream9
・elasticsearch-8.17
・kibana-8.17
Elasticserchインストール手順
公式ドキュメントを参考に、インストールを進めていきます。
1.GCPキーのインポート
以下のコマンドで、GCPキーをインポートします。
rpm --import https://artifacts.elastic.co/GPG-KEY-elasticsearch
2.RPMリポジトリからインストール
/etc/yum.repos.d/配下にelasticsearch.repoというファイルを作成します。
# touch elasticsearch.repo
作成した 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=0
autorefresh=1
type=rpm-md
以下のコマンドで、elasticserchのインストールを開始します。
sudo yum install --enablerepo=elasticsearch elasticsearch
⇒「完了しました!」表示されること
ちなみに、私の環境ではインストールが完了するまで結構時間がかかりました。
3.ポート開放
elasticserchで使われる9200番ポートを開放します。
# firewall-cmd --add-port=9200/tcp --zone=public --permanent
設定を反映します。
# firewall-cmd --reload
4.サービス起動
以下のコマンドで、サービスを実行します。
# systemctl start elasticsearch.service
以下のコマンドで、サービスが起動していることを確認します。
# systemctl status elasticsearch.service
5.Elasticserchが動いているかの確認
以下のコマンドで、elasticserchノードが起動しているか確認します。
curl --cacert /etc/elasticsearch/certs/http_ca.crt -u elastic:$ELASTIC_PASSWORD https://localhost:9200
↑こんな感じの結果が返ってこれば成功です。※これは公式サイトから抜粋した一例です。
私の環境では以下が返ってきました。
curl: (7) Failed to connect to localhost port 9200: 接続を拒否されました
エラー調査をすると、ElasticSearchのパスワードリセットをする必要があることがわかりました。
qiitaにこのエラーに関する記事あげてくれてた人感謝です!
以下のコマンドで、パスワードリセットを試みましたが、、、
# sudo /usr/share/elasticsearch/bin/elasticsearch-reset-password -u elastic
うまくいかず、
今度はelasticserchのクラスター生成に失敗しました。
ERROR: Failed to determine the health of the cluster. Unexpected http status [503], with exit code 65
こんな↑エラーが出ました。
この場合の対処は、/etc/lasticsearch/elasticsearch.ymlを編集します。
具体的には、
elasticsearch.ymlファイル内のcluster.initial_master_nodes: ["localhost"]をコメントアウトして、discovery.type: single-nodeを追記します。
"#cluster.initial_master_nodes: [""localhost""]
discovery.type: single-node"
こんな感じに編集できればOK。
再びパスワードをリセットします。
# 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 ★yを入力する
Password for the [elastic] user successfully reset.
New value: <新しいパスワード>
export ELASTIC_PASSWORD="<新しいパスワード>"
ここまでしてもう一度elasticserchの起動確認コマンドを実行します。
# curl --cacert /etc/elasticsearch/certs/http_ca.crt -u elastic:$ELASTIC_PASSWORD https://localhost:9200
無事、↑のスクショにあるような記述が表示されました。
★項番5.で実施した一連の流れ★
起動確認コマンド実施
↓
エラー発生
↓
パスワードリセット
↓
ElasticSearchのクラスター生成に失敗する
↓
再度パスワードリセット
↓
起動確認コマンド実施
kibanaインストール手順
公式ドキュメントを参考に、インストールを進めていきます。
1.GCPキーのインポート
以下のコマンドで、GCPキーをインポートします。
# rpm --import https://artifacts.elastic.co/GPG-KEY-elasticsearch
2.RPMリポジトリからインストール
/etc/yum.repos.d/配下にkibana.repoというファイルを作成します。
# touch kibana.repo
作成した 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
以下のコマンドで、kibanaのインストールを開始します。
# sudo yum install kibana
⇒「完了しました!」表示されること
ちなみに、私の環境ではインストールが完了するまで結構時間がかかりました。
3.ポート開放
kibanaで使われる5601番ポートを開放します。
# firewall-cmd --add-port=5601/tcp --zone=public --permanent
設定を反映します。
# firewall-cmd --reload
4.サービス起動
以下のコマンドで、サービスを実行します。
# systemctl start kibana
以下のコマンドで、サービスが起動していることを確認します。
# systemctl status kibana
5.外部アクセスの有効化
/etc/kibana/配下にあるkibana.ymlファイルを編集します。
#server.host: "localhost"
server.host: "0.0.0.0"
kibanaを再起動します。
# systemctl restart kibana
6.WEBブラウザでkibanaにアクセス
WEBブラウザに【★kibanaがインストールされているipアドレス★:5601】を入力する。
以下のような画面が出たら成功。
WEBブラウザが表示されない場合、SELinuxが無効になっているか確認してください。
参考URL