当前位置: 首页 > news >正文

elasticsearch 配置用户名和密码

无密码的其他配置项在:https://blog.csdn.net/Xeon_CC/article/details/132064295

elasticsearch.yml配置文件:

xpack.security.enabled: true
xpack.security.http.ssl.enabled: true
xpack.security.http.ssl.keystore.path: /path/to/elastic-certificates.p12
xpack.security.transport.ssl: enabled: trueverification_mode: certificateclient_authentication: requiredkeystore.path: /path/to/elastic-certificates.p12truststore.path: /path/to/elastic-certificates.p12
证书的密码:
abcd1234所有用户的密码:
bcda1234生成证书
elasticsearch-certutil ca --out /path/to/elastic-stack-ca.p12 --pass abcd1234如果你不想生成单独的证书,也就是三个节点共用一个证书,请不要执行这行命令,这行命令将被下文所提到的证书生成方式代替。
elasticsearch-certutil cert --ca /path/to/elastic-stack-ca.p12输入指定路径
/path/to/elastic-certificates.p12注意:设置密码这一步,三个节点都要执行。
设置密码
elasticsearch-keystore add xpack.security.http.ssl.keystore.secure_password
elasticsearch-keystore add xpack.security.http.ssl.truststore.secure_password
elasticsearch-keystore add xpack.security.transport.ssl.truststore.secure_password
elasticsearch-keystore add xpack.security.transport.ssl.keystore.secure_password查看密码
elasticsearch-keystore show xpack.security.http.ssl.keystore.secure_password
elasticsearch-keystore show xpack.security.http.ssl.truststore.secure_password
elasticsearch-keystore show xpack.security.transport.ssl.truststore.secure_password
elasticsearch-keystore show xpack.security.transport.ssl.keystore.secure_password如果你希望集群共享一个整数,那么三个节点,确保elastic-certificates.p12证书文件是复制到每个节点的。设置为false
xpack.security.http.ssl.enabled: false
修改密码
elasticsearch-setup-passwords interactive最后,配置文件改回去
xpack.security.http.ssl.enabled: true最后在elasticsearch-head访问:https://192.168.0.111:9200/?auth_user=xxx&auth_password=xxx

在上面的“生成证书”这个步骤中的第二行命令,可以换为以下的步骤,安全性会更高,注意,确保存在elastic-stack-ca.p12文件,也就上述“生成证书”步骤中的第一行命令生成的文件。
首先随便选择一个节点:在任何目录下创建instances.yml,并键入如下内容:

instances:- name: "node-1"dns:- "localhost"ip:- "192.168.1.105"- name: "node-2"dns:- "localhost"ip:- "192.168.1.105"- name: "node-3"dns:- "localhost"ip:- "192.168.1.105"

比如我放在config目录下

elasticsearch-certutil cert --in config/instances.yml --out config/certs/certificates.zip --ca config/certs/elastic-stack-ca.p12 --pass abcd1234

然后,解压certificates.zip文件,会得到node-1、node-2、node-3文件夹
把node-1.p12、node-2.p12、node-3.p12复制到每个对应es节点中的config/certs目录下,certs目录如果没有则自己新建。

最后更改elasticsearch.yml配置文件
在这里插入图片描述
把这些证书文件替换为各自的证书文件。

这种配置方式的安全性要更高,推荐使用这种每个节点的证书都不同的方式。

如何用python通过SSL证书连接ES集群?
在每一个节点执行一下命令:

使用openssl配置客户端证书

openssl pkcs12 -in node-1.p12 -out node-1.crt -nokeys -nodes
openssl pkcs12 -in node-2.p12 -out node-2.crt -nokeys -nodes
openssl pkcs12 -in node-3.p12 -out node-3.crt -nokeys -nodes

然后,合并证书;

type node-1.crt node-2.crt node-3.crt > combined_ca.crt

最后在python中使用combined_ca.crt文件,把服务器生成的这个文件拷贝到python项目的目录中。

es = Elasticsearch(['https://192.168.1.105:9201', 'https://192.168.1.105:9202', 'https://192.168.1.105:9203'],  # 你可以指定一个或多个节点http_auth=('elastic', 'your_password'),scheme='https',use_ssl=True,ca_certs='combined_ca.crt', # 指定证书的路径。verify_certs=True  # 设置为True意味着客户端将验证服务器的证书
)index_name='abccc_2023-08-09'
if not es.indices.exists(index=index_name):body = {"settings": {"number_of_shards": 3,},"mappings": {"properties": {"location": {"type": "geo_shape"},"geo_loctn": {"type": "geo_point"}}}}es.indices.create(index=index_name, body=body)print('create es index ...')

如果能创建索引,说明验证成功。

http://www.lryc.cn/news/112230.html

相关文章:

  • 侯捷 C++面向对象编程笔记——9 复合 委托
  • 状态模式——对象状态及其转换
  • Linux一阶段复习
  • 宝塔Linux面板怎么升级?升级命令及失败解决方法
  • 前端面试的性能优化部分(6)每天10个小知识点
  • 2023年 Java 面试八股文(20w字)
  • 银河麒麟服务器ky10-server在线一键安装docker
  • spring boot中web容器配置
  • DNSlog注入(利用DNSlog平台将SQL盲注变成回显注入)
  • vim学习笔记(致敬vim作者)
  • 力扣 -- 139. 单词拆分
  • 百度秋招攻略,百度网申笔试面试详解
  • nohup Java -jar 生成的nohup.out 文件一直增加,如何处理
  • 静态页面与动态页面的区别及部署jpress应用
  • 华为数通HCIA-华为VRP系统基础
  • 基于Azure OpenAI Service 的知识库搭建实验⼿册
  • 第七节--结构体
  • Docker学习(二十四)报错速查手册
  • 一种SpringBoot下Scheduler定时任务优雅退出方案
  • DNS部署与安全详解(上)
  • 【51单片机】晨启科技,酷黑版,音乐播放器
  • 基于SPSSPRO实现层次分析法(AHP)
  • Spring Test中使用MockMvc进行上传文件单元测试时,报NullPointerException
  • HTTP常用状态码及其含义
  • FFmpeg中AVIOContext的使用
  • 【react】react中BrowserRouter和HashRouter的区别:
  • 机器学习常用Python库安装
  • HTTP 劫持、DNS 劫持与 XSS
  • bash引用-Quoting详细介绍
  • powershell几句话设置环境变量