Preface

Several aspects of ES security

Account password configuration

  • Open the configuration file elasticsearch.yml , modify or add the following content

    xpack.security.enabled: true
  • Restart elasticsearch

    sudo systemctl restart elasticsearch
  • Generate password (in particular, remember the passwords of elastic and kibana_system

    # 自动生成(须记住密码!!)
    /usr/share/elasticsearch/bin/elasticsearch-setup-passwords auto
    # 手动生成
    /usr/share/elasticsearch/bin/elasticsearch-setup-passwords interactive
  • Open the configuration file kibana.yml , modify or add the following content

    elasticsearch.username: "kibana_system"
    elasticsearch.password: "刚才生成的密码
  • Restart kibana and log in elastic
    image.png
  • Different roles and users can be created under Stack Managent
    image.png

Python client call example

from elasticsearch import Elasticsearch
host = '192.168.2.3:9200'
user = 'elastic'
pwd = 'xxx'
# 下面两种格式二选一
es = Elasticsearch(host, http_auth=(user, pwd))
#es = Elasticsearch(f'http://{user}:{pwd}@{host}')
es.cat.nodes()
This article is from qbit snap

qbit
268 声望279 粉丝