這里寫目錄標題
- 前言
- 一、elasticsearch設定密碼
- 首先開啟 X-Pack
- 測驗是否設定成功
- 修改密碼
- 已知密碼修改
- 忘記密碼
- 二、kibana配置elasticsearch密碼
前言
之前在docker中安裝過elasticsearch和elasticsearchhead以及kibana都沒有配置密碼,在此記錄下設定程序,
一、elasticsearch設定密碼
參考 官方檔案
xpack.security.enabled: true
設定引導性密碼
The setup-passwords tool is the simplest method to set the built-in users’ passwords for the first time. It uses the elastic user’s bootstrap password to run user management API requests. For example, you can run the command in an “interactive” mode, which prompts you to enter new passwords for the elastic, kibana, and logstash_system users:
首先開啟 X-Pack
修改容器內或者修改掛載出來的elasticsearch.yml
docker exec -it elasticsearch /bin/bash # 進入容器內部
vi /data/elasticsearch/config/elasticsearch.yml # 掛載目錄
elasticsearch.yml 檔案添加
cluster.name: "docker-cluster-01"
network.host: 0.0.0.0
http.cors.enabled: true
http.cors.allow-origin: "*"
# 此處開啟xpack
xpack.security.enabled: true
重新啟動elasticsearch,
docker restart elasticsearch
進入docker中的elasticsearch中,設定密碼,執行
/usr/share/elasticsearch/bin/x-pack/setup-passwords interactive
依次設定用戶:elastic、apm_system、kibana_system、logstash_system、beats_system、remote_monitoring_user共6個用戶,
內部用戶
X-Pack 安全有三個內部用戶(_system、_xpack和_xpack_security),負責在 Elasticsearch 集群中進行的操作,
這些用戶僅由源自集群內的請求使用,出于這個原因,它們不能用于對 API 進行身份驗證,并且沒有密碼可以管理或重置,
有時,您可能會在日志中找到對這些用戶之一的參考,包括審計日志,
Initiating the setup of passwords for reserved users elastic,apm_system,kibana,kibana_system,logstash_system,beats_system,remote_monitoring_user.
You will be prompted to enter passwords as the process progresses.
Please confirm that you would like to continue [y/N]y
Enter password for [elastic]:
Reenter password for [elastic]:
Enter password for [apm_system]:
Reenter password for [apm_system]:
Enter password for [kibana_system]:
Reenter password for [kibana_system]:
Enter password for [logstash_system]:
Reenter password for [logstash_system]:
Enter password for [beats_system]:
Reenter password for [beats_system]:
Enter password for [remote_monitoring_user]:
Reenter password for [remote_monitoring_user]:
Changed password for user [apm_system]
Changed password for user [kibana_system]
Changed password for user [kibana]
Changed password for user [logstash_system]
Changed password for user [beats_system]
Changed password for user [remote_monitoring_user]
Changed password for user [elastic]
測驗是否設定成功
curl localhost:9200
結果顯示:
[root@VM-24-15-centos config]# curl localhost:9200
{"error":{"root_cause":[{"type":"security_exception","reason":"missing authentication credentials for REST request [/]","header":{"WWW-Authenticate":"Basic realm=\"security\" charset=\"UTF-8\""}}],"type":"security_exception","reason":"missi
顯示這個則設定成功,
使用密碼訪問elasticsearch測驗是否可以訪問,
curl localhost:9200 -u elastic
就可以看到elasticsearch資訊,
修改密碼
已知密碼修改
POST _xpack/security/user/_password
POST _xpack/security/user/<username>/_password
# 將用戶elastic 密碼改為elastic
curl -u elastic -H "Content-Type: application/json" -X POST "localhost:9200/_xpack/security/user/elastic/_password" --data '{"password":"elastic"}'
# 測驗是否修改成功
curl localhost:9200 -u elastic
登錄成功的結果展示:
{
"name" : "384cda4775e5",
"cluster_name" : "docker-cluster-01",
"cluster_uuid" : "SOH21TLnQdSZnJq0ZW2iDw",
"version" : {
"number" : "7.14.2",
"build_flavor" : "default",
"build_type" : "docker",
"build_hash" : "6bc13727ce758c0e943c3c21653b3da82f627f75",
"build_date" : "2021-09-15T10:18:09.722761972Z",
"build_snapshot" : false,
"lucene_version" : "8.9.0",
"minimum_wire_compatibility_version" : "6.8.0",
"minimum_index_compatibility_version" : "6.0.0-beta1"
},
"tagline" : "You Know, for Search"
}
忘記密碼
創建本地超級賬戶,然后使用api介面本地超級賬戶重置elastic賬戶的密碼
- 停止elasticsearch服務
- 確保你的組態檔中支持本地賬戶認證支持,如果你使用的是xpack的默認配置則無需做特殊修改;如果你配置了其他認證方式則需要確保配置本地認證方式在ES_HOME/config/elasticsearch.yml中,
- 使用命令ES_HOME/bin/x-pack/users創建一個基于本地問價認證的超級管理員,
- 進入docker容器中elasticsearch中,執行
docker exec -it elasticsearch /bin/bash
bin/x-pack/users useradd test_admin -p test_password -r superuser
- 啟動elasticsearch服務
docker restart elasticsearch
- 通過api重置elastic超級管理員的密碼
curl -u test_admin -XPUT -H 'Content-Type: application/json' 'http://localhost:9200/_xpack/security/user/elastic/_password' -d '{"password" : "新密碼"}'
- 校驗下密碼是否重置成功
curl localhost:9200 -u elastic
二、kibana配置elasticsearch密碼
檔案
修改容器內或者修改掛載出來的kibana.yml
docker exec -it kibana /bin/bash # 進入容器內部
vi /data/kibana/config/kibana.yml # 掛載目錄
kibana.yml 檔案添加
#
# ** THIS IS AN AUTO-GENERATED FILE **
#
# Default Kibana configuration for docker target
server.host: "0"
server.shutdownTimeout: "5s"
elasticsearch.hosts: [ "http://172.17.0.3:9200" ]
monitoring.ui.container.elasticsearch.enabled: true
i18n.locale: "zh-CN"
# 此處設定elastic的用戶名和密碼
elasticsearch.username: elastic
elasticsearch.password: elastic
重新啟動elasticsearch,
docker restart kibana
訪問網址:

搞定!
新手最近開始寫文章,手敲不易,請多多支持!在此感謝每位讀者0.0
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/389096.html
標籤:其他
上一篇:Kafka:部署Kafka
下一篇:Hadoop入門篇
