Elasticsearch集群配置密码(传统方式&Docker方式)

本文涉及的产品
Elasticsearch Serverless通用抵扣包,测试体验金 200元
简介: Elasticsearch集群配置密码(传统方式&Docker方式)

正文


 在最低安全配置中添加密码保护后,需要配置传输层安全 (TLS)。传输层处理集群中节点之间的所有内部通信。如果集群有多个节点,那么您必须在节点之间配置 TLS。如果不启用 TLS,生产模式集群将不会启动。传输层依赖于双向 TLS 来加密和验证节点。正确应用 TLS 可确保恶意节点无法加入集群并与其他节点交换数据。虽然在 HTTP 层实现用户名和密码认证对于保护本地集群很有用,但节点之间的通信安全需要 TLS。在节点之间配置 TLS 是基本的安全设置,以防止未经授权的节点访问您的集群。


传统方式


集群安装


1、生成证书


./bin/elasticsearch-certutil ca


Please enter the desired output file [elastic-stack-ca.p12]:  此处按回车键

Enter password for elastic-stack-ca.p12 :  输入密码 snail(也可以不输入)


2、集群中的任意一个节点生成证书和私钥


./bin/elasticsearch-certutil cert --ca elastic-stack-ca.p12


Enter password for CA (elastic-stack-ca.p12) : 输入上面的密码

Please enter the desired output file [elastic-certificates.p12]:  回车


Enter password for elastic-certificates.p12 : 输入上面的密码


3、此时已生成证书elastic-certificates.p12,将该证书复制到每一个节点的config目录下


/usr/local/elasticsearch/config


4、在每一个节点上存储密码


./bin/elasticsearch-keystore add xpack.security.transport.ssl.keystore.secure_password
./bin/elasticsearch-keystore add xpack.security.transport.ssl.truststore.secure_password


5、修改每一个节点elasticsearch.yml 注意不要有多余的空格


# ======================== Elasticsearch Configuration =========================
#
# NOTE: Elasticsearch comes with reasonable defaults for most settings.
#       Before you set out to tweak and tune the configuration, make sure you
#       understand what are you trying to accomplish and the consequences.
#
# The primary way of configuring a node is via this file. This template lists
# the most important settings you may want to configure for a production cluster.
#
# Please consult the documentation for further information on configuration options:
# https://www.elastic.co/guide/en/elasticsearch/reference/index.html
#
# ---------------------------------- Cluster -----------------------------------
#
# Use a descriptive name for your cluster:
#
cluster.name: my-es
#
# ------------------------------------ Node ------------------------------------
#
# Use a descriptive name for the node:
#
node.name: node-3
#
# Add custom attributes to the node:
#
#node.attr.rack: r1
#
# ----------------------------------- Paths ------------------------------------
#
# Path to directory where to store the data (separate multiple locations by comma):
#
path.data: /usr/local/es/data
#
# Path to log files:
#
path.logs: /usr/local/es/logs
#
# ----------------------------------- Memory -----------------------------------
#
# Lock the memory on startup:
#
#bootstrap.memory_lock: true
#
# Make sure that the heap size is set to about half the memory available
# on the system and that the owner of the process is allowed to use this
# limit.
#
# Elasticsearch performs poorly when the system is swapping the memory.
#
# ---------------------------------- Network -----------------------------------
#
# By default Elasticsearch is only accessible on localhost. Set a different
# address here to expose this node on the network:
#
network.host: 0.0.0.0
#
# By default Elasticsearch listens for HTTP traffic on the first free port it
# finds starting at 9200. Set a specific HTTP port here:
#
http.port: 9200
#
# For more information, consult the network module documentation.
#
# --------------------------------- Discovery ----------------------------------
#
# Pass an initial list of hosts to perform discovery when this node is started:
# The default list of hosts is ["127.0.0.1", "[::1]"]
#
discovery.seed_hosts: ["192.168.139.160","192.168.139.161", "192.168.139.162"]
#
# Bootstrap the cluster using an initial set of master-eligible nodes:
#
cluster.initial_master_nodes: ["node-1", "node-2","node-3"]
#
# For more information, consult the discovery and cluster formation module documentation.
#
# ---------------------------------- Various -----------------------------------
#
# Require explicit names when deleting indices:
#
#action.destructive_requires_name: true
#设置密码
xpack.security.enabled: true
http.cors.allow-headers: Authorization
xpack.license.self_generated.type: basic
#设置单点模式
#discovery.type: single-node
#设置证书
xpack.security.transport.ssl.enabled: true
xpack.security.transport.ssl.verification_mode: certificate
xpack.security.transport.ssl.client_authentication: required
xpack.security.transport.ssl.keystore.path: elastic-certificates.p12
xpack.security.transport.ssl.truststore.path: elastic-certificates.p12


6、授权证书文件


chown -R snail_es.es /usr/local/elasticsearch/


7、设置密码,请保证每个节点都在运行的状态


./bin/elasticsearch-setup-passwords interactive  手动
./bin/elasticsearch-setup-passwords auto 自动


Changed password for user apm_system

PASSWORD apm_system = Yu0vjHZxkCBXuGnTM9VM


Changed password for user kibana_system

PASSWORD kibana_system = oNXyGWsWHLC3VllVb4Qb


Changed password for user kibana

PASSWORD kibana = oNXyGWsWHLC3VllVb4Qb


Changed password for user logstash_system

PASSWORD logstash_system = XFd1IoqZAgt7scdxwXN2


Changed password for user beats_system

PASSWORD beats_system = 1oENHpgMQLeLyiugkmRy


Changed password for user remote_monitoring_user

PASSWORD remote_monitoring_user = bjGZqG7SxffKciVJRxsX


Changed password for user elastic

PASSWORD elastic = cGKuMaWGZLBaSSDW7qKX


elastic

一个内置的超级用户。

kibana_system

Kibana 用于连接 Elasticsearch 并与之通信的用户。

logstash_system

Logstash 在 Elasticsearch 中存储监控信息时使用的用户。

beats_system

Beats 在 Elasticsearch 中存储监控信息时使用的用户。

apm_system

APM 服务器在 Elasticsearch 中存储监控信息时使用的用户。

remote_monitoring_user

在 Elasticsearch 中收集和存储监控信息时使用的用户 Metricbeat。

它具有remote_monitoring_agent和 remote_monitoring_collector内置角色。


8、结束


Docker方式


1、创建挂载目录并授权


[root@localhost ~]# mkdir -p /data/es/{conf,data,logs,plugins}
#授权
[root@localhost ~]# chmod 777 -R /data/

2、进入容器生成证书


docker exec -it elasticsearch /bin/bash 
./bin/elasticsearch-certutil ca
#集群中的任意一个节点生成证书和私钥
./bin/elasticsearch-certutil cert --ca elastic-stack-ca.p12


3、将证书复制到每个节点的config目录(挂载目录)


将证书复制到宿主机
#复制
docker cp elasticsearch:/usr/share/elasticsearch/elastic-certificates.p12 /root


4、将证书复制到每一个节点docker容器中


docker cp /data/es/conf/elastic-certificates.p12 
elasticsearch:/usr/share/elasticsearch/config
#存储密码 每一个节点都要执行
./bin/elasticsearch-keystore add xpack.security.transport.ssl.keystore.secure_password
./bin/elasticsearch-keystore add xpack.security.transport.ssl.truststore.secure_password


5、修改配置文件跟上面配置文件一样


6、进入容器设置密码


docker exec -it elasticsearch /bin/bash 
./bin/elasticsearch-setup-passwords interactive  手动
./bin/elasticsearch-setup-passwords auto 自动


7、重新启动容器或者新创建容器


docker run --name elasticsearch --privileged=true --net=host \
 -v /data/es/conf/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml \
 -v /data/es/data:/usr/share/elasticsearch/data \
 -v /data/es/logs:/usr/share/elasticsearch/logs \
 -v /data/es/plugins:/usr/share/elasticsearch/plugins \
 -d elasticsearch:7.14.2


8、结束


相关实践学习
以电商场景为例搭建AI语义搜索应用
本实验旨在通过阿里云Elasticsearch结合阿里云搜索开发工作台AI模型服务,构建一个高效、精准的语义搜索系统,模拟电商场景,深入理解AI搜索技术原理并掌握其实现过程。
ElasticSearch 最新快速入门教程
本课程由千锋教育提供。全文搜索的需求非常大。而开源的解决办法Elasricsearch(Elastic)就是一个非常好的工具。目前是全文搜索引擎的首选。本系列教程由浅入深讲解了在CentOS7系统下如何搭建ElasticSearch,如何使用Kibana实现各种方式的搜索并详细分析了搜索的原理,最后讲解了在Java应用中如何集成ElasticSearch并实现搜索。  
相关文章
kde
|
2月前
|
Kubernetes 关系型数据库 文件存储
手把手教你完成极空间 NAS Docker 镜像加速配置
本教程详细介绍了如何在极空间NAS上配置轩辕镜像加速器,以提升Docker镜像的下载速度与稳定性。内容涵盖账号注册、网络确认、加速器设置及验证方法,并提供常见问题解决方案,帮助用户高效完成容器化应用部署。
kde
539 1
|
5月前
|
Prometheus 监控 Cloud Native
Prometheus配置docker采集器
本文介绍了如何使用 Prometheus 监控 Docker 容器,涵盖环境准备、配置文件编写及服务启动等步骤。首先确保安装 Docker 和 Docker Compose,接着通过 `docker-compose.yml` 配置 Prometheus 和示例应用。创建 `prometheus.yml` 指定数据采集目标,最后用 `docker-compose up -d` 启动服务。文章还展示了甘特图和类图,帮助理解服务状态与关系,助力提升系统可靠性和可维护性。
177 11
kde
|
2月前
|
文件存储 数据安全/隐私保护 开发者
群晖NAS Docker镜像源加速配置教程
本教程介绍了群晖NAS用户如何通过配置轩辕镜像加速服务提升Docker镜像拉取速度。内容包括配置前准备、详细设置步骤及日常使用说明,帮助用户快速完成配置并享受高效稳定的镜像下载体验。
kde
1186 59
kde
|
Docker 容器 文件存储
飞牛fnOS Docker镜像加速配置全攻略
本文介绍了如何在飞牛fnOS中配置Docker镜像加速服务,通过设置轩辕镜像仓库加速器,提升镜像拉取速度与稳定性。内容涵盖配置前准备、加速源设置、首选加速源调整及使用指南,帮助用户高效完成镜像操作。
kde
682 56
|
4月前
|
Prometheus 监控 Cloud Native
除了Prometheus,还有哪些工具可以监控Docker Swarm集群的资源使用情况?
除了Prometheus,还有哪些工具可以监控Docker Swarm集群的资源使用情况?
343 79
|
2月前
|
Java 分布式数据库 Docker
使用Docker配置并连接HBase的Java API
本流程概要的解释了如何在Docker上配置并启动HBase服务,并通过Java API进行连接和操作表,不涉及具体的业务逻辑处理和数据模型设计,这些因应用而异需由开发者根据实际需求进行实现。
111 13
|
3月前
|
存储 NoSQL MongoDB
Docker中安装MongoDB并配置数据、日志、配置文件持久化。
现在,你有了一个运行在Docker中的MongoDB,它拥有自己的小空间,对高楼大厦的崩塌视而不见(会话丢失和数据不持久化的问题)。这个MongoDB的数据、日志、配置文件都会妥妥地保存在你为它精心准备的地方,天旋地转,它也不会失去一丁点儿宝贵的记忆(即使在容器重启后)。
320 4
|
7月前
|
消息中间件 监控 RocketMQ
Docker部署RocketMQ5.2.0集群
本文详细介绍了如何使用Docker和Docker Compose部署RocketMQ 5.2.0集群。通过创建配置文件、启动集群和验证容器状态,您可以快速搭建起一个RocketMQ集群环境。希望本文能够帮助您更好地理解和应用RocketMQ,提高消息中间件的部署和管理效率。
902 91
|
5月前
|
Java Linux
CentOS环境搭建Elasticsearch集群
至此,您已成功在CentOS环境下搭建了Elasticsearch集群。通过以上介绍和步骤,相信您对部署Elasticsearch集群有了充分的了解。最后祝您在使用Elasticsearch集群的过程中顺利开展工作!
284 22